class RSpec::Expectations::ExpectationTarget
directly by users. Use ‘expect` instead.
@note `ExpectationTarget` is not intended to be instantiated
expect(actual).not_to eq(3)
# with `not_to`
expect(actual).to eq(3)
# used with `to`
expect { do_something } # => ExpectationTarget wrapping the block
expect(something) # => ExpectationTarget wrapping something
@example
Wraps the target of an expectation.
def self.disable_deprecated_should
def self.disable_deprecated_should return unless deprecated_should_enabled? remove_method :should remove_method :should_not self.deprecated_should_enabled = false end
def self.enable_deprecated_should
def self.enable_deprecated_should return if deprecated_should_enabled? def should(*args) RSpec.deprecate "`expect { }.should`", :replacement => "`expect { }.to`" @target.should(*args) end def should_not(*args) RSpec.deprecate "`expect { }.should_not`", :replacement => "`expect { }.not_to`" @target.should_not(*args) end self.deprecated_should_enabled = true end
def self.for(value, block)
- Private: -
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
def initialize(value)
- Api: - private
def initialize(value) @target = value end
def not_to(matcher=nil, message=nil, &block)
- See: RSpec::Matchers -
Returns:
-
(Boolean)- false if the negative expectation succeeds (else raises)
Parameters:
-
message(String) -- optional message to display when the expectation fails -
(Matcher) --
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
def prevent_operator_matchers(verb)
def prevent_operator_matchers(verb) raise ArgumentError, "The expect syntax does not support operator matchers, " + "so you must pass a matcher to `##{verb}`." end
def should(*args)
def should(*args) RSpec.deprecate "`expect { }.should`", :replacement => "`expect { }.to`" @target.should(*args) end
def should_not(*args)
def should_not(*args) RSpec.deprecate "`expect { }.should_not`", :replacement => "`expect { }.not_to`" @target.should_not(*args) end
def to(matcher=nil, message=nil, &block)
- See: RSpec::Matchers -
Returns:
-
(Boolean)- true if the expectation succeeds (else raises)
Parameters:
-
message(String) -- optional message to display when the expectation fails -
(Matcher) --
def to(matcher=nil, message=nil, &block) prevent_operator_matchers(:to) unless matcher RSpec::Expectations::PositiveExpectationHandler.handle_matcher(@target, matcher, message, &block) end