Sha256: 7bf94863303249bb787933fcf3be6314600601a051b0ed413a6fe51ef60e644d

Contents?: true

Size: 1.98 KB

Versions: 29

Compression:

Stored size: 1.98 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)
        expect(double.use).to 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

      [[:should, :expect], [:expect], [:should]].each do |syntax|
        context "with syntax #{syntax.inspect}" do
          include_context "with syntax", syntax
          it 'stubs the methods passed in the stubs hash' do
            double = Module.new do
              TestDouble.extend_onto(self, "MyDouble", :a => 5, :b => 10)
            end

            expect(double.a).to eq(5)
            expect(double.b).to eq(10)
          end
        end
      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

      it 'warns of deprecation of :null_object => true' do
        RSpec.should_receive :deprecate
        double = Class.new { TestDouble.extend_onto self, 'name', :null_object => true }
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/test_double_spec.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/test_double_spec.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/test_double_spec.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/test_double_spec.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/test_double_spec.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/test_double_spec.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/test_double_spec.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/test_double_spec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-mocks-2.14.6/spec/rspec/mocks/test_double_spec.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-mocks-2.14.4/spec/rspec/mocks/test_double_spec.rb
rspec-mocks-2.14.6 spec/rspec/mocks/test_double_spec.rb
rspec-mocks-2.14.5 spec/rspec/mocks/test_double_spec.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-mocks-2.14.4/spec/rspec/mocks/test_double_spec.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-mocks-2.14.4/spec/rspec/mocks/test_double_spec.rb
dxruby_rp5-0.0.3 spec/vendor/rspec-mocks-2.14.4/spec/rspec/mocks/test_double_spec.rb
tuktuk-rails-0.0.10 vendor/bundle/ruby/2.0.0/gems/rspec-mocks-2.14.4/spec/rspec/mocks/test_double_spec.rb
tuktuk-rails-0.0.9 vendor/bundle/ruby/2.0.0/gems/rspec-mocks-2.14.4/spec/rspec/mocks/test_double_spec.rb
tuktuk-rails-0.0.8 vendor/bundle/ruby/2.0.0/gems/rspec-mocks-2.14.4/spec/rspec/mocks/test_double_spec.rb
tuktuk-rails-0.0.7 vendor/bundle/ruby/2.0.0/gems/rspec-mocks-2.14.4/spec/rspec/mocks/test_double_spec.rb
dxruby_rp5-0.0.2 spec/vendor/rspec-mocks-2.14.4/spec/rspec/mocks/test_double_spec.rb