mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Fix reporting for should syntax
This commit is contained in:
parent
97923d6bcd
commit
3ec267abbb
1 changed files with 16 additions and 16 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue