1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
shared_examples_for "stubbing methods with keyword arguments" do
it "can spy on stubbed methods" do
stub(subject).foo(any_args)
subject.foo(x: "test")
expect(subject).to have_received.foo(x: "test")
expect(subject).not_to have_received.foo(x: "baz")
end
it "can mock methods with keyword arguments" do
mock(subject).foo(x: 1) { :return }
expect(subject.foo(x: 1)).to eq(:return)
expect { Bogus.after_each_test }.not_to raise_error
end
it "can stub methods with keyword arguments" do
stub(subject).foo(x: "bar") { :return_value }
expect(subject.foo(x: "bar")).to eq(:return_value)
end
it "raises on error on unknown keyword" do
expect {
stub(subject).foo(x: "bar", baz: "baz")
}.to raise_error(ArgumentError)
end
it "does not overwrite the method signature" do
stub(subject).foo(x: 1)
expect {
subject.foo(bar: 1)
}.to raise_error(ArgumentError)
end
end
shared_examples_for "stubbing methods with double splat" do
it "can spy on stubbed methods" do
stub(subject).bar(any_args)
subject.bar(x: "test", z: "spec")
expect(subject).to have_received.bar(x: "test", z: "spec")
expect(subject).not_to have_received.bar(x: "test", y: "baz")
end
it "can mock methods with keyword arguments" do
mock(subject).bar(x: 1, z: 2) { :return }
expect(subject.bar(x: 1, z: 2)).to eq(:return)
expect { Bogus.after_each_test }.not_to raise_error
end
it "can stub methods with keyword arguments" do
stub(subject).bar(x: "bar", z: "bar") { :return_value }
expect(subject.bar(x: "bar", z: "bar")).to eq(:return_value)
end
end
|