Search code examples
rubyrspecdeviseruby-on-rails-5rspec-rails

Rspec results are different when running one and all specs


Here's the source code https://github.com/tenzan/eshop

When I run a specific spec by rspec spec/features/application_controller_spec.rb, test passes.

But when I run all by executing rspec, it's giving me error for the spec above:

Failures:

  1) Admin::ApplicationController GET #index returns http success
     Failure/Error: expect(response).to have_http_status(:success)
       expected the response to have a success status code (2xx) but it was 302
     # ./spec/controllers/admin/application_controller_spec.rb:8:in `block (3 levels) in <top (required)>'

Finished in 0.61968 seconds (files took 1.53 seconds to load)
12 examples, 1 failure

Failed examples:

rspec ./spec/controllers/admin/application_controller_spec.rb:6 # Admin::ApplicationController GET #index returns http success

Any ideas why this is happening?


Solution

  • The file you run alone is not the one that fails when you run the whole suite ;-)

    rspec spec/features/application_controller_spec.rb --> is perfectly alright.

    rspec spec/controllers/admin/application_controller_spec.rb:6 --> Fails in any case, since there is no authenticated user.

    And a few tips: you can use --require rails_helper instead of --require spec_helper in the .rspec file, then you won't need to require it in every test file. And a shortcut: it is possible to use simple describe instead of RSpec.describe.