Integration test for H1 text failing when it should be passing (Rspec and Capybara)
- by rebec
Below you can see my test for what happens when a user tries to access the page to edit a profile photo that they don't own. I've used the same test on the NEW action, where it worked fine, but it surprised me by failing when I copied it down to the EDIT action tests.
I've used save_and_open_page to test what Capybara's seeing (as you can see below); the resulting page definitely has an h1 with the specified text in it. No spelling errors, and case is all the same as in the test. I've tried using both have_css and have_selector. Both fail.
I'm still learning Ruby, Rails, Rspec and especially Capybara (was using webrat previously and recently switched over), and wonder if I'm misconceiving of something that's making me expect this to pass when it doesn't. Any thoughts? Thanks!
describe "EDIT" do
let(:user) { FactoryGirl.create(:user) }
let(:different_user) { FactoryGirl.create(:user) }
let(:admin_user) { FactoryGirl.create(:user, role: "admin") }
let(:profile_photo1) { FactoryGirl.create(:profile_photo, user: user) }
subject { page }
context "when signed in as any member" do
before {
login different_user
visit edit_user_profile_photo_path(:id => profile_photo1, :user_id => profile_photo1.user_id)
save_and_open_page
}
# It should deny access with an Unauthorised/Forbidden message.
it { should have_css('h1', text: "Unauthorised/Forbidden.") }
end