Module: RSpec::Expectations::ExpectationTarget::InstanceMethods

Included in:
RSpec::Expectations::ExpectationTarget
Defined in:
lib/rspec/expectations/expectation_target.rb

Overview

Defines instance RSpec::Expectations::ExpectationTarget instance methods. These are defined in a module so we can include it in Minitest::Expectation when rspec/expectations/minitest_integration is loaded in order to support usage with Minitest.

Instance Method Summary collapse

Instance Method Details

#not_to(matcher = nil, message = nil, &block) ⇒ Boolean Also known as: to_not

Runs the given expectation, passing if matcher returns false.

Examples:

expect(value).not_to eq(5)

Parameters:

  • matcher (Matcher) (defaults to: nil)
  • message (String, Proc) (defaults to: nil)

    optional message to display when the expectation fails

Returns:

  • (Boolean)

    false if the negative expectation succeeds (else raises)

See Also:

76
77
78
79
# File 'lib/rspec/expectations/expectation_target.rb', line 76
def not_to(matcher=nil, message=nil, &block)
  prevent_operator_matchers(:not_to) unless matcher
  RSpec::Expectations::NegativeExpectationHandler.handle_matcher(target, matcher, message, &block)
end

#to(matcher = nil, message = nil, &block) ⇒ Boolean

Runs the given expectation, passing if matcher returns true.

Examples:

expect(value).to eq(5)
expect { perform }.to raise_error

Parameters:

  • matcher (Matcher) (defaults to: nil)
  • message (String, Proc) (defaults to: nil)

    optional message to display when the expectation fails

Returns:

  • (Boolean)

    true if the expectation succeeds (else raises)

See Also:

63
64
65
66
# File 'lib/rspec/expectations/expectation_target.rb', line 63
def to(matcher=nil, message=nil, &block)
  prevent_operator_matchers(:to) unless matcher
  RSpec::Expectations::PositiveExpectationHandler.handle_matcher(target, matcher, message, &block)
end