Sha256: 975b9616c8f6234f2b540c8a1c1b1e676da0021c599e4e9e032e6ee41dd71433

Contents?: true

Size: 1.89 KB

Versions: 16

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

describe Object, "#should" do
  before(:each) do
    @target = "target"
    @matcher = mock("matcher")
    @matcher.stub!(:matches?).and_return(true)
    @matcher.stub!(:failure_message_for_should)
  end
  
  it "accepts and interacts with a matcher" do
    @matcher.should_receive(:matches?).with(@target).and_return(true)    
    @target.should @matcher
  end
  
  it "asks for a failure_message_for_should when matches? returns false" do
    @matcher.should_receive(:matches?).with(@target).and_return(false)
    @matcher.should_receive(:failure_message_for_should).and_return("the failure message")
    lambda {
      @target.should @matcher
    }.should fail_with("the failure message")
  end

  context "on interpretters that have BasicObject", :if => defined?(BasicObject) do
    let(:proxy_class) do
      Class.new(BasicObject) do
        def initialize(target)
          @target = target
        end

        def proxied?
          true
        end

        def method_missing(name, *args)
          @target.send(name, *args)
        end
      end
    end

    it 'works properly on BasicObject-subclassed proxy objects' do
      proxy_class.new(Object.new).should be_proxied
    end
  end
end

describe Object, "#should_not" do
  before(:each) do
    @target = "target"
    @matcher = mock("matcher")
  end
  
  it "accepts and interacts with a matcher" do
    @matcher.should_receive(:matches?).with(@target).and_return(false)
    @matcher.stub!(:failure_message_for_should_not)
    
    @target.should_not @matcher
  end
  
  it "asks for a failure_message_for_should_not when matches? returns true" do
    @matcher.should_receive(:matches?).with(@target).and_return(true)
    @matcher.should_receive(:failure_message_for_should_not).and_return("the failure message for should not")
    lambda {
      @target.should_not @matcher
    }.should fail_with("the failure message for should not")
  end
end

Version data entries

16 entries across 16 versions & 6 rubygems

Version Path
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/expectations/extensions/kernel_spec.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/expectations/extensions/kernel_spec.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/spec/rspec/expectations/extensions/kernel_spec.rb
remq-0.0.4 vendor/bundle/gems/rspec-expectations-2.12.1/spec/rspec/expectations/extensions/kernel_spec.rb
remq-0.0.3 vendor/bundle/gems/rspec-expectations-2.12.1/spec/rspec/expectations/extensions/kernel_spec.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/spec/rspec/expectations/extensions/kernel_spec.rb
rspec-expectations-2.12.1 spec/rspec/expectations/extensions/kernel_spec.rb
rspec-expectations-2.12.0 spec/rspec/expectations/extensions/kernel_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/expectations/extensions/kernel_spec.rb
gem_repackager-0.1.0 support/gems/rspec-expectations-2.11.2/spec/rspec/expectations/extensions/kernel_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/spec/rspec/expectations/extensions/kernel_spec.rb
rspec-expectations-2.11.3 spec/rspec/expectations/extensions/kernel_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/spec/rspec/expectations/extensions/kernel_spec.rb
rspec-expectations-2.11.2 spec/rspec/expectations/extensions/kernel_spec.rb
rspec-expectations-2.11.1 spec/rspec/expectations/extensions/kernel_spec.rb
rspec-expectations-2.11.0 spec/rspec/expectations/extensions/kernel_spec.rb