lib/expect/expectation_target.rb in expect-0.0.6 vs lib/expect/expectation_target.rb in expect-0.0.7
- old
+ new
@@ -1,35 +1,57 @@
+require_relative File.join 'exception', 'failure'
require_relative 'matcher'
module Expect
# Wraps the target of an expectation.
#
+ # @api private
+ #
# @example
- # this { stuff } # => ExpectationTarget wrapping the block
- class ExpectationTarget < BasicObject
+ # ExpectationTarget.new { 42 }.to equal: 42 # => true
+ class ExpectationTarget
+ # Create a new expection target
+ #
+ # @example
+ # ExpectationTarget.new { block of code }
+ #
+ # @yieldparam actual the value which is compared with the expected value.
def initialize(&actual)
@actual = actual
end
# Evaluate to a positive assertion.
#
# @api public
#
# @param [Hash, Symbol] definition
#
- # @return [Boolean] report if the expectation is true or false
+ # @return [Boolean] pass or fail the spec
def to(definition)
- Matcher.pass?(definition, &@actual)
+ match?(definition) || fail(Failure)
end
# Evaluate to a negative assertion.
#
# @api public
#
# @param [Hash, Symbol] definition
#
- # @return [Boolean] report if the expectation is true or false
+ # @return [Boolean] pass or fail the spec
def not_to(definition)
- to(definition).equal?(false)
+ match?(definition).equal?(false) || fail(Failure)
+ end
+
+ private
+
+ # Boolean comparison between the actual value and the expected value.
+ #
+ # @api private
+ #
+ # @param [Hash, Symbol] definition
+ #
+ # @return [Boolean] report if the expectation is true or false
+ def match?(definition)
+ Matcher.pass?(definition, &@actual)
end
end
end