4

I'm having some trouble setting up capybara (0.4.1.2) in a rails 2.3.8 app with Rspec 1.3 From the installation capybara instructions, I've inserted the line:

require 'capybara/rspec' 

However that gives me a missing constant error. Seems like it's looking for a class 'RSpec' which isn't loaded (I'm guessing that's an RSpec 2 / Rails 3 thing).

So how do I get Rspec to recognize capybara under rails 2.3? Should I use an earlier version of capy?

PS. Here's a snippet of the backtrace:

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|443| in `load_missing_constant': uninitialized constant RSpec (NameError)

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|80| in `const_missing_not_from_s3_library'

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb|206| in `const_missing'

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|92| in `const_missing'

||  from /Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/capybara-0.4.1.2/lib/capybara/rspec.rb:4


/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/rails-2.3.5/lib/rails/gem_dependency.rb|119| Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010.  Use #requirement

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|443| in `load_missing_constant': uninitialized constant RSpec (NameError)

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|80| in `const_missing_not_from_s3_library'

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb|206| in `const_missing'

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|92| in `const_missing'

|   from /Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/capybara-0.4.1.2/lib/capybara/rspec.rb:4

/Users/rafe/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb|31| in `gem_original_require'

/Users/rafe/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb|31| in `require'

/Users/rafe/.rvm/gems/ruby-1.8.6-p399@lci/gems/activesupport-2.3.5/lib/active_support/dependencies.rb|158| in `require'

||  from /Users/rafe/cmi/lci/branches/forums/spec/spec_helper.rb:12
Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
existentialmutt
  • 446
  • 5
  • 12

3 Answers3

5

it seems steak isn't really needed if, say, you just want to do 'request specs'(as defined in railscasts's "how I test"). Also see: What does Steak add beyond just using Capybara and RSpec in Rails testing?

I've just set up rails 2.3 + rspec 1 + capybara(latest version) here and there wasn't any hassle

you can't have require capybara/rspec, but it seems all it does is add some matchers... but what matters really is capybara and its DSL and validating stuff

Capybara works with any rack app

on my spec_helper.rb:

require 'capybara/rails'
include Capybara::DSL

and that's it (just hit the docs for Capybara and it's DSL because some rspec-capybara matchers may be missing, nothing that would be blocking, tho)

Community
  • 1
  • 1
Breno Salgado
  • 1,922
  • 1
  • 20
  • 26
  • I am getting this error: uninitialized constant Capybara::DSL (NameError) – RAJ Jul 24 '12 at 11:50
  • 1
    I'd suggest doing a bit of debugging on your spec_helper.rb... I THINK it could be because we're already using bundler on this rails 2.3 project, so Bundler could be requiring capybara automatically for me... look at Capybara doc and see which file requires capybara/dsl, maybe `require 'capybara'` on top of spec_helper.rb will do the trick – Breno Salgado Jul 25 '12 at 15:11
5

Capybara does not have built in support for RSpec 1.x. However, you can use Steak instead of rolling your own RSpec support.

jconley
  • 606
  • 4
  • 3
3

From the Capybara doc,

Note that Capybara’s built in RSpec support only works with RSpec 2.0 or later. You’ll need to roll your own for earlier versions of RSpec.

mculp
  • 2,637
  • 1
  • 25
  • 34