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
|
require 'spec_helper'
module RSpec
module Mocks
describe "#once" do
before(:each) do
@double = double
end
it "passes when called once" do
@double.should_receive(:do_something).once
@double.do_something
verify @double
end
it "passes when called once with specified args" do
@double.should_receive(:do_something).once.with("a", "b", "c")
@double.do_something("a", "b", "c")
verify @double
end
it "passes when called once with unspecified args" do
@double.should_receive(:do_something).once
@double.do_something("a", "b", "c")
verify @double
end
it "fails when called with wrong args" do
@double.should_receive(:do_something).once.with("a", "b", "c")
expect {
@double.do_something("d", "e", "f")
}.to raise_error(RSpec::Mocks::MockExpectationError)
reset @double
end
it "fails fast when called twice" do
@double.should_receive(:do_something).once
@double.do_something
expect {
@double.do_something
}.to raise_error(RSpec::Mocks::MockExpectationError)
end
it "fails when not called" do
@double.should_receive(:do_something).once
expect {
verify @double
}.to raise_error(RSpec::Mocks::MockExpectationError)
end
end
end
end
|