[rspec-users] undefined method `has_selector?' for "":String

David Chelimsky dchelimsky at gmail.com
Tue Sep 21 07:55:21 EDT 2010

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

> David Chelimsky 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.

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.


> 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.

More information about the rspec-users mailing list