Currently these tests are flakey.
Sometimes they pass. Sometimes they fail.
Below is the setup, code and output demons
The immediate thing that jumps out is that your admin_sign_in
doesn't actually wait for the sign_in to complete. This means that your call to create_costing
can occur without the session cookie having been set in your browser. The last line in your admin_sign_in
method should be something like
expect(page).to have_text('You are signed in') # whatever message is shown upon sign in
or
expect(page).to have_current_path('/') # whatever path an admin is redirected to upon signing in
That will make sure the login has actually completed and therefore the session cookies have been set in your browser.
Also your database cleaner config should use an append_after block rather than after - see https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example