Hi all, I''m trying to emulate the have_tag matcher that used to be in rspec-rails. How would I do that with the rspec 2 interface? html.should have_tag("div") do with_tag("span") end RSpec::Matchers.define won''t let me pass in a block. I could extend the RSpec::Matchers module but I''m not sure if that''s the way to do it anymore. Any guidance would be helpful! Abhik -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110105/b81f6887/attachment.html>
David Chelimsky
2011-Jan-10 04:07 UTC
[rspec-users] Writing a matcher that accepts a block
On Jan 5, 2011, at 11:11 AM, Abhik Pramanik wrote:> Hi all, > > I''m trying to emulate the have_tag matcher that used to be in rspec-rails. How would I do that with the rspec 2 interface? > > html.should have_tag("div") do > with_tag("span") > end > > RSpec::Matchers.define won''t let me pass in a block. I could extend the RSpec::Matchers module but I''m not sure if that''s the way to do it anymore. Any guidance would be helpful!I''d recommend not doing this. Webrat and Capybara matchers both work very well for this and there is no need to roll your own by hacking RSpec. html.should have_selector("div span") FWIW, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110109/fd4281e1/attachment.html>
Yah I know. They''re not available in view tests. Someone had posted a question about this on the Capybara users group and the response was to write your own. Abhik -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110109/fcd30d3d/attachment-0001.html>
Anyways I got it working, so no need for help. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110109/55215f65/attachment.html>