Sha256: 89b014857fbd6ae465ff5c7790ef8dbd8a10d8f474bfe8732e7f5bdeafb6a71a

Contents?: true

Size: 1.8 KB

Versions: 33

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

module RSpec
  module Mocks
    describe "stub implementation" do
      describe "with no args" do
        it "execs the block when called" do
          obj = stub()
          obj.stub(:foo) { :bar }
          obj.foo.should == :bar
        end
      end

      describe "with one arg" do
        it "execs the block with that arg when called" do
          obj = stub()
          obj.stub(:foo) {|given| given}
          obj.foo(:bar).should == :bar
        end
      end

      describe "with variable args" do
        it "execs the block when called" do
          obj = stub()
          obj.stub(:foo) {|*given| given.first}
          obj.foo(:bar).should == :bar
        end        
      end
    end

  
    describe "unstub implementation" do      
      it "replaces the stubbed method with the original method" do
        obj = Object.new
        def obj.foo; :original; end
        obj.stub(:foo)
        obj.unstub(:foo)
        obj.foo.should == :original
      end
    
      it "removes all stubs with the supplied method name" do
        obj = Object.new
        def obj.foo; :original; end
        obj.stub(:foo).with(1)
        obj.stub(:foo).with(2)
        obj.unstub(:foo)
        obj.foo.should == :original
      end
    
      it "does not remove any expectations with the same method name" do
        obj = Object.new
        def obj.foo; :original; end
        obj.should_receive(:foo).with(3).and_return(:three)
        obj.stub(:foo).with(1)
        obj.stub(:foo).with(2)
        obj.unstub(:foo)
        obj.foo(3).should == :three
      end
    
      it "raises a MockExpectationError if the method has not been stubbed" do
        obj = Object.new
        lambda do
          obj.unstub(:foo)
        end.should raise_error(RSpec::Mocks::MockExpectationError)
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 4 rubygems

Version Path
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/rspec-mocks-2.5.0/spec/rspec/mocks/stub_implementation_spec.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/rspec-mocks-2.5.0/spec/rspec/mocks/stub_implementation_spec.rb
rspec-mocks-2.6.0 spec/rspec/mocks/stub_implementation_spec.rb
rspec-mocks-2.6.0.rc6 spec/rspec/mocks/stub_implementation_spec.rb
rspec-mocks-2.6.0.rc4 spec/rspec/mocks/stub_implementation_spec.rb
rspec-mocks-2.6.0.rc2 spec/rspec/mocks/stub_implementation_spec.rb
rspec-mocks-2.5.0 spec/rspec/mocks/stub_implementation_spec.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/rspec-mocks-2.1.0/spec/rspec/mocks/stub_implementation_spec.rb
rspec-mocks-2.4.0 spec/rspec/mocks/stub_implementation_spec.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/rspec-mocks-2.1.0/spec/rspec/mocks/stub_implementation_spec.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/rspec-mocks-2.1.0/spec/rspec/mocks/stub_implementation_spec.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/rspec-mocks-2.1.0/spec/rspec/mocks/stub_implementation_spec.rb
rspec-mocks-2.3.0 spec/rspec/mocks/stub_implementation_spec.rb
vim-jar-0.0.3 bundler/ruby/1.8/gems/rspec-mocks-2.1.0/spec/rspec/mocks/stub_implementation_spec.rb
vim-jar-0.0.2 bundler/ruby/1.8/gems/rspec-mocks-2.1.0/spec/rspec/mocks/stub_implementation_spec.rb
vim-jar-0.0.1 bundler/ruby/1.8/gems/rspec-mocks-2.1.0/spec/rspec/mocks/stub_implementation_spec.rb
rspec-mocks-2.2.0 spec/rspec/mocks/stub_implementation_spec.rb
rspec-mocks-2.1.0 spec/rspec/mocks/stub_implementation_spec.rb
rspec-mocks-2.0.1 spec/rspec/mocks/stub_implementation_spec.rb
gemrage-1.0.0 vendor/ruby/1.8/gems/rspec-mocks-2.0.0/spec/rspec/mocks/stub_implementation_spec.rb