ruby on rails 3 - How can I click_link a specific row with Capybara -
i'm trying write capybara code not use css or funny matchers. acceptance test purposes, i'm using capybara navigate button , link text visible user.
so have simple test asserts administrator can edit user:
it 'allows administrator edit user' user = login_admin_user user1 = factorygirl.create(:user) click_link "users" current_path.should eq(users_path) click_link "edit" # problem current_path.should eq(edit_user_path(user1)) fill_in "last name", with: "myxzptlk" click_button "update user" page.should have_content("myxzptlk") end of course problem line above not specific enough; there 2 lines in table (user , user1). i'm pretty new tdd, how use capybara select correct link using visible text?
i'm not sure why you're avoiding 'css or funny matchers'. if don't want put them in test, abstract them away helper methods.
in specs have helper method this:
module featurehelper def within_row(text, &block) within :xpath, "//table//tr[td[contains(.,\"#{text}\")]]" yield end end end and in specs can call like:
within_row(user1.name) click_link 'edit' end the helper module goes inside spec/support folder, , gets loaded specs doing:
config.include featurehelper, type: :feature in spec_helper.rb.
Comments
Post a Comment