Sha256: a3b7dd284332eb6d84a95633d3520cb8214c6978dda6648e07004af1132c1069

Contents?: true

Size: 1.44 KB

Versions: 22

Compression:

Stored size: 1.44 KB

Contents

require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")

describe "any_instance_of" do
  context "when passed a block" do
    it "applies to instances instantiated before the Double expection was created" do
      subject_class = Class.new
      subject = subject_class.new
      class_called = false
      any_instance_of(subject_class) do |o|
        stub(o).to_s {"Subject is stubbed"}
        stub.proxy(o).class {|klass| class_called = true; klass}
        stub(o).foobar {:baz}
      end

      subject.to_s.should == "Subject is stubbed"
      subject.class.should == subject_class
      class_called.should == true
      subject.foobar.should == :baz

      RR.reset

      subject.to_s.should_not == "Subject is stubbed"
      class_called = false
      subject.class.should == subject_class
      class_called.should == false
      subject.should_not respond_to(:baz)
    end
  end

  context "when passed a Hash" do
    it "stubs methods (key) with the value on instances instantiated before the Double expection was created" do
      subject_class = Class.new
      subject = subject_class.new
      subject.should_not respond_to(:baz)

      any_instance_of(subject_class, :to_s => "Subject is stubbed", :foobar => lambda {:baz})

      subject.to_s.should == "Subject is stubbed"
      subject.foobar.should == :baz

      RR.reset

      subject.to_s.should_not == "Subject is stubbed"
      subject.should_not respond_to(:baz)
    end
  end
end

Version data entries

22 entries across 18 versions & 5 rubygems

Version Path
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/api/any_instance_of/any_instance_of_spec.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/api/any_instance_of/any_instance_of_spec.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/api/any_instance_of/any_instance_of_spec.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/api/any_instance_of/any_instance_of_spec.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/api/any_instance_of/any_instance_of_spec.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/api/any_instance_of/any_instance_of_spec.rb
bitclust-core-0.5.1 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/api/any_instance_of/any_instance_of_spec.rb
mcmire-rr-1.0.5.rc1 spec/api/any_instance_of/any_instance_of_spec.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/rr-1.0.2/spec/api/any_instance_of/any_instance_of_spec.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/rr-1.0.2/spec/api/any_instance_of/any_instance_of_spec.rb
rr-1.0.4 spec/api/any_instance_of/any_instance_of_spec.rb
rr-1.0.3 spec/api/any_instance_of/any_instance_of_spec.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/rr-1.0.2/spec/api/any_instance_of/any_instance_of_spec.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/rr-1.0.2/spec/api/any_instance_of/any_instance_of_spec.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/rr-1.0.2/spec/api/any_instance_of/any_instance_of_spec.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/rr-1.0.2/spec/api/any_instance_of/any_instance_of_spec.rb
vim-jar-0.0.3 bundler/ruby/1.8/gems/rr-1.0.2/spec/api/any_instance_of/any_instance_of_spec.rb
vim-jar-0.0.2 bundler/ruby/1.8/gems/rr-1.0.2/spec/api/any_instance_of/any_instance_of_spec.rb
vim-jar-0.0.1 bundler/ruby/1.8/gems/rr-1.0.2/spec/api/any_instance_of/any_instance_of_spec.rb
rr-1.0.2 spec/api/any_instance_of/any_instance_of_spec.rb