Method: RSpec::Expectations::ExpectationTarget::InstanceMethods#to

Defined in:
lib/rspec/expectations/expectation_target.rb

#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