Module: CapybaraTestHelpers::ToOrExpectationHandler

Defined in:
lib/capybara_test_helpers/to_or_expectation_handler.rb

Overview

Internal: Used heavily in the RSpec matchers, makes it very easy to create a dual assertion (can be used as positive or negative).

See maximomussini.com/posts/cucumber-to_or_not_to/

Instance Method Summary collapse

Instance Method Details

#to_or(not_to, matcher, message = nil, &block) ⇒ Object

Public: Allows a more convenient definition of should/should not Gherkin steps.

Example:

Then(/^I should (not )?see "(.*)"$/) do |not_to, text|
  expect(page).to_or not_to, have_content(text)
end


18
19
20
21
22
23
24
# File 'lib/capybara_test_helpers/to_or_expectation_handler.rb', line 18

def to_or(not_to, matcher, message = nil, &block)
  if not_to
    not_to(matcher, message, &block)
  else
    to(matcher, message, &block)
  end
end