mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Use location of the 'should' keyword for their expectation
This commit is contained in:
parent
faff2933e6
commit
acf810553a
2 changed files with 19 additions and 12 deletions
|
@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Fixed
|
||||
- Fix invalid syntax (unterminated call) when recording calls to stubs with an un-named splat.
|
||||
|
||||
### Changed
|
||||
- Expectations using 'should' syntax report file and line where the 'should' keyword is instead of the test start.
|
||||
|
||||
## [0.11.5] - 2022-12-18
|
||||
### Added
|
||||
- Added support for mock modules and types that include mocked modules.
|
||||
|
|
|
@ -22,51 +22,55 @@ class Object
|
|||
# ```
|
||||
# require "spectator/should"
|
||||
# ```
|
||||
def should(matcher, message = nil)
|
||||
def should(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
|
||||
actual = ::Spectator::Value.new(self)
|
||||
location = ::Spectator::Location.new(_file, _line)
|
||||
match_data = matcher.match(actual)
|
||||
expectation = ::Spectator::Expectation.new(match_data, message: message)
|
||||
expectation = ::Spectator::Expectation.new(match_data, location, message)
|
||||
::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, message = nil)
|
||||
def should_not(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
|
||||
actual = ::Spectator::Value.new(self)
|
||||
location = ::Spectator::Location.new(_file, _line)
|
||||
match_data = matcher.negated_match(actual)
|
||||
expectation = ::Spectator::Expectation.new(match_data, message: message)
|
||||
expectation = ::Spectator::Expectation.new(match_data, location, message)
|
||||
::Spectator::Harness.current.report(expectation)
|
||||
end
|
||||
|
||||
# Works the same as `#should` except that the condition check is postponed.
|
||||
# The expectation is checked after the example finishes and all hooks have run.
|
||||
def should_eventually(matcher, message = nil)
|
||||
::Spectator::Harness.current.defer { should(matcher, message) }
|
||||
def should_eventually(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
|
||||
::Spectator::Harness.current.defer { should(matcher, message, _file: _file, _line: _line) }
|
||||
end
|
||||
|
||||
# Works the same as `#should_not` except that the condition check is postponed.
|
||||
# The expectation is checked after the example finishes and all hooks have run.
|
||||
def should_never(matcher, message = nil)
|
||||
::Spectator::Harness.current.defer { should_not(matcher, message) }
|
||||
def should_never(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
|
||||
::Spectator::Harness.current.defer { should_not(matcher, message, _file: _file, _line: _line) }
|
||||
end
|
||||
end
|
||||
|
||||
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, message = nil)
|
||||
def should(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
|
||||
actual = ::Spectator::Block.new(self)
|
||||
location = ::Spectator::Location.new(_file, _line)
|
||||
match_data = matcher.match(actual)
|
||||
expectation = ::Spectator::Expectation.new(match_data, message: message)
|
||||
expectation = ::Spectator::Expectation.new(match_data, location, message)
|
||||
::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, message = nil)
|
||||
def should_not(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
|
||||
actual = ::Spectator::Block.new(self)
|
||||
location = ::Spectator::Location.new(_file, _line)
|
||||
match_data = matcher.negated_match(actual)
|
||||
expectation = ::Spectator::Expectation.new(match_data, message: message)
|
||||
expectation = ::Spectator::Expectation.new(match_data, location, message)
|
||||
::Spectator::Harness.current.report(expectation)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue