#156 Webrat
If you prefer writing integration tests in ruby instead of Cucumber's plain english, consider interacting with Webrat directly as I show in this episode.
- Download:
- source codeProject Files in Zip (98.1 KB)
- mp4Full Size H.264 Video (15 MB)
- m4vSmaller H.264 Video (9.17 MB)
- webmFull Size VP8 Video (24.4 MB)
- ogvFull Size Theora Video (21.3 MB)
Resources
- Webrat Documentation
- Switching Webrat to Selenium mode
- Nifty Generators
- Episode 155: Beginning with Cucumber
- Episode 116: Selenium
- Full Episode Source Code
bash
sudo rake gems:install RAILS_ENV=test
script/generate integration_test authentication
rake test:integration
script/generate nifty_authentication
rake db:migrate
sudo rake gems:install RAILS_ENV=test script/generate integration_test authentication rake test:integration script/generate nifty_authentication rake db:migrate
config/environments/test.rb
config.gem "webrat", :version => ">=0.4.3"
config.gem "webrat", :version => ">=0.4.3"
test/test_helper.rb
Webrat.configure do |config|
config.mode = :rails
end
Webrat.configure do |config| config.mode = :rails end
test/integration/authentication_test.rb
class AuthenticationTest < ActionController::IntegrationTest
test "logging in with valid username and password" do
User.create!(:username => "rbates", :email => "ryan@example.com", :password => "secret")
visit login_url
fill_in "Username", :with => "rbates"
fill_in "Password", :with => "secret"
click_button "Log in"
assert_contain "Logged in successfully."
end
test "logging in with invalid username and password" do
User.create!(:username => "rbates", :email => "ryan@example.com", :password => "secret")
visit login_url
fill_in "Username", :with => "rbates"
fill_in "Password", :with => "badsecret"
click_button "Log in"
assert_contain "Invalid login or password."
end
end
class AuthenticationTest < ActionController::IntegrationTest test "logging in with valid username and password" do User.create!(:username => "rbates", :email => "ryan@example.com", :password => "secret") visit login_url fill_in "Username", :with => "rbates" fill_in "Password", :with => "secret" click_button "Log in" assert_contain "Logged in successfully." end test "logging in with invalid username and password" do User.create!(:username => "rbates", :email => "ryan@example.com", :password => "secret") visit login_url fill_in "Username", :with => "rbates" fill_in "Password", :with => "badsecret" click_button "Log in" assert_contain "Invalid login or password." end end

