[rspec-users] undefined method `contain' for #<RSpec::Core::ExampleGroup::Nested_1:0x10595b1a8>

David Chelimsky dchelimsky at gmail.com
Wed Nov 10 11:03:24 EST 2010

On Nov 10, 2010, at 5:44 AM, Chad Ostrowski wrote:

> Here's my Gemfile:
> group :development, :test do
>   gem 'rspec-rails', '2.0.0'
>   gem 'cucumber-rails', '0.3.2'
>   gem 'capybara', '0.4.0.rc'
> end
> and here's my spec:
> describe "welcome/index.html.haml" do
>   it "displays 'Problem Child' in the header" do
>     render
>     rendered.should contain("Problem Child")
>   end
> end
> This results in the error given in the subject:
> Failures:
>   1) welcome/index.html.haml displays 'Problem Child' in the header
>      Failure/Error: rendered.should contain("Problem Child")
>      undefined method `contain' for #<RSpec::Core::ExampleGroup::Nested_1:0x10595b1a8>
> Does the "contain" matcher come with Webrat? Is that why the RSpec book seems to be lying to me? I'm trying to get the feel of RSpec and I love the idea of speccing views. I've been approximately following along with The RSpec Book. I'm using Capybara instead of Webrat because Webrat wasn't playing well with Rails 3 (I forget the details).

The book says "these examples use Webrat" and you choose Capybara (a perfectly good option, but not for the examples in the book). Not sure who is lying to you, but it is not the book :)

Webrat works fine for all of the examples in the book. I'd recommend using it to go through the book to get the feel for the process.

Also, Capybara's matchers are not available in view specs or helper specs (see https://github.com/rspec/rspec-rails/issues/closed#issue/242).


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101110/17700a13/attachment.html>

More information about the rspec-users mailing list