Sha256: 2f2d0c799efda1682e350ba8eaca36b579fef444f7ff80c20c05ab848d1feafc

Contents?: true

Size: 1.39 KB

Versions: 14

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'

describe RSpecCandy::Helpers::DisposableCopy do

  describe Class do

    describe '.disposable_copy' do

      it 'should return a class' do
        Model.disposable_copy.should be_a(Class)
      end

      it 'should return a class with the same name as the original class' do
        Model.disposable_copy.name.should == 'Model'
      end

      it 'should return a class that instantiates objects that are also instances of the original class' do
        instance = Model.disposable_copy.new
        instance.should be_a(Model)
      end

      it 'should return a class that can be modified without changing the original class' do
        copy = Model.disposable_copy
        copy.class_eval do
          def foo
          end
        end
        copy.new.should respond_to(:foo)
        Model.new.should_not respond_to(:foo)
      end

      it 'should take a block with is evaluated in the context of the disposable class' do
        copy = Model.disposable_copy do
          def foo
          end
        end
        copy.new.should respond_to(:foo)
        Model.new.should_not respond_to(:foo)
      end

      it 'should evaluate the block after the copy has been renamed to the original class name' do
        spy = mock('spy')
        spy.should_receive(:observe_name).with('Model')
        Model.disposable_copy do
          spy.observe_name(name)
        end
      end

    end

  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rspec_candy-0.3.1 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.3.0 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.10 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.9 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.8 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.7 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.6 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.5 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.4 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.3 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.2 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.1 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.2.0 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb
rspec_candy-0.1.2 spec/shared/rspec_candy/helpers/disposable_copy_spec.rb