Sha256: 730194fc0082b8199994042770bc92f61ac569a23fbd1e6b62f9da0284eb24c4

Contents?: true

Size: 1.54 KB

Versions: 7

Compression:

Stored size: 1.54 KB

Contents

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

class HMMSpecs
  def instance_method
  end

  class Subclass < HMMSpecs
    def instance_sub_method
    end
  end
end

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

  it "matches when mod has the method" do
    matcher = HaveMethodMatcher.new :instance_method
    matcher.matches?(HMMSpecs).should be_true
    matcher.matches?(HMMSpecs.new).should be_true
    matcher.matches?(HMMSpecs::Subclass).should be_true
    matcher.matches?(HMMSpecs::Subclass.new).should be_true
  end

  it "does not match when mod does not have the method" do
    matcher = HaveMethodMatcher.new :another_method
    matcher.matches?(HMMSpecs).should be_false
  end

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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mspec-1.8.0 spec/matchers/have_method_spec.rb
mspec-1.7.0 spec/matchers/have_method_spec.rb
mspec-1.6.0 spec/matchers/have_method_spec.rb
mspec-1.5.21 spec/matchers/have_method_spec.rb
mspec-1.5.20 spec/matchers/have_method_spec.rb
mspec-1.5.19 spec/matchers/have_method_spec.rb
mspec-1.5.18 spec/matchers/have_method_spec.rb