More multi value stub tests

This commit is contained in:
Michael Miller 2022-07-09 21:48:22 -06:00
parent 667c05b484
commit f17cc73487
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 78 additions and 1 deletions

View file

@ -18,13 +18,18 @@ Spectator.describe Spectator::MultiValueStub do
values = Array.new(3) { stub.call(method_call) }
expect(values).to eq([3, 5, 7])
end
it "returns the final value after exhausting other values" do
values = Array.new(5) { stub.call(method_call) }
expect(values).to eq([3, 5, 7, 7, 7])
end
end
context Spectator::StubModifiers do
describe "#and_return(value)" do
let(arguments) { Spectator::Arguments.capture(/foo/) }
let(location) { Spectator::Location.new(__FILE__, __LINE__) }
let(original) { Spectator::ValueStub.new(:foo, 42, arguments, location) }
let(original) { Spectator::MultiValueStub.new(:foo, [3, 5, 7], arguments, location) }
subject(stub) { original.and_return(123) }
it "produces a stub that returns a value" do
@ -43,6 +48,30 @@ Spectator.describe Spectator::MultiValueStub do
expect(stub.location).to eq(location)
end
end
describe "#and_return(*values)" do
let(arguments) { Spectator::Arguments.capture(/foo/) }
let(location) { Spectator::Location.new(__FILE__, __LINE__) }
let(original) { Spectator::MultiValueStub.new(:foo, [3, 5, 7], arguments, location) }
subject(stub) { original.and_return(3, 2, 1, 0) }
it "produces a stub that returns values" do
values = Array.new(5) { stub.call(method_call) }
expect(values).to eq([3, 2, 1, 0, 0])
end
it "retains the method name" do
expect(stub.method).to eq(:foo)
end
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
describe "#===" do

View file

@ -40,6 +40,30 @@ Spectator.describe Spectator::NullStub do
expect(stub.location).to eq(location)
end
end
describe "#and_return(*values)" do
let(arguments) { Spectator::Arguments.capture(/foo/) }
let(location) { Spectator::Location.new(__FILE__, __LINE__) }
let(original) { Spectator::NullStub.new(:foo, arguments, location) }
subject(stub) { original.and_return(3, 2, 1, 0) }
it "produces a stub that returns values" do
values = Array.new(5) { stub.call(method_call) }
expect(values).to eq([3, 2, 1, 0, 0])
end
it "retains the method name" do
expect(stub.method).to eq(:foo)
end
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
describe "#===" do

View file

@ -40,6 +40,30 @@ Spectator.describe Spectator::ValueStub do
expect(stub.location).to eq(location)
end
end
describe "#and_return(*values)" do
let(arguments) { Spectator::Arguments.capture(/foo/) }
let(location) { Spectator::Location.new(__FILE__, __LINE__) }
let(original) { Spectator::ValueStub.new(:foo, 42, arguments, location) }
subject(stub) { original.and_return(3, 2, 1, 0) }
it "produces a stub that returns values" do
values = Array.new(5) { stub.call(method_call) }
expect(values).to eq([3, 2, 1, 0, 0])
end
it "retains the method name" do
expect(stub.method).to eq(:foo)
end
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
describe "#===" do