Lord Raiden
2010-Sep-19 17:44 UTC
[rspec-users] 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. -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2010-Sep-19 18:16 UTC
[rspec-users] undefined method `has_selector?'' for "":String
On Sep 19, 2010, at 12:44 PM, Lord Raiden wrote:> 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.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
Toni Tuominen
2010-Sep-20 10:04 UTC
[rspec-users] undefined method `has_selector?'' for "":String
You should use this gem: http://github.com/grimen/rspec_tag_matchers - Toni On Sun, Sep 19, 2010 at 9:16 PM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Sep 19, 2010, at 12:44 PM, Lord Raiden wrote: > >> 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. > > 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Lord Raiden
2010-Sep-21 09:57 UTC
[rspec-users] undefined method `has_selector?'' for "":String
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_selectorThanks 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. -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2010-Sep-21 11:55 UTC
[rspec-users] undefined method `has_selector?'' for "":String
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. 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.
David Chelimsky
2010-Sep-21 11:56 UTC
[rspec-users] undefined method `has_selector?'' for "":String
On Sep 21, 2010, at 6:55 AM, David Chelimsky wrote:> 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. > > 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 :) http://github.com/jnicklas/capybara/issues#issue/139
Wincent Colaiuta
2010-Sep-21 13:40 UTC
[rspec-users] undefined method `has_selector?'' for "":String
El 21/09/2010, a las 13:55, David Chelimsky escribi?:> On Sep 21, 2010, at 4:57 AM, Lord Raiden wrote: > >> David Chelimsky 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
Lord Raiden
2010-Sep-22 03:11 UTC
[rspec-users] undefined method `has_selector?'' for "":String
> 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, > WincentWincent 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. -- Posted via http://www.ruby-forum.com/.