Store location information in stub

Allows tracking where a stub was originally defined.
This commit is contained in:
Michael Miller 2022-04-02 10:39:59 -06:00
parent e61b31e47b
commit 318e4f3707
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 9 additions and 5 deletions

View file

@ -167,8 +167,8 @@ module Spectator::DSL
# allow(dbl).to receive(:foo).and_return(42)
# expect(dbl.foo).to eq(42)
# ```
macro receive(method)
::Spectator::NullStub.new({{method.id.symbolize}})
macro receive(method, *, _file = __FILE__, _line = __LINE__)
::Spectator::NullStub.new({{method.id.symbolize}}, location: ::Spectator::Location.new({{_file}}, {{_line}}))
end
end
end

View file

@ -12,8 +12,11 @@ module Spectator
# Is nil when there's no constraint - only the method name must match.
getter constraint : AbstractArguments?
# Location the stub was defined.
getter location : Location?
# Creates the base of the stub.
def initialize(@method : Symbol, @constraint : AbstractArguments? = nil)
def initialize(@method : Symbol, @constraint : AbstractArguments? = nil, @location : Location? = nil)
end
# Checks if a method call should receive the response from this stub.

View file

@ -1,3 +1,4 @@
require "../location"
require "./arguments"
require "./typed_stub"
@ -10,8 +11,8 @@ module Spectator
end
# Creates the stub.
def initialize(method : Symbol, @value : T, constraint : AbstractArguments? = nil)
super(method, constraint)
def initialize(method : Symbol, @value : T, constraint : AbstractArguments? = nil, location : Location? = nil)
super(method, constraint, location)
end
end
end