Sha256: 20ddd46b9bd52b8e11a52c3c0a13f1d818137e1c87b249e3b738e32a722c0d97

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

shared_context 'stub + instance_of + strong' do
  include StubDefinitionCreatorHelpers

  context 'where subject is a class', method_type: :class do
    context 'where methods being doubled already exist', methods_exist: true do
      include_context 'tests for a double definition creator method that supports stubbing'

      it_behaves_like 'comparing the arity between the method and double definition'

      it "lets you stub methods which are called in #initialize" do
        klass = Class.new do
          def initialize; method_run_in_initialize; end
          def method_run_in_initialize; end
        end
        method_double_called = false
        double_creator = double_definition_creator_for(klass)
        double_creator.method_run_in_initialize { method_double_called = true }
        klass.new
        expect(method_double_called).to eq true
      end
    end

    context 'where methods being doubled do not already exist', methods_exist: false do
      it "doesn't work" do
        klass = Class.new
        double_creator = double_definition_creator_for(klass)
        expect { double_creator.some_method }.to \
          raise_error(RR::Errors::SubjectDoesNotImplementMethodError)
      end
    end
  end

  context 'where subject is an instance of a class', method_type: :instance do
    it "doesn't work" do
      double_creator = double_definition_creator_for(Object.new)
      expect { double_creator.some_method }.to raise_error(ArgumentError)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rr-3.1.1 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.1.0 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.0.9 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.0.8 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.0.7 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.0.6 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.0.5 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.0.4 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.0.3 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.0.2 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.0.1 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-3.0.0 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-1.2.1 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb
rr-1.2.0 spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb