diff --git a/src/spectator/should.cr b/src/spectator/should.cr index 4c63d2c..3be851f 100644 --- a/src/spectator/should.cr +++ b/src/spectator/should.cr @@ -17,21 +17,19 @@ class Object # require "spectator/should" # ``` def should(matcher) - # First argument of the `Expectation` initializer is the expression label. - # However, since this isn't a macro and we can't "look behind" this method call - # to see what it was invoked on, the argument is an empty string. - # Additionally, the source file and line can't be obtained. - actual = ::Spectator::TestValue.new(self) - source = ::Spectator::Source.new(__FILE__, __LINE__) - ::Spectator::Expectations::ExpectationPartial.new(actual, source).to(matcher) + actual = ::Spectator::Value.new(self) + match_data = matcher.match(actual) + expectation = ::Spectator::Expectation.new(match_data) + ::Spectator::Harness.current.report(expectation) end # Works the same as `#should` except the condition is inverted. # When `#should` succeeds, this method will fail, and vice-versa. def should_not(matcher) - actual = ::Spectator::TestValue.new(self) - source = ::Spectator::Source.new(__FILE__, __LINE__) - ::Spectator::Expectations::ExpectationPartial.new(actual, source).to_not(matcher) + actual = ::Spectator::Value.new(self) + match_data = matcher.negated_match(actual) + expectation = ::Spectator::Expectation.new(match_data) + ::Spectator::Harness.current.report(expectation) end # Works the same as `#should` except that the condition check is postphoned. @@ -51,17 +49,19 @@ struct Proc(*T, R) # Extension method to create an expectation for a block of code (proc). # Depending on the matcher, the proc may be executed multiple times. def should(matcher) - actual = ::Spectator::TestBlock.new(self) - source = ::Spectator::Source.new(__FILE__, __LINE__) - ::Spectator::Expectations::ExpectationPartial.new(actual, source).to(matcher) + actual = ::Spectator::Block.new(self) + match_data = matcher.match(actual) + expectation = ::Spectator::Expectation.new(match_data) + ::Spectator::Harness.current.report(expectation) end # Works the same as `#should` except the condition is inverted. # When `#should` succeeds, this method will fail, and vice-versa. def should_not(matcher) - actual = ::Spectator::TestBlock.new(self) - source = ::Spectator::Source.new(__FILE__, __LINE__) - ::Spectator::Expectations::BlockExpectationPartial.new(actual, source).to_not(matcher) + actual = ::Spectator::Block.new(self) + match_data = matcher.negated_match(actual) + expectation = ::Spectator::Expectation.new(match_data) + ::Spectator::Harness.current.report(expectation) end end