Sha256: 8bf3efabcf45e5fc7415a5132e89d85dd76c52af1a3c946aef86b010880968a0

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

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

class HPIMMSpecs
  private

  def private_method
  end

  class Subclass < HPIMMSpecs
    private

    def private_sub_method
    end
  end
end

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

  it "matches when mod has the private instance method" do
    matcher = HavePrivateInstanceMethodMatcher.new :private_method
    matcher.matches?(HPIMMSpecs).should be_truthy
    matcher.matches?(HPIMMSpecs::Subclass).should be_truthy
  end

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

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

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

  it "provides a failure message for #should_not" do
    matcher = HavePrivateInstanceMethodMatcher.new :some_method
    matcher.matches?(HPIMMSpecs)
    matcher.negative_failure_message.should == [
      "Expected HPIMMSpecs NOT to have private 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_private_instance_method_spec.rb
mspec-1.9.0 spec/matchers/have_private_instance_method_spec.rb