mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Test contexts and memoized values
This commit is contained in:
parent
a6fc2a4917
commit
f6f4f9dc1e
2 changed files with 58 additions and 0 deletions
|
@ -294,4 +294,44 @@ Spectator.describe "Double DSL" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "context" do
|
||||||
|
double(:context_double, predefined: :predefined, override: :predefined) do
|
||||||
|
stub abstract def memoize : Symbol
|
||||||
|
|
||||||
|
stub def inline : Symbol
|
||||||
|
:inline # Memoized values can't be used here.
|
||||||
|
end
|
||||||
|
|
||||||
|
stub def reference : String
|
||||||
|
memoize.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
let(memoize) { :memoize }
|
||||||
|
let(override) { :override }
|
||||||
|
let(dbl) { double(:context_double, override: override) }
|
||||||
|
|
||||||
|
before_each { allow(dbl).to receive(:memoize).and_return(memoize) }
|
||||||
|
|
||||||
|
it "doesn't change predefined values" do
|
||||||
|
expect(dbl.predefined).to eq(:predefined)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can use memoized values for overrides" do
|
||||||
|
expect(dbl.override).to eq(:override)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can use memoized values for stubs" do
|
||||||
|
expect(dbl.memoize).to eq(:memoize)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can override inline stubs" do
|
||||||
|
expect { allow(dbl).to receive(:inline).and_return(override) }.to change { dbl.inline }.from(:inline).to(:override)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can reference memoized values with indirection" do
|
||||||
|
expect { allow(dbl).to receive(:memoize).and_return(override) }.to change { dbl.reference }.from("memoize").to("override")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -62,4 +62,22 @@ Spectator.describe "Lazy double DSL" do
|
||||||
expect(dbl.foo).to eq(42)
|
expect(dbl.foo).to eq(42)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "context" do
|
||||||
|
let(memoize) { :memoize }
|
||||||
|
let(override) { :override }
|
||||||
|
let(dbl) { double(predefined: :predefined, memoize: memoize) }
|
||||||
|
|
||||||
|
it "doesn't change predefined values" do
|
||||||
|
expect(dbl.predefined).to eq(:predefined)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can use memoized values for stubs" do
|
||||||
|
expect(dbl.memoize).to eq(:memoize)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can stub methods with memoized values" do
|
||||||
|
expect { allow(dbl).to receive(:memoize).and_return(override) }.to change { dbl.memoize }.from(:memoize).to(:override)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue