Wraps the target of an expectation.
@example
expect(something) # => ExpectationTarget wrapping something expect { do_something } # => ExpectationTarget wrapping the block # used with `to` expect(actual).to eq(3) # with `not_to` expect(actual).not_to eq(3)
@note `ExpectationTarget` is not intended to be instantiated
directly by users. Use `expect` instead.
@private Used as a sentinel value to be able to tell when the user did not pass an argument. We can’t use `nil` for that because `nil` is a valid value to pass.
@private
# File lib/rspec/expectations/expectation_target.rb, line 30 def self.for(value, block) if UndefinedValue.equal?(value) unless block raise ArgumentError, "You must pass either an argument or a block to `expect`." end BlockExpectationTarget.new(block) elsif block raise ArgumentError, "You cannot pass both an argument and a block to `expect`." else new(value) end end
Runs the given expectation, passing if `matcher` returns false. @example
expect(value).not_to eq(5)
@param [Matcher]
matcher
@param [String or Proc] message optional message to display when the expectation fails @return [Boolean] false if the negative expectation succeeds (else raises) @see RSpec::Matchers
# File lib/rspec/expectations/expectation_target.rb, line 65 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
Runs the given expectation, passing if `matcher` returns true. @example
expect(value).to eq(5) expect { perform }.to raise_error
@param [Matcher]
matcher
@param [String or Proc] message optional message to display when the expectation fails @return [Boolean] true if the expectation succeeds (else raises) @see RSpec::Matchers
# File lib/rspec/expectations/expectation_target.rb, line 52 def to(matcher=nil, message=nil, &block) prevent_operator_matchers(:to) unless matcher RSpec::Expectations::PositiveExpectationHandler.handle_matcher(@target, matcher, message, &block) end
Generated with the Darkfish Rdoc Generator 2.