Dalam rspec (1.2.9), apa cara yang benar untuk menentukan bahwa suatu objek akan menerima beberapa panggilan ke suatu metode dengan argumen yang berbeda setiap waktu?
Saya bertanya karena hasil yang membingungkan ini:
describe Object do
it "passes, as expected" do
foo = mock('foo')
foo.should_receive(:bar).once.ordered.with(1)
foo.should_receive(:bar).once.ordered.with(2)
foo.bar(1)
foo.bar(2)
end
it "fails, as expected" do
foo = mock('foo')
foo.should_receive(:bar).once.ordered.with(1) # => Mock "foo" expected :bar with (1) once, but received it twice
foo.should_receive(:bar).once.ordered.with(2)
foo.bar(1)
foo.bar(1)
foo.bar(2)
end
it "fails, as expected" do
foo = mock('foo')
foo.should_receive(:bar).once.ordered.with(1)
foo.should_receive(:bar).once.ordered.with(2)
foo.bar(2) # => Mock "foo" received :bar out of order
foo.bar(1)
end
it "fails, as expected, but with an unexpected message" do
foo = mock('foo')
foo.should_receive(:bar).once.ordered.with(1)
foo.should_receive(:bar).once.ordered.with(2)
foo.bar(1)
foo.bar(999) # => Mock "foo" received :bar with unexpected arguments
# => expected: (1)
# => got (999)
end
end
Saya mengharapkan pesan kegagalan terakhir "diharapkan: (2)", bukan "diharapkan (1)". Sudahkah saya menggunakan rspec dengan salah?