Sha256: 5740c2284e32bf9e612e52259cdbc641abe829ed15f9eeb13e8ea60b784d6b82

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'
require 'mspec/expectations/expectations'
require 'mspec/matchers'

class HIMMSpecs
  def instance_method
  end

  class Subclass < HIMMSpecs
    def instance_sub_method
    end
  end
end

describe HaveInstanceMethodMatcher do
  it "inherits from MethodMatcher" do
    HaveInstanceMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
  end

  it "matches when mod has the instance method" do
    matcher = HaveInstanceMethodMatcher.new :instance_method
    matcher.matches?(HIMMSpecs).should be_truthy
    matcher.matches?(HIMMSpecs::Subclass).should be_truthy
  end

  it "does not match when mod does not have the instance method" do
    matcher = HaveInstanceMethodMatcher.new :another_method
    matcher.matches?(HIMMSpecs).should be_falsey
  end

  it "does not match if the method is in a superclass and include_super is false" do
    matcher = HaveInstanceMethodMatcher.new :instance_method, false
    matcher.matches?(HIMMSpecs::Subclass).should be_falsey
  end

  it "provides a failure message for #should" do
    matcher = HaveInstanceMethodMatcher.new :some_method
    matcher.matches?(HIMMSpecs)
    matcher.failure_message.should == [
      "Expected HIMMSpecs to have instance method 'some_method'",
      "but it does not"
    ]
  end

  it "provides a failure messoge for #should_not" do
    matcher = HaveInstanceMethodMatcher.new :some_method
    matcher.matches?(HIMMSpecs)
    matcher.negative_failure_message.should == [
      "Expected HIMMSpecs NOT to have instance method 'some_method'",
      "but it does"
    ]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mspec-1.9.1 spec/matchers/have_instance_method_spec.rb
mspec-1.9.0 spec/matchers/have_instance_method_spec.rb