Rspec-rails: `cannot load such file -- capybara/dsl` on `require 'rspec/rails'`, am I doing it wrong?

Created on 17 Oct 2017  ·  15Comments  ·  Source: rspec/rspec-rails

I created a new rails project that does not depend on capybara, but does depend on rspec-rails. It 'splodes when I require 'rspec/rails'.

Failure/Error: require 'rspec/rails'

LoadError:
  cannot load such file -- capybara/dsl

Most helpful comment

This has been fixed with the release of RSpec 3.7.1

All 15 comments

Same here. It is a rails api application

+1

I'm having the same issue. Downgraded back to 3.6.1 for the time being.

same here!

https://relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files
guys check this out! I guess u also had rspec 2.x before, and you are trying to upgrade to 3.x now

@yyutianzheng thanks, but that is not my case.

I'm on a quite new application started with RSpec 3.6.

I've also tried to regenerate default helpers, but the result is the same.

btw I'm using Rails 5.1, I think this has something to do with #1813

@samphippen is this related to #1884? Are people here using puma?

To reproduce, I ran rails new broken, added rspec-rails to the Gemfile, removed capybara from the Gemfile, ran rails generate rspec:install, added a spec file, and then ran rspec.

@JonRowe I'm running puma

How to reproduce:

  1. rails new my_api --api -T
  2. Add gem 'rspec-rails', '~> 3.7' to Gemfile (group: development, test)
  3. bundle
  4. rails g rspec:install
  5. Create a spec in spec folder like
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'test' do
  it 'works' do
  end
end
  1. run rspec
$ rspec

An error occurred while loading ./spec/test_spec.rb.
Failure/Error: require 'rspec/rails'

LoadError:
  cannot load such file -- capybara/dsl
$ rails -v
Rails 5.1.4
$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]

Downgrading to 3.6 is fine

It appears to be the same with thin

Just investigated this myself in one of my apps. The issue, from what I can tell, is that Rails' actionpack has an (optional?) dependency on Capybara - in particular, within action_dispatch/system_test_case.rb, which is required from rspec/rails/example/system_example_group.rb.

Adding Capybara to my Gemfile got everything working again. Not sure what the proper solution is, though.

We need to expand #1884 to do the same check for capybara as it does for
puma, as it's a hard requirement for system tests

On Wed, 18 Oct 2017 at 13:00, Pat Allan notifications@github.com wrote:

Just investigated this myself in one of my apps. The issue, from what I
can tell, is that Rails' actionpack has an (optional?) dependency on
Capybara - in particular, within action_dispatch/system_test_case.rb,
which is required from rspec/rails/example/system_example_group.rb.

Adding Capybara to my Gemfile got everything working again. Not sure what
the proper solution is, though.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/rspec/rspec-rails/issues/1883#issuecomment-337438222,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJ8oCptSMynaqAydcRk50zG2u3_2ZVKks5stVu5gaJpZM4P8bTG
.

@JonRowe: sounds like the right approach to me 👍 especially now that I've glanced at the Rails docs for system tests and can see they rely on Capybara.

This has been fixed with the release of RSpec 3.7.1

Thanks Sam :) Can confirm it's working fine for my app (with Capybara no longer in my Gemfile)

@pat could you test #1893 for me to ensure that also resolves your issue too?

Was this page helpful?
0 / 5 - 0 ratings