Test ValueStub

This commit is contained in:
Michael Miller 2022-03-05 20:57:43 -07:00
parent ae14a47329
commit 7c8db07eda
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2

View 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