mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
93 lines
3.1 KiB
Crystal
93 lines
3.1 KiB
Crystal
require "../../spec_helper"
|
|
|
|
Spectator.describe Spectator::ReferenceMockRegistry do
|
|
subject(registry) { described_class.new }
|
|
let(obj) { "foobar" }
|
|
let(stub) { Spectator::ValueStub.new(:test, 42) }
|
|
let(stubs) { [stub] of Spectator::Stub }
|
|
let(no_stubs) { [] of Spectator::Stub }
|
|
let(call) { Spectator::MethodCall.capture(:method2, 5) }
|
|
let(calls) { [call] }
|
|
let(no_calls) { [] of Spectator::MethodCall }
|
|
|
|
it "initially has no stubs" do
|
|
expect(registry[obj].stubs).to be_empty
|
|
end
|
|
|
|
it "initially has no calls" do
|
|
expect(registry[obj].calls).to be_empty
|
|
end
|
|
|
|
it "stores stubs for an object" do
|
|
expect { registry[obj].stubs << stub }.to change { registry[obj].stubs }.from(no_stubs).to(stubs)
|
|
end
|
|
|
|
it "stores calls for an object" do
|
|
expect { registry[obj].calls << call }.to change { registry[obj].calls }.from(no_calls).to(calls)
|
|
end
|
|
|
|
it "isolates stubs between different objects" do
|
|
obj1 = "foo"
|
|
obj2 = "bar"
|
|
registry[obj2].stubs << Spectator::ValueStub.new(:obj2, 42)
|
|
expect { registry[obj1].stubs << stub }.to_not change { registry[obj2].stubs }
|
|
end
|
|
|
|
it "isolates calls between different objects" do
|
|
obj1 = "foo"
|
|
obj2 = "bar"
|
|
registry[obj2].calls << Spectator::MethodCall.capture(:method1, 42)
|
|
expect { registry[obj1].calls << call }.to_not change { registry[obj2].calls }
|
|
end
|
|
|
|
describe "#fetch" do
|
|
it "retrieves existing stubs" do
|
|
registry[obj].stubs << stub
|
|
expect(registry.fetch(obj) { no_stubs }.stubs).to eq(stubs)
|
|
end
|
|
|
|
it "stores stubs on the first retrieval" do
|
|
expect(registry.fetch(obj) { stubs }.stubs).to eq(stubs)
|
|
end
|
|
|
|
it "isolates stubs between different objects" do
|
|
obj1 = "foo"
|
|
obj2 = "bar"
|
|
registry[obj2].stubs << Spectator::ValueStub.new(:obj2, 42)
|
|
expect { registry.fetch(obj1) { no_stubs }.stubs }.to_not change { registry[obj2].stubs }
|
|
end
|
|
|
|
it "isolates calls between different objects" do
|
|
obj1 = "foo"
|
|
obj2 = "bar"
|
|
registry[obj2].calls << Spectator::MethodCall.capture(:method1, 42)
|
|
expect { registry.fetch(obj1) { no_stubs }.calls }.to_not change { registry[obj2].calls }
|
|
end
|
|
end
|
|
|
|
describe "#delete" do
|
|
it "clears stubs for an object" do
|
|
registry[obj].stubs << stub
|
|
expect { registry.delete(obj) }.to change { registry[obj].stubs }.from(stubs).to(no_stubs)
|
|
end
|
|
|
|
it "doesn't clear initial stubs provided with #fetch" do
|
|
registry[obj].stubs << Spectator::ValueStub.new(:stub2, 42)
|
|
expect { registry.delete(obj) }.to change { registry.fetch(obj) { stubs }.stubs }.to(stubs)
|
|
end
|
|
|
|
it "isolates stubs between different objects" do
|
|
obj1 = "foo"
|
|
obj2 = "bar"
|
|
registry[obj2].stubs << Spectator::ValueStub.new(:obj2, 42)
|
|
expect { registry.delete(obj1) }.to_not change { registry[obj2].stubs }
|
|
end
|
|
|
|
it "isolates calls between different objects" do
|
|
obj1 = "foo"
|
|
obj2 = "bar"
|
|
registry[obj2].calls << Spectator::MethodCall.capture(:method1, 42)
|
|
expect { registry.delete(obj1) }.to_not change { registry[obj2].calls }
|
|
end
|
|
end
|
|
end
|