everydayrails / everydayrails-rspec-2017

Sample source for the 2017 edition of Everyday Rails Testing with RSpec.
http://rspectutorial.com
312 stars 247 forks source link

Chapter 6 page 98 #28

Closed twalpole closed 6 years ago

twalpole commented 6 years ago

click_button has no guarantee that any actions triggered by it will have completed when it returns. Because of this you should have an expectation after it that verifies/waits until the action has completed. In the example on page 98 that means moving at least one of the expectations inside the change block. Without that change the test will be flaky with some drivers.

expect {
    click_link "New Project"
    fill_in "Name", with: "Test Project"
    fill_in "Description", with: "Trying out Capybara"
    click_button "Create Project"
    expect(page).to have_content "Project was successfully created"
    expect(page).to have_content "Test Project"
    expect(page).to have_content "Owner: #{user.name}"
}.to change(user.projects, :count).by(1)
ruralocity commented 6 years ago

Thanks, I wasn't aware of this. Addressed for the upcoming maintenance release.

ruralocity commented 6 years ago

Fixed in 2017-10-23 maintenance release.