Rspec/Capybara Loading in Progress, Circular Require Considered Harmful

Rspec/Capybara loading in progress, circular require considered harmful

Remove --warnings from .rspec. The generator in rspec 3.0.0 included this setting, but we've realized it was a mistake -- while it's good to encourage users to write warning-free code, it's confusing for users to get these warnings without being sure why.

For more info:

https://github.com/rspec/rspec-core/issues/1571

Guard warning warning: loading in progress, circular require considered harmful

If you just want to turn off the warnings, you can do so in the rake test task setup:

require 'rake/testtask'
task :default => [:test]
Rake::TestTask.new do |t|
t.libs << 'test'
t.pattern = "test/test_*"
t.warning = false
end

Stack Dump in Rspec 3

It seems that you have enabled the --warnings (-w) option of RSpec.

Remove the option from your .rspec file and those warnings should disappear.

RSpec2 and Capybara

So I just ran into similar, and this is I think what's going on:

It depends on code you didn't include here of how you visit the page. I'm writing an rspec request spec.

If I retrieve the page with rspec's own:

get '/some/path'

then response.body.should have_selector works as you say, but page.should does not.

To make Capybara 'page' work (and to make Capybara interactions like click_button or fill_in work), instead of retrieving with rspec's 'get', you need to retrieve with Capybara's 'visit':

visit '/some/path'
page.should have_selector("works")

'page', a capybara method, only gets set when using 'visit', a capybara method.

This does get confusing, all the mixing and matching of different libraries involved in rails testing.

Capybara + RSpec, spec/features dir being ignored by the rspec . command?

You need to make sure all of your specs end in_spec.rb.

Change the filename to spec/features/my_first_feature_spec.rb

This is how I do it:

rspec spec

You may also want to use guard-rspec, which gives you better control.

How do I make rails errors in Capybara show up in rspec features?

Capybara is capable of raising server errors as failures on your tests, provided it's hooking into Rails correctly (see: the last bullet point on the "Gotchas" section of the README).

Make sure that you:

  • Are running your Capybara tests in your Rails environment
  • Have require 'capybara/rails' in your spec_helper.rb or rails_helper.rb file
  • Do not need your actual server running in order to run the tests (if you do, this is a symptom that your setup is incorrect).
  • Are visiting relative, not absolute, URLs in your tests (e.g. visit 'http://localhost:3000/mypage is wrong, visit '/mypage' is right).

If the above are all true, and you're still seeing the behavior, something else is likely wrong with your setup. Try changing your driver back to the default (Rack::Test) and see if the issue persists.

Edit: as explained in the comments below, the issue here was that the better_errors gem was loading in the test environment, which rescued the error and displayed the pretty error page before Capybara and Rspec got a chance to see the error. Moving it to the development-only group in the Gemfile fixed the issue. This thread held the answer.

Failing to run RSpec (uninitialized constant User (NameError)

After removing --warnings from .rspec (thank you kirti), current error was about capybara version being too low (requires 2.2). After installing the latest version (modifying gemfile and bundle install), rspec appears to be executing correctly. Thank you to all for your comments.

What could cause RSpec to fail when a controller test sees a view file with a _path helper only when when running the entire suite

Oh wow, so in one of our test files someone (normally git blame points fingers at me, strangely not this time!!) had added

include Rails.application.routes.url_helpers

Which presumably has changed between 6.0 and 6.1 so including this file does something.

Unlike other tests I've seen fail based on the order they ran, because this sits at the top of a file, no order would pass so long as RSpec loaded in the file.

tl;dr, don't include url_helpers in your test this way!



Related Topics



Leave a reply



Submit