Sha256: c8d627caaa6d54ddc2b6e773d5d45d737127ee12a96eada01940d2e1803bd9ef
Contents?: true
Size: 1.91 KB
Versions: 9
Compression:
Stored size: 1.91 KB
Contents
module RSpec module Mocks RSpec.describe "#twice" do before(:each) do @double = double("test double") end it "passes when called twice" do expect(@double).to receive(:do_something).twice @double.do_something @double.do_something verify @double end it "passes when called twice with specified args" do expect(@double).to receive(:do_something).twice.with("1", 1) @double.do_something("1", 1) @double.do_something("1", 1) verify @double end it "passes when called twice with unspecified args" do expect(@double).to receive(:do_something).twice @double.do_something("1") @double.do_something(1) verify @double end it "fails fast when call count is higher than expected" do expect(@double).to receive(:do_something).twice @double.do_something @double.do_something expect { @double.do_something }.to raise_error(RSpec::Mocks::MockExpectationError) end it "fails when call count is lower than expected" do expect(@double).to receive(:do_something).twice @double.do_something expect { verify @double }.to raise_error(RSpec::Mocks::MockExpectationError) end it "fails when called with wrong args on the first call" do expect(@double).to receive(:do_something).twice.with("1", 1) expect { @double.do_something(1, "1") }.to raise_error(RSpec::Mocks::MockExpectationError) reset @double end it "fails when called with wrong args on the second call" do expect(@double).to receive(:do_something).twice.with("1", 1) @double.do_something("1", 1) expect { @double.do_something(1, "1") }.to raise_error(RSpec::Mocks::MockExpectationError) reset @double end end end end
Version data entries
9 entries across 9 versions & 2 rubygems