Test stub location

This commit is contained in:
Michael Miller 2022-04-02 12:09:59 -06:00
parent 873b1abcae
commit be1c698836
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
2 changed files with 18 additions and 3 deletions

View file

@ -2,12 +2,17 @@ require "../../spec_helper"
Spectator.describe Spectator::NullStub do
let(method_call) { Spectator::MethodCall.capture(:foo) }
subject(stub) { described_class.new(:foo) }
let(location) { Spectator::Location.new(__FILE__, __LINE__) }
subject(stub) { described_class.new(:foo, location: location) }
it "stores the method name" do
expect(stub.method).to eq(:foo)
end
it "stores the location" do
expect(stub.location).to eq(location)
end
it "returns nil" do
expect(stub.call(method_call)).to be_nil
end
@ -15,7 +20,8 @@ Spectator.describe Spectator::NullStub do
context Spectator::StubModifiers do
describe "#and_return(value)" do
let(arguments) { Spectator::Arguments.capture(/foo/) }
let(original) { Spectator::NullStub.new(:foo, arguments) }
let(location) { Spectator::Location.new(__FILE__, __LINE__) }
let(original) { Spectator::NullStub.new(:foo, arguments, location) }
subject(stub) { original.and_return(42) }
it "produces a stub that returns a value" do
@ -29,6 +35,10 @@ Spectator.describe Spectator::NullStub do
it "retains the arguments constraint" do
expect(stub.constraint).to eq(arguments)
end
it "retains the location" do
expect(stub.location).to eq(location)
end
end
end

View file

@ -2,12 +2,17 @@ require "../../spec_helper"
Spectator.describe Spectator::ValueStub do
let(method_call) { Spectator::MethodCall.capture(:foo) }
subject(stub) { Spectator::ValueStub.new(:foo, 42) }
let(location) { Spectator::Location.new(__FILE__, __LINE__) }
subject(stub) { described_class.new(:foo, 42, location: location) }
it "stores the method name" do
expect(stub.method).to eq(:foo)
end
it "stores the location" do
expect(stub.location).to eq(location)
end
it "stores the return value" do
expect(stub.call(method_call)).to eq(42)
end