ruby - TDD with Capybara (Rails); difference between page.should and expect(page).to? -


i'm new world of rails , test driven development. tdd, i'm using rspec , capybara. currently, i'm working on tutorial learn more rails , author using following syntaxes:

page.should have_title('all users') expect(page).to have_selector('li', text: user.name) 

since seems both interchangeable i'm wondering when use syntax? because, described case above, write:

page.should have_title('all users') page.should have_selector('li', text: user.name) 

which same, right?

also, when should use "specify" instead of "it"?

it { should have_link('sign out', href: signout_path) } specify { expect(user.reload.name).to eq new_name } 

in case, write:

it { should have_link('sign out', href: signout_path) } { expect(user.reload.name).to eq new_name } 

i guess decision of 1 use based on want express. maybe, can me out here?!

thanks!

page.should have_title('all users') expect(page).to have_selector('li', text: user.name) 

go latter one, it's newer, they're pushing in direction. don't know if have intent of deprecating former, if do, won't have go update code.

it { should have_link('sign out', href: signout_path) } specify { expect(user.reload.name).to eq new_name } 

they aliases, choose 1 makes clearer. if name tests, know when use (example).

it { should have_link('sign out', href: signout_path) } 

frankly, avoid non-named spec style. it's bit magical, making difficult reason about, , requiring acrobatic setup subject work out correctly. also, run specs --format documentation, , auto-generated message never want. in case, i'd want it 'has signout link'


Comments