[rspec-users] how can I do an "or" within the context of a matcher?
jko170 at gmail.com
Tue May 15 16:03:52 UTC 2012
On May 15, 2012, at 12:47 AM, Patrick J. Collins wrote:
> Capybara has two methods:
> ... I am wondering, how can I make a helper method that will be
> satisfied by one or the other? In other words, I want to be able to do:
> page.should have_link_or_button("blah")
> def have_link_or_button(locator)
> have_link(locator) || have_button(locator)
> But that doesn't work... Is there any way to do this?
> Patrick J. Collins
> rspec-users mailing list
> rspec-users at rubyforge.org
You need a custom matcher, something like this:
RSpec::Matchers.define :have_link_or_button do |locator|
match do |page|
page.has_button?(locator) || page.has_link?(locator)
BTW, I believe Capybara has a method that checks for a button *or* link - look into that.
More information about the rspec-users