HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/src/ruby-3.0.2/spec/mspec/spec/matchers/have_private_method_spec.rb
require 'spec_helper'
require 'mspec/expectations/expectations'
require 'mspec/matchers'

class HPMMSpecs
  def self.private_method
  end

  private_class_method :private_method
end

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

  it "matches when mod has the private method" do
    matcher = HavePrivateMethodMatcher.new :private_method
    matcher.matches?(HPMMSpecs).should be_true
  end

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

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

  it "provides a failure message for #should_not" do
    matcher = HavePrivateMethodMatcher.new :private_method
    matcher.matches?(HPMMSpecs)
    matcher.negative_failure_message.should == [
      "Expected HPMMSpecs NOT to have private method 'private_method'",
      "but it does"
    ]
  end
end