mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
More multi value stub tests
This commit is contained in:
parent
667c05b484
commit
f17cc73487
3 changed files with 78 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue