diff options
Diffstat (limited to 'spec/mspec/spec/mocks')
-rw-r--r-- | spec/mspec/spec/mocks/mock_spec.rb | 238 | ||||
-rw-r--r-- | spec/mspec/spec/mocks/proxy_spec.rb | 196 |
2 files changed, 217 insertions, 217 deletions
diff --git a/spec/mspec/spec/mocks/mock_spec.rb b/spec/mspec/spec/mocks/mock_spec.rb index 8cf04cf462..73f9bdfa14 100644 --- a/spec/mspec/spec/mocks/mock_spec.rb +++ b/spec/mspec/spec/mocks/mock_spec.rb @@ -7,78 +7,78 @@ require 'mspec/runner/mspec' require 'mspec/mocks/mock' require 'mspec/mocks/proxy' -describe Mock, ".mocks" do +RSpec.describe Mock, ".mocks" do it "returns a Hash" do - Mock.mocks.should be_kind_of(Hash) + expect(Mock.mocks).to be_kind_of(Hash) end end -describe Mock, ".stubs" do +RSpec.describe Mock, ".stubs" do it "returns a Hash" do - Mock.stubs.should be_kind_of(Hash) + expect(Mock.stubs).to be_kind_of(Hash) end end -describe Mock, ".replaced_name" do +RSpec.describe Mock, ".replaced_name" do it "returns the name for a method that is being replaced by a mock method" do m = double('a fake id') - Mock.replaced_name(m, :method_call).should == :"__mspec_#{m.object_id}_method_call__" + expect(Mock.replaced_name(m, :method_call)).to eq(:"__mspec_#{m.object_id}_method_call__") end end -describe Mock, ".replaced_key" do +RSpec.describe Mock, ".replaced_key" do it "returns a key used internally by Mock" do m = double('a fake id') - Mock.replaced_key(m, :method_call).should == [:"__mspec_#{m.object_id}_method_call__", :method_call] + expect(Mock.replaced_key(m, :method_call)).to eq([:"__mspec_#{m.object_id}_method_call__", :method_call]) end end -describe Mock, ".replaced?" do +RSpec.describe Mock, ".replaced?" do before :each do @mock = double('install_method') - MSpec.stub(:actions) - MSpec.stub(:current).and_return(double("spec state").as_null_object) + allow(MSpec).to receive(:actions) + allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object) end it "returns true if a method has been stubbed on an object" do Mock.install_method @mock, :method_call - Mock.replaced?(Mock.replaced_name(@mock, :method_call)).should be_true + expect(Mock.replaced?(Mock.replaced_name(@mock, :method_call))).to be_truthy end it "returns true if a method has been mocked on an object" do Mock.install_method @mock, :method_call, :stub - Mock.replaced?(Mock.replaced_name(@mock, :method_call)).should be_true + expect(Mock.replaced?(Mock.replaced_name(@mock, :method_call))).to be_truthy end it "returns false if a method has not been stubbed or mocked" do - Mock.replaced?(Mock.replaced_name(@mock, :method_call)).should be_false + expect(Mock.replaced?(Mock.replaced_name(@mock, :method_call))).to be_falsey end end -describe Mock, ".name_or_inspect" do +RSpec.describe Mock, ".name_or_inspect" do before :each do @mock = double("I have a #name") end it "returns the value of @name if set" do @mock.instance_variable_set(:@name, "Myself") - Mock.name_or_inspect(@mock).should == "Myself" + expect(Mock.name_or_inspect(@mock)).to eq("Myself") end end -describe Mock, ".install_method for mocks" do +RSpec.describe Mock, ".install_method for mocks" do before :each do @mock = double('install_method') - MSpec.stub(:actions) - MSpec.stub(:current).and_return(double("spec state").as_null_object) + allow(MSpec).to receive(:actions) + allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object) end after :each do - Mock.cleanup + Mock.reset end it "returns a MockProxy instance" do - Mock.install_method(@mock, :method_call).should be_an_instance_of(MockProxy) + expect(Mock.install_method(@mock, :method_call)).to be_an_instance_of(MockProxy) end it "does not override a previously mocked method with the same name" do @@ -86,7 +86,7 @@ describe Mock, ".install_method for mocks" do Mock.install_method(@mock, :method_call).with(:c).and_return(2) @mock.method_call(:a, :b) @mock.method_call(:c) - lambda { @mock.method_call(:d) }.should raise_error(SpecExpectationNotMetError) + expect { @mock.method_call(:d) }.to raise_error(SpecExpectationNotMetError) end # This illustrates RSpec's behavior. This spec fails in mock call count verification @@ -105,44 +105,44 @@ describe Mock, ".install_method for mocks" do # it "does not override a previously mocked method having the same arguments" do Mock.install_method(@mock, :method_call).with(:a).and_return(true) - @mock.method_call(:a).should == true + expect(@mock.method_call(:a)).to eq(true) Mock.install_method(@mock, :method_call).with(:a).and_return(false) - @mock.method_call(:a).should == true - lambda { Mock.verify_count }.should raise_error(SpecExpectationNotMetError) + expect(@mock.method_call(:a)).to eq(true) + expect { Mock.verify_count }.to raise_error(SpecExpectationNotMetError) end it "properly sends #respond_to? calls to the aliased respond_to? method when not matching mock expectations" do Mock.install_method(@mock, :respond_to?).with(:to_str).and_return('mock to_str') Mock.install_method(@mock, :respond_to?).with(:to_int).and_return('mock to_int') - @mock.respond_to?(:to_str).should == 'mock to_str' - @mock.respond_to?(:to_int).should == 'mock to_int' - @mock.respond_to?(:to_s).should == true - @mock.respond_to?(:not_really_a_real_method_seriously).should == false + expect(@mock.respond_to?(:to_str)).to eq('mock to_str') + expect(@mock.respond_to?(:to_int)).to eq('mock to_int') + expect(@mock.respond_to?(:to_s)).to eq(true) + expect(@mock.respond_to?(:not_really_a_real_method_seriously)).to eq(false) end it "adds to the expectation tally" do state = double("run state").as_null_object - state.stub(:state).and_return(double("spec state")) - MSpec.should_receive(:current).and_return(state) - MSpec.should_receive(:actions).with(:expectation, state.state) + allow(state).to receive(:state).and_return(double("spec state")) + expect(MSpec).to receive(:current).and_return(state) + expect(MSpec).to receive(:actions).with(:expectation, state.state) Mock.install_method(@mock, :method_call).and_return(1) - @mock.method_call.should == 1 + expect(@mock.method_call).to eq(1) end it "registers that an expectation has been encountered" do state = double("run state").as_null_object - state.stub(:state).and_return(double("spec state")) - MSpec.should_receive(:expectation) + allow(state).to receive(:state).and_return(double("spec state")) + expect(MSpec).to receive(:expectation) Mock.install_method(@mock, :method_call).and_return(1) - @mock.method_call.should == 1 + expect(@mock.method_call).to eq(1) end end -describe Mock, ".install_method for stubs" do +RSpec.describe Mock, ".install_method for stubs" do before :each do @mock = double('install_method') - MSpec.stub(:actions) - MSpec.stub(:current).and_return(double("spec state").as_null_object) + allow(MSpec).to receive(:actions) + allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object) end after :each do @@ -150,7 +150,7 @@ describe Mock, ".install_method for stubs" do end it "returns a MockProxy instance" do - Mock.install_method(@mock, :method_call, :stub).should be_an_instance_of(MockProxy) + expect(Mock.install_method(@mock, :method_call, :stub)).to be_an_instance_of(MockProxy) end # This illustrates RSpec's behavior. This spec passes on RSpec and we mimic it @@ -166,26 +166,26 @@ describe Mock, ".install_method for stubs" do # end it "inserts new stubs before old stubs" do Mock.install_method(@mock, :method_call, :stub).with(:a).and_return(true) - @mock.method_call(:a).should == true + expect(@mock.method_call(:a)).to eq(true) Mock.install_method(@mock, :method_call, :stub).with(:a).and_return(false) - @mock.method_call(:a).should == false + expect(@mock.method_call(:a)).to eq(false) Mock.verify_count end it "does not add to the expectation tally" do state = double("run state").as_null_object - state.stub(:state).and_return(double("spec state")) - MSpec.should_not_receive(:actions) + allow(state).to receive(:state).and_return(double("spec state")) + expect(MSpec).not_to receive(:actions) Mock.install_method(@mock, :method_call, :stub).and_return(1) - @mock.method_call.should == 1 + expect(@mock.method_call).to eq(1) end end -describe Mock, ".install_method" do +RSpec.describe Mock, ".install_method" do before :each do @mock = double('install_method') - MSpec.stub(:actions) - MSpec.stub(:current).and_return(double("spec state").as_null_object) + allow(MSpec).to receive(:actions) + allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object) end after :each do @@ -193,24 +193,24 @@ describe Mock, ".install_method" do end it "does not alias a mocked or stubbed method when installing a new mock or stub" do - @mock.should_not respond_to(:method_call) + expect(@mock).not_to respond_to(:method_call) Mock.install_method @mock, :method_call - @mock.should respond_to(:method_call) - @mock.should_not respond_to(Mock.replaced_name(@mock, :method_call)) + expect(@mock).to respond_to(:method_call) + expect(@mock).not_to respond_to(Mock.replaced_name(@mock, :method_call)) Mock.install_method @mock, :method_call, :stub - @mock.should respond_to(:method_call) - @mock.should_not respond_to(Mock.replaced_name(@mock, :method_call)) + expect(@mock).to respond_to(:method_call) + expect(@mock).not_to respond_to(Mock.replaced_name(@mock, :method_call)) end end class MockAndRaiseError < Exception; end -describe Mock, ".verify_call" do +RSpec.describe Mock, ".verify_call" do before :each do - MSpec.stub(:actions) - MSpec.stub(:current).and_return(double("spec state").as_null_object) + allow(MSpec).to receive(:actions) + allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object) @mock = double('verify_call') @proxy = Mock.install_method @mock, :method_call @@ -228,23 +228,23 @@ describe Mock, ".verify_call" do it "raises an SpecExpectationNotMetError when the mock method does not receive the expected arguments" do @proxy.with(4, 2) - lambda { + expect { Mock.verify_call @mock, :method_call, 42 - }.should raise_error(SpecExpectationNotMetError) + }.to raise_error(SpecExpectationNotMetError) end it "raises an SpecExpectationNotMetError when the mock method is called with arguments but expects none" do - lambda { + expect { @proxy.with(:no_args) Mock.verify_call @mock, :method_call, "hello" - }.should raise_error(SpecExpectationNotMetError) + }.to raise_error(SpecExpectationNotMetError) end it "raises an SpecExpectationNotMetError when the mock method is called with no arguments but expects some" do @proxy.with("hello", "beautiful", "world") - lambda { + expect { Mock.verify_call @mock, :method_call - }.should raise_error(SpecExpectationNotMetError) + }.to raise_error(SpecExpectationNotMetError) end it "does not raise an exception when the mock method is called with arguments and is expecting :any_args" do @@ -257,14 +257,14 @@ describe Mock, ".verify_call" do Mock.verify_call @mock, :method_call do ScratchPad.record true end - ScratchPad.recorded.should == true + expect(ScratchPad.recorded).to eq(true) end it "does not yield a passed block when it is not expected to" do Mock.verify_call @mock, :method_call do ScratchPad.record true end - ScratchPad.recorded.should == nil + expect(ScratchPad.recorded).to eq(nil) end it "can yield subsequently" do @@ -274,28 +274,28 @@ describe Mock, ".verify_call" do Mock.verify_call @mock, :method_call do |arg| ScratchPad << arg end - ScratchPad.recorded.should == [1, 2, 3] + expect(ScratchPad.recorded).to eq([1, 2, 3]) end it "can yield and return an expected value" do @proxy.and_yield(1).and_return(3) - Mock.verify_call(@mock, :method_call) { |arg| ScratchPad.record arg }.should == 3 - ScratchPad.recorded.should == 1 + expect(Mock.verify_call(@mock, :method_call) { |arg| ScratchPad.record arg }).to eq(3) + expect(ScratchPad.recorded).to eq(1) end it "raises an exception when it is expected to yield but no block is given" do @proxy.and_yield(1, 2, 3) - lambda { + expect { Mock.verify_call(@mock, :method_call) - }.should raise_error(SpecExpectationNotMetError) + }.to raise_error(SpecExpectationNotMetError) end it "raises an exception when it is expected to yield more arguments than the block can take" do @proxy.and_yield(1, 2, 3) - lambda { + expect { Mock.verify_call(@mock, :method_call) {|a, b|} - }.should raise_error(SpecExpectationNotMetError) + }.to raise_error(SpecExpectationNotMetError) end it "does not raise an exception when it is expected to yield to a block that can take any number of arguments" do @@ -307,16 +307,16 @@ describe Mock, ".verify_call" do it "raises an exception when expected to" do @proxy.and_raise(MockAndRaiseError) - lambda { + expect { Mock.verify_call @mock, :method_call - }.should raise_error(MockAndRaiseError) + }.to raise_error(MockAndRaiseError) end end -describe Mock, ".verify_call mixing mocks and stubs" do +RSpec.describe Mock, ".verify_call mixing mocks and stubs" do before :each do - MSpec.stub(:actions) - MSpec.stub(:current).and_return(double("spec state").as_null_object) + allow(MSpec).to receive(:actions) + allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object) @mock = double('verify_call') end @@ -330,17 +330,17 @@ describe Mock, ".verify_call mixing mocks and stubs" do Mock.install_method @mock, :method_call, :stub Mock.install_method(@mock, :method_call, :mock).with("arg") - -> { + expect { @mock.method_call - }.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \(\)/) + }.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \(\)/) - -> { + expect { @mock.method_call("a", "b") - }.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("a", "b"\)/) + }.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("a", "b"\)/) - -> { + expect { @mock.method_call("foo") - }.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("foo"\)/) + }.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("foo"\)/) @mock.method_call("arg") end @@ -349,26 +349,26 @@ describe Mock, ".verify_call mixing mocks and stubs" do Mock.install_method(@mock, :method_call, :mock).with("arg") Mock.install_method @mock, :method_call, :stub - -> { + expect { @mock.method_call - }.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \(\)/) + }.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \(\)/) - -> { + expect { @mock.method_call("a", "b") - }.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("a", "b"\)/) + }.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("a", "b"\)/) - -> { + expect { @mock.method_call("foo") - }.should raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("foo"\)/) + }.to raise_error(SpecExpectationNotMetError, /called with unexpected arguments \("foo"\)/) @mock.method_call("arg") end end -describe Mock, ".verify_count" do +RSpec.describe Mock, ".verify_count" do before :each do - MSpec.stub(:actions) - MSpec.stub(:current).and_return(double("spec state").as_null_object) + allow(MSpec).to receive(:actions) + allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object) @mock = double('verify_count') @proxy = Mock.install_method @mock, :method_call @@ -388,7 +388,7 @@ describe Mock, ".verify_count" do it "raises an SpecExpectationNotMetError when the mock receives less than at least the expected number of calls" do @proxy.at_least(2) @mock.method_call - lambda { Mock.verify_count }.should raise_error(SpecExpectationNotMetError) + expect { Mock.verify_count }.to raise_error(SpecExpectationNotMetError) end it "does not raise an exception when the mock receives at most the expected number of calls" do @@ -403,7 +403,7 @@ describe Mock, ".verify_count" do @mock.method_call @mock.method_call @mock.method_call - lambda { Mock.verify_count }.should raise_error(SpecExpectationNotMetError) + expect { Mock.verify_count }.to raise_error(SpecExpectationNotMetError) end it "does not raise an exception when the mock receives exactly the expected number of calls" do @@ -416,7 +416,7 @@ describe Mock, ".verify_count" do it "raises an SpecExpectationNotMetError when the mock receives less than exactly the expected number of calls" do @proxy.exactly(2) @mock.method_call - lambda { Mock.verify_count }.should raise_error(SpecExpectationNotMetError) + expect { Mock.verify_count }.to raise_error(SpecExpectationNotMetError) end it "raises an SpecExpectationNotMetError when the mock receives more than exactly the expected number of calls" do @@ -424,14 +424,14 @@ describe Mock, ".verify_count" do @mock.method_call @mock.method_call @mock.method_call - lambda { Mock.verify_count }.should raise_error(SpecExpectationNotMetError) + expect { Mock.verify_count }.to raise_error(SpecExpectationNotMetError) end end -describe Mock, ".verify_count mixing mocks and stubs" do +RSpec.describe Mock, ".verify_count mixing mocks and stubs" do before :each do - MSpec.stub(:actions) - MSpec.stub(:current).and_return(double("spec state").as_null_object) + allow(MSpec).to receive(:actions) + allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object) @mock = double('verify_count') end @@ -449,9 +449,9 @@ describe Mock, ".verify_count mixing mocks and stubs" do Mock.install_method @mock, :method_call, :stub Mock.install_method @mock, :method_call, :mock - -> { + expect { Mock.verify_count - }.should raise_error(SpecExpectationNotMetError, /received it 0 times/) + }.to raise_error(SpecExpectationNotMetError, /received it 0 times/) @mock.method_call Mock.verify_count @@ -461,19 +461,19 @@ describe Mock, ".verify_count mixing mocks and stubs" do Mock.install_method @mock, :method_call, :mock Mock.install_method @mock, :method_call, :stub - -> { + expect { Mock.verify_count - }.should raise_error(SpecExpectationNotMetError, /received it 0 times/) + }.to raise_error(SpecExpectationNotMetError, /received it 0 times/) @mock.method_call Mock.verify_count end end -describe Mock, ".cleanup" do +RSpec.describe Mock, ".cleanup" do before :each do - MSpec.stub(:actions) - MSpec.stub(:current).and_return(double("spec state").as_null_object) + allow(MSpec).to receive(:actions) + allow(MSpec).to receive(:current).and_return(double("spec state").as_null_object) @mock = double('cleanup') @proxy = Mock.install_method @mock, :method_call @@ -484,47 +484,47 @@ describe Mock, ".cleanup" do end it "removes the mock method call if it did not override an existing method" do - @mock.should respond_to(:method_call) + expect(@mock).to respond_to(:method_call) Mock.cleanup - @mock.should_not respond_to(:method_call) + expect(@mock).not_to respond_to(:method_call) end it "removes the replaced method if the mock method overrides an existing method" do def @mock.already_here() :hey end - @mock.should respond_to(:already_here) + expect(@mock).to respond_to(:already_here) replaced_name = Mock.replaced_name(@mock, :already_here) Mock.install_method @mock, :already_here - @mock.should respond_to(replaced_name) + expect(@mock).to respond_to(replaced_name) Mock.cleanup - @mock.should_not respond_to(replaced_name) - @mock.should respond_to(:already_here) - @mock.already_here.should == :hey + expect(@mock).not_to respond_to(replaced_name) + expect(@mock).to respond_to(:already_here) + expect(@mock.already_here).to eq(:hey) end it "removes all mock expectations" do - Mock.mocks.should == { Mock.replaced_key(@mock, :method_call) => [@proxy] } + expect(Mock.mocks).to eq({ Mock.replaced_key(@mock, :method_call) => [@proxy] }) Mock.cleanup - Mock.mocks.should == {} + expect(Mock.mocks).to eq({}) end it "removes all stubs" do Mock.cleanup # remove @proxy @stub = Mock.install_method @mock, :method_call, :stub - Mock.stubs.should == { Mock.replaced_key(@mock, :method_call) => [@stub] } + expect(Mock.stubs).to eq({ Mock.replaced_key(@mock, :method_call) => [@stub] }) Mock.cleanup - Mock.stubs.should == {} + expect(Mock.stubs).to eq({}) end it "removes the replaced name for mocks" do replaced_key = Mock.replaced_key(@mock, :method_call) - Mock.should_receive(:clear_replaced).with(replaced_key) + expect(Mock).to receive(:clear_replaced).with(replaced_key) replaced_name = Mock.replaced_name(@mock, :method_call) - Mock.replaced?(replaced_name).should be_true + expect(Mock.replaced?(replaced_name)).to be_truthy Mock.cleanup - Mock.replaced?(replaced_name).should be_false + expect(Mock.replaced?(replaced_name)).to be_falsey end end diff --git a/spec/mspec/spec/mocks/proxy_spec.rb b/spec/mspec/spec/mocks/proxy_spec.rb index d9e754b972..b994634694 100644 --- a/spec/mspec/spec/mocks/proxy_spec.rb +++ b/spec/mspec/spec/mocks/proxy_spec.rb @@ -1,276 +1,276 @@ require 'spec_helper' require 'mspec/mocks/proxy' -describe MockObject, ".new" do +RSpec.describe MockObject, ".new" do it "creates a new mock object" do m = MockObject.new('not a null object') - lambda { m.not_a_method }.should raise_error(NoMethodError) + expect { m.not_a_method }.to raise_error(NoMethodError) end it "creates a new mock object that follows the NullObject pattern" do m = MockObject.new('null object', :null_object => true) - m.not_really_a_method.should equal(m) + expect(m.not_really_a_method).to equal(m) end end -describe MockProxy, ".new" do +RSpec.describe MockProxy, ".new" do it "creates a mock proxy by default" do - MockProxy.new.mock?.should be_true + expect(MockProxy.new.mock?).to be_truthy end it "creates a stub proxy by request" do - MockProxy.new(:stub).stub?.should be_true + expect(MockProxy.new(:stub).stub?).to be_truthy end it "sets the call expectation to 1 call for a mock" do - MockProxy.new.count.should == [:exactly, 1] + expect(MockProxy.new.count).to eq([:exactly, 1]) end it "sets the call expectation to any number of times for a stub" do - MockProxy.new(:stub).count.should == [:any_number_of_times, 0] + expect(MockProxy.new(:stub).count).to eq([:any_number_of_times, 0]) end end -describe MockProxy, "#count" do +RSpec.describe MockProxy, "#count" do before :each do @proxy = MockProxy.new end it "returns the expected number of calls the mock should receive" do - @proxy.count.should == [:exactly, 1] - @proxy.at_least(3).count.should == [:at_least, 3] + expect(@proxy.count).to eq([:exactly, 1]) + expect(@proxy.at_least(3).count).to eq([:at_least, 3]) end end -describe MockProxy, "#arguments" do +RSpec.describe MockProxy, "#arguments" do before :each do @proxy = MockProxy.new end it "returns the expected arguments" do - @proxy.arguments.should == :any_args + expect(@proxy.arguments).to eq(:any_args) end end -describe MockProxy, "#with" do +RSpec.describe MockProxy, "#with" do before :each do @proxy = MockProxy.new end it "returns self" do - @proxy.with(:a).should be_equal(@proxy) + expect(@proxy.with(:a)).to be_equal(@proxy) end it "raises an ArgumentError if no arguments are given" do - lambda { @proxy.with }.should raise_error(ArgumentError) + expect { @proxy.with }.to raise_error(ArgumentError) end it "accepts any number of arguments" do - @proxy.with(1, 2, 3).should be_an_instance_of(MockProxy) - @proxy.arguments.should == [1,2,3] + expect(@proxy.with(1, 2, 3)).to be_an_instance_of(MockProxy) + expect(@proxy.arguments).to eq([1,2,3]) end end -describe MockProxy, "#once" do +RSpec.describe MockProxy, "#once" do before :each do @proxy = MockProxy.new end it "returns self" do - @proxy.once.should be_equal(@proxy) + expect(@proxy.once).to be_equal(@proxy) end it "sets the expected calls to 1" do @proxy.once - @proxy.count.should == [:exactly, 1] + expect(@proxy.count).to eq([:exactly, 1]) end it "accepts no arguments" do - lambda { @proxy.once(:a) }.should raise_error + expect { @proxy.once(:a) }.to raise_error end end -describe MockProxy, "#twice" do +RSpec.describe MockProxy, "#twice" do before :each do @proxy = MockProxy.new end it "returns self" do - @proxy.twice.should be_equal(@proxy) + expect(@proxy.twice).to be_equal(@proxy) end it "sets the expected calls to 2" do @proxy.twice - @proxy.count.should == [:exactly, 2] + expect(@proxy.count).to eq([:exactly, 2]) end it "accepts no arguments" do - lambda { @proxy.twice(:b) }.should raise_error + expect { @proxy.twice(:b) }.to raise_error end end -describe MockProxy, "#exactly" do +RSpec.describe MockProxy, "#exactly" do before :each do @proxy = MockProxy.new end it "returns self" do - @proxy.exactly(2).should be_equal(@proxy) + expect(@proxy.exactly(2)).to be_equal(@proxy) end it "sets the expected calls to exactly n" do @proxy.exactly(5) - @proxy.count.should == [:exactly, 5] + expect(@proxy.count).to eq([:exactly, 5]) end it "does not accept an argument that Integer() cannot convert" do - lambda { @proxy.exactly('x') }.should raise_error + expect { @proxy.exactly('x') }.to raise_error end end -describe MockProxy, "#at_least" do +RSpec.describe MockProxy, "#at_least" do before :each do @proxy = MockProxy.new end it "returns self" do - @proxy.at_least(3).should be_equal(@proxy) + expect(@proxy.at_least(3)).to be_equal(@proxy) end it "sets the expected calls to at least n" do @proxy.at_least(3) - @proxy.count.should == [:at_least, 3] + expect(@proxy.count).to eq([:at_least, 3]) end it "accepts :once :twice" do @proxy.at_least(:once) - @proxy.count.should == [:at_least, 1] + expect(@proxy.count).to eq([:at_least, 1]) @proxy.at_least(:twice) - @proxy.count.should == [:at_least, 2] + expect(@proxy.count).to eq([:at_least, 2]) end it "does not accept an argument that Integer() cannot convert" do - lambda { @proxy.at_least('x') }.should raise_error + expect { @proxy.at_least('x') }.to raise_error end end -describe MockProxy, "#at_most" do +RSpec.describe MockProxy, "#at_most" do before :each do @proxy = MockProxy.new end it "returns self" do - @proxy.at_most(2).should be_equal(@proxy) + expect(@proxy.at_most(2)).to be_equal(@proxy) end it "sets the expected calls to at most n" do @proxy.at_most(2) - @proxy.count.should == [:at_most, 2] + expect(@proxy.count).to eq([:at_most, 2]) end it "accepts :once, :twice" do @proxy.at_most(:once) - @proxy.count.should == [:at_most, 1] + expect(@proxy.count).to eq([:at_most, 1]) @proxy.at_most(:twice) - @proxy.count.should == [:at_most, 2] + expect(@proxy.count).to eq([:at_most, 2]) end it "does not accept an argument that Integer() cannot convert" do - lambda { @proxy.at_most('x') }.should raise_error + expect { @proxy.at_most('x') }.to raise_error end end -describe MockProxy, "#any_number_of_times" do +RSpec.describe MockProxy, "#any_number_of_times" do before :each do @proxy = MockProxy.new end it "returns self" do - @proxy.any_number_of_times.should be_equal(@proxy) + expect(@proxy.any_number_of_times).to be_equal(@proxy) end it "sets the expected calls to any number of times" do @proxy.any_number_of_times - @proxy.count.should == [:any_number_of_times, 0] + expect(@proxy.count).to eq([:any_number_of_times, 0]) end it "does not accept an argument" do - lambda { @proxy.any_number_of_times(2) }.should raise_error + expect { @proxy.any_number_of_times(2) }.to raise_error end end -describe MockProxy, "#and_return" do +RSpec.describe MockProxy, "#and_return" do before :each do @proxy = MockProxy.new end it "returns self" do - @proxy.and_return(false).should equal(@proxy) + expect(@proxy.and_return(false)).to equal(@proxy) end it "sets the expected return value" do @proxy.and_return(false) - @proxy.returning.should == false + expect(@proxy.returning).to eq(false) end it "accepts any number of return values" do @proxy.and_return(1, 2, 3) - @proxy.returning.should == 1 - @proxy.returning.should == 2 - @proxy.returning.should == 3 + expect(@proxy.returning).to eq(1) + expect(@proxy.returning).to eq(2) + expect(@proxy.returning).to eq(3) end it "implicitly sets the expected number of calls" do @proxy.and_return(1, 2, 3) - @proxy.count.should == [:exactly, 3] + expect(@proxy.count).to eq([:exactly, 3]) end it "only sets the expected number of calls if it is higher than what is already set" do @proxy.at_least(5).times.and_return(1, 2, 3) - @proxy.count.should == [:at_least, 5] + expect(@proxy.count).to eq([:at_least, 5]) @proxy.at_least(2).times.and_return(1, 2, 3) - @proxy.count.should == [:at_least, 3] + expect(@proxy.count).to eq([:at_least, 3]) end end -describe MockProxy, "#returning" do +RSpec.describe MockProxy, "#returning" do before :each do @proxy = MockProxy.new end it "returns nil by default" do - @proxy.returning.should be_nil + expect(@proxy.returning).to be_nil end it "returns the value set by #and_return" do @proxy.and_return(2) - @proxy.returning.should == 2 - @proxy.returning.should == 2 + expect(@proxy.returning).to eq(2) + expect(@proxy.returning).to eq(2) end it "returns a sequence of values set by #and_return" do @proxy.and_return(1,2,3,4) - @proxy.returning.should == 1 - @proxy.returning.should == 2 - @proxy.returning.should == 3 - @proxy.returning.should == 4 - @proxy.returning.should == 4 - @proxy.returning.should == 4 + expect(@proxy.returning).to eq(1) + expect(@proxy.returning).to eq(2) + expect(@proxy.returning).to eq(3) + expect(@proxy.returning).to eq(4) + expect(@proxy.returning).to eq(4) + expect(@proxy.returning).to eq(4) end end -describe MockProxy, "#calls" do +RSpec.describe MockProxy, "#calls" do before :each do @proxy = MockProxy.new end it "returns the number of times the proxy is called" do - @proxy.calls.should == 0 + expect(@proxy.calls).to eq(0) end end -describe MockProxy, "#called" do +RSpec.describe MockProxy, "#called" do before :each do @proxy = MockProxy.new end @@ -278,128 +278,128 @@ describe MockProxy, "#called" do it "increments the number of times the proxy is called" do @proxy.called @proxy.called - @proxy.calls.should == 2 + expect(@proxy.calls).to eq(2) end end -describe MockProxy, "#times" do +RSpec.describe MockProxy, "#times" do before :each do @proxy = MockProxy.new end it "is a no-op" do - @proxy.times.should == @proxy + expect(@proxy.times).to eq(@proxy) end end -describe MockProxy, "#stub?" do +RSpec.describe MockProxy, "#stub?" do it "returns true if the proxy is created as a stub" do - MockProxy.new(:stub).stub?.should be_true + expect(MockProxy.new(:stub).stub?).to be_truthy end it "returns false if the proxy is created as a mock" do - MockProxy.new(:mock).stub?.should be_false + expect(MockProxy.new(:mock).stub?).to be_falsey end end -describe MockProxy, "#mock?" do +RSpec.describe MockProxy, "#mock?" do it "returns true if the proxy is created as a mock" do - MockProxy.new(:mock).mock?.should be_true + expect(MockProxy.new(:mock).mock?).to be_truthy end it "returns false if the proxy is created as a stub" do - MockProxy.new(:stub).mock?.should be_false + expect(MockProxy.new(:stub).mock?).to be_falsey end end -describe MockProxy, "#and_yield" do +RSpec.describe MockProxy, "#and_yield" do before :each do @proxy = MockProxy.new end it "returns self" do - @proxy.and_yield(false).should equal(@proxy) + expect(@proxy.and_yield(false)).to equal(@proxy) end it "sets the expected values to yield" do - @proxy.and_yield(1).yielding.should == [[1]] + expect(@proxy.and_yield(1).yielding).to eq([[1]]) end it "accepts multiple values to yield" do - @proxy.and_yield(1, 2, 3).yielding.should == [[1, 2, 3]] + expect(@proxy.and_yield(1, 2, 3).yielding).to eq([[1, 2, 3]]) end end -describe MockProxy, "#raising" do +RSpec.describe MockProxy, "#raising" do before :each do @proxy = MockProxy.new end it "returns nil by default" do - @proxy.raising.should be_nil + expect(@proxy.raising).to be_nil end it "returns the exception object passed to #and_raise" do exc = double("exception") @proxy.and_raise(exc) - @proxy.raising.should equal(exc) + expect(@proxy.raising).to equal(exc) end it "returns an instance of RuntimeError when a String is passed to #and_raise" do @proxy.and_raise("an error") exc = @proxy.raising - exc.should be_an_instance_of(RuntimeError) - exc.message.should == "an error" + expect(exc).to be_an_instance_of(RuntimeError) + expect(exc.message).to eq("an error") end end -describe MockProxy, "#yielding" do +RSpec.describe MockProxy, "#yielding" do before :each do @proxy = MockProxy.new end it "returns an empty array by default" do - @proxy.yielding.should == [] + expect(@proxy.yielding).to eq([]) end it "returns an array of arrays of values the proxy should yield" do @proxy.and_yield(3) - @proxy.yielding.should == [[3]] + expect(@proxy.yielding).to eq([[3]]) end it "returns an accumulation of arrays of values the proxy should yield" do @proxy.and_yield(1).and_yield(2, 3) - @proxy.yielding.should == [[1], [2, 3]] + expect(@proxy.yielding).to eq([[1], [2, 3]]) end end -describe MockProxy, "#yielding?" do +RSpec.describe MockProxy, "#yielding?" do before :each do @proxy = MockProxy.new end it "returns false if the proxy is not yielding" do - @proxy.yielding?.should be_false + expect(@proxy.yielding?).to be_falsey end it "returns true if the proxy is yielding" do @proxy.and_yield(1) - @proxy.yielding?.should be_true + expect(@proxy.yielding?).to be_truthy end end -describe MockIntObject, "#to_int" do +RSpec.describe MockIntObject, "#to_int" do before :each do @int = MockIntObject.new(10) end it "returns the number if to_int is called" do - @int.to_int.should == 10 - @int.count.should == [:at_least, 1] + expect(@int.to_int).to eq(10) + expect(@int.count).to eq([:at_least, 1]) end it "tries to convert the target to int if to_int is called" do - MockIntObject.new(@int).to_int.should == 10 - @int.count.should == [:at_least, 1] + expect(MockIntObject.new(@int).to_int).to eq(10) + expect(@int.count).to eq([:at_least, 1]) end end |