mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Test ValueStub
This commit is contained in:
parent
ae14a47329
commit
7c8db07eda
1 changed files with 62 additions and 0 deletions
62
spec/spectator/mocks/value_stub_spec.cr
Normal file
62
spec/spectator/mocks/value_stub_spec.cr
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
require "../../spec_helper"
|
||||||
|
|
||||||
|
Spectator.describe Spectator::ValueStub do
|
||||||
|
subject(stub) { Spectator::ValueStub.new(:foo, 42) }
|
||||||
|
|
||||||
|
it "stores the method name" do
|
||||||
|
expect(stub.method).to eq(:foo)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "stores the return value" do
|
||||||
|
expect(stub.value).to eq(42)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#===" do
|
||||||
|
subject { stub === call }
|
||||||
|
|
||||||
|
context "with a matching method name" do
|
||||||
|
let(call) { Spectator::MethodCall.capture(:foo, "foobar") }
|
||||||
|
|
||||||
|
it "returns true" do
|
||||||
|
is_expected.to be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a different method name" do
|
||||||
|
let(call) { Spectator::MethodCall.capture(:bar, "foobar") }
|
||||||
|
|
||||||
|
it "returns false" do
|
||||||
|
is_expected.to be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a constraint" do
|
||||||
|
let(constraint) { Spectator::Arguments.capture(/foo/) }
|
||||||
|
let(stub) { Spectator::ValueStub.new(:foo, 42, constraint) }
|
||||||
|
|
||||||
|
context "with a matching method name" do
|
||||||
|
let(call) { Spectator::MethodCall.capture(:foo, "foobar") }
|
||||||
|
|
||||||
|
it "returns true" do
|
||||||
|
is_expected.to be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a non-matching arguments" do
|
||||||
|
let(call) { Spectator::MethodCall.capture(:foo, "baz") }
|
||||||
|
|
||||||
|
it "returns false" do
|
||||||
|
is_expected.to be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a different method name" do
|
||||||
|
let(call) { Spectator::MethodCall.capture(:bar, "foobar") }
|
||||||
|
|
||||||
|
it "returns false" do
|
||||||
|
is_expected.to be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue