diff --git a/src/spectator/dsl/mocks.cr b/src/spectator/dsl/mocks.cr index c7126f4..06d7346 100644 --- a/src/spectator/dsl/mocks.cr +++ b/src/spectator/dsl/mocks.cr @@ -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 diff --git a/src/spectator/mocks/stub.cr b/src/spectator/mocks/stub.cr index ee7b6ee..486d429 100644 --- a/src/spectator/mocks/stub.cr +++ b/src/spectator/mocks/stub.cr @@ -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. diff --git a/src/spectator/mocks/value_stub.cr b/src/spectator/mocks/value_stub.cr index 2ae597b..d902be6 100644 --- a/src/spectator/mocks/value_stub.cr +++ b/src/spectator/mocks/value_stub.cr @@ -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