Sha256: 67be3aac400be0adf41cd443326b81932cf0357cf48234f7f03b7efedc66cca6

Contents?: true

Size: 1.57 KB

Versions: 74

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

module RSpec
  module Mocks
    describe TestDouble do
      before(:all) do
        Module.class_eval do
          private
          def use; end
        end
      end

      after(:all) do
        Module.class_eval do
          undef use
        end
      end

      it 'can be extended onto a module to make it a pure test double that can mock private methods' do
        double = Module.new
        double.stub(:use)
        expect { double.use }.to raise_error(/private method `use' called/)

        double = Module.new { TestDouble.extend_onto(self) }
        double.should_receive(:use).and_return(:ok)
        double.use.should be(:ok)
      end

      it 'sets the test double name when a name is passed' do
        double = Module.new { TestDouble.extend_onto(self, "MyDouble") }
        expect { double.foo }.to raise_error(/Mock "MyDouble" received/)
      end

      it 'stubs the methods passed in the stubs hash' do
        double = Module.new do
          TestDouble.extend_onto(self, "MyDouble", :a => 5, :b => 10)
        end

        double.a.should eq(5)
        double.b.should eq(10)
      end

      it 'indicates what type of test double it is in error messages' do
        double = Module.new do
          TestDouble.extend_onto(self, "A", :__declared_as => "ModuleMock")
        end
        expect { double.foo }.to raise_error(/ModuleMock "A"/)
      end

      it 'is declared as a mock by default' do
        double = Module.new { TestDouble.extend_onto(self) }
        expect { double.foo }.to raise_error(/Mock received/)
      end
    end
  end
end

Version data entries

74 entries across 69 versions & 9 rubygems

Version Path
classiccms-0.5.2 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
classiccms-0.5.1 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
classiccms-0.5.0 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
classiccms-0.4.2 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
rspec-mocks-2.11.1 spec/rspec/mocks/test_double_spec.rb
rspec-mocks-2.11.0 spec/rspec/mocks/test_double_spec.rb
classiccms-0.4.1 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
classiccms-0.4.0 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
classiccms-0.3.9 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
classiccms-0.3.8 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb
classiccms-0.3.7 vendor/bundle/gems/rspec-mocks-2.10.1/spec/rspec/mocks/test_double_spec.rb