Undefined method `has_selector?' for "":String

I’m running rails 3.0.0 on ruby 1.9.2p0.

I’ve rspec beta 22 with Capybara 0.3.9. NO WEBRAT.

I’m unable to use 'rendered.should have_selector(‘a’) in my view specs.

  1. home/_menu.erb should add a link to home first
    Failure/Error: rendered.should have_selector(‘a’, ‘Home’)
    undefined method `has_selector?’ for “”:String

I read in this forum that rspec beta 20 and above should pick Capybara
automatically if its included in Gemfile.

In my gem file I’ve this:

group :development, :test do
gem ‘database_cleaner’
gem ‘cucumber-rails’
gem ‘cucumber’
gem ‘rspec-rails’, “>= 2.0.0.beta.19”
gem ‘capybara’
gem ‘spork’
gem ‘launchy’ # So you can do Then show me the page
gem ‘machinist’, ‘>= 2.0.0.beta1’
end

Can anyone please point out what am I missing here? Thanks in advance.

On Sep 19, 2010, at 12:44 PM, Lord Raiden wrote:

I read in this forum that rspec beta 20 and above should pick Capybara
gem ‘spork’
gem ‘launchy’ # So you can do Then show me the page
gem ‘machinist’, ‘>= 2.0.0.beta1’
end

Can anyone please point out what am I missing here? Thanks in advance.

Two issues:

  1. Capybara matchers do not support arbitrary strings, so they do not
    work in view specs
  2. Even if they did, the capybara matcher would be has_css, not
    has_selector

You should use this gem: http://github.com/grimen/rspec_tag_matchers

  • Toni

David C. wrote:

Two issues:

  1. Capybara matchers do not support arbitrary strings, so they do not
    work in view specs
  2. Even if they did, the capybara matcher would be has_css, not
    has_selector

Thanks for quick reply. Sorry about my delay (I was sick and down).

I’m not an expert in these tools, so please bear with me.

Is there anyway to get Capybara to work with view:specs? May be by doing
something Cucumber is doing to get Capybara to work with it.

Reason I’m asking is I really want to write few view specs, (outside of
cucumber), and I would like not to use Webrat, to keep things clean.

It seems the gem Tony pointed out can help, but as I said I would rather
not use it if there is any hack which could let me use Capybara for
rspec view specs.

On Sep 21, 2010, at 4:57 AM, Lord Raiden wrote:

I’m not an expert in these tools, so please bear with me.

Is there anyway to get Capybara to work with view:specs? May be by doing
something Cucumber is doing to get Capybara to work with it.

Not now. Capybara is designed to work with a Rack application. View
specs are built on Rails’ ActionView::TestCase, which is designed to
make an isolated call into the rendering framework, and get back a
String. They don’t know anything about requests or sessions, so the
Capybara matchers don’t work.

I’ve talked to Jonas about extracting the matchers so they can work with
arbitrary Strings. He’s interested in the idea, but it won’t likely
happen for a while due to other priorities. I’ve added an issue [1],
which you are welcome to comment on and follow.

Reason I’m asking is I really want to write few view specs, (outside of
cucumber), and I would like not to use Webrat, to keep things clean.

Why would Webrat be any less clean in this case? The matchers are pretty
much the same, and that’s all you need. Are you using Capybara in
controller specs? If not, I’d recommend using Webrat with RSpec and
Capybara with Cucumber.

HTH,
David

On Sep 21, 2010, at 6:55 AM, David C. wrote:

Thanks for quick reply. Sorry about my delay (I was sick and down).
Reason I’m asking is I really want to write few view specs, (outside of
cucumber), and I would like not to use Webrat, to keep things clean.

Why would Webrat be any less clean in this case? The matchers are pretty much the same, and that’s all you need. Are you using Capybara in controller specs? If not, I’d recommend using Webrat with RSpec and Capybara with Cucumber.

HTH,
David

It seems the gem Tony pointed out can help, but as I said I would rather
not use it if there is any hack which could let me use Capybara for
rspec view specs.

Forgot to include the issue :slight_smile:

http://github.com/jnicklas/capybara/issues#issue/139

El 21/09/2010, a las 13:55, David C.
escribió:

On Sep 21, 2010, at 4:57 AM, Lord Raiden wrote:

David C. wrote:

Reason I’m asking is I really want to write few view specs, (outside of
cucumber), and I would like not to use Webrat, to keep things clean.

Why would Webrat be any less clean in this case? The matchers are pretty much the same, and that’s all you need. Are you using Capybara in controller specs? If not, I’d recommend using Webrat with RSpec and Capybara with Cucumber.

I think the issue is that even though they are effectively the same in
terms of their capabilities (ie. they both wrap Nokogiri AFAIK), the
names of the matchers are slightly different so you end up having to use
two different sets of language depending on whether you’re writing view
specs or acceptance specs. (This is probably less of an issue for
Cucumber users because the Cucumber steps are another layer of
abstraction over the top of the matchers, but if you’re a Steak user,
then you’re always working directly with the matcher APIs).

I’m using Steak + Capybara right now for acceptance specs and Webrat for
my view specs, but I’d prefer to be able to use Capybara matchers for
everything in order to avoid the duplication of two very similar but
slightly different APIs.

Cheers,
Wincent

I’d prefer to be able to use Capybara matchers for
everything in order to avoid the duplication of two very similar but
slightly different APIs.

Cheers,
Wincent

Wincent pointed out my exact feelings on the matter (Probably in a
better way than I could have.)

But I’m willing to follow David’s advice if that’s the only way for now,
and it works without clashes.

/Thanks guys.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs