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