Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Capybara for Rails 2.3 and Rspec

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
like image 857
existentialmutt Avatar asked Dec 12 '22 13:12

existentialmutt


2 Answers

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

like image 169
jconley Avatar answered Dec 25 '22 01:12

jconley


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)

like image 42
Breno Salgado Avatar answered Dec 25 '22 01:12

Breno Salgado