Rails integration tests. Testing for actual pages -


when using automated tests test custom routes work, this:

test "that /logout route opens logout page"     '/logout'     assert_response :success end 

or test "that /logout route opens logout page" '/logout' assert_response :redirect end enough test? mind seems bit vague. how write test explicitly verify /logout route going logout page/the user served logout view?

i suggest rspec/rails , capybara integration , or acceptance tests. these tests more descriptive , sounds may asking about. example, spec describing authentication process

describe "signin" before { visit signin_path }  describe "with invalid information"   before { click_button "sign in" }    { should have_selector('title', text: 'sign in') }   { should have_selector('div.alert.alert-error', text: 'invalid') }    describe "after visiting page"     before { click_link "home" }     { should_not have_selector('div.alert.alert-error') }   end end  describe "with valid information"   let(:user) { factorygirl.create(:user) }   before     fill_in "email",    with: user.email.upcase     fill_in "password", with: user.password     click_button "sign in"   end    { should have_selector('title', text: user.name) }    { should have_link('users',    href: users_path) }   { should have_link('profile',  href: user_path(user)) }   { should have_link('settings', href: edit_user_path(user)) }   { should have_link('sign out', href: signout_path) }   { should_not have_link('sign in', href: signin_path) }    describe "followed signout"     before { click_link "sign out" }     { should have_link('sign in') }   end end 

this example taken ruby on rails tutorial book , free online. has hundreds of examples on integration testing.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -