Sha256: b97a2109f1f811fd85c791072d5ec2040696f2adbb0e327c8a04548804187a85

Contents?: true

Size: 1.26 KB

Versions: 10

Compression:

Stored size: 1.26 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'
require 'mspec/expectations/expectations'
require 'mspec/matchers/respond_to'

describe RespondToMatcher do
  it "matches when actual does respond_to? expected" do
    RespondToMatcher.new(:to_s).matches?(Object.new).should == true
    RespondToMatcher.new(:inject).matches?([]).should == true
    RespondToMatcher.new(:[]).matches?(1).should == true
    RespondToMatcher.new(:[]=).matches?("string").should == true
  end

  it "does not match when actual does not respond_to? expected" do
    RespondToMatcher.new(:to_i).matches?(Object.new).should == false
    RespondToMatcher.new(:inject).matches?(1).should == false
    RespondToMatcher.new(:non_existent_method).matches?([]).should == false
    RespondToMatcher.new(:[]=).matches?(1).should == false
  end

  it "provides a useful failure message" do
    matcher = RespondToMatcher.new(:non_existent_method)
    matcher.matches?('string')
    matcher.failure_message.should == ["Expected \"string\" (String)", "to respond to non_existent_method"]
  end

  it "provides a useful negative failure message" do
    matcher = RespondToMatcher.new(:to_i)
    matcher.matches?(4.2)
    matcher.negative_failure_message.should == ["Expected 4.2 (Float)", "not to respond to to_i"]
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mspec-1.5.10 spec/matchers/respond_to_spec.rb
mspec-1.5.2 spec/matchers/respond_to_spec.rb
mspec-1.5.1 spec/matchers/respond_to_spec.rb
mspec-1.5.3 spec/matchers/respond_to_spec.rb
mspec-1.5.4 spec/matchers/respond_to_spec.rb
mspec-1.5.9 spec/matchers/respond_to_spec.rb
mspec-1.5.5 spec/matchers/respond_to_spec.rb
mspec-1.5.7 spec/matchers/respond_to_spec.rb
mspec-1.5.6 spec/matchers/respond_to_spec.rb
mspec-1.5.8 spec/matchers/respond_to_spec.rb