Class: Sinclair::Matchers::AddClassMethodTo Private

Inherits:
AddMethodTo show all
Defined in:
lib/sinclair/matchers/add_class_method_to.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

AddClassMethodTo checks whether a method was or not added to a class by the call of a block

This is used with a RSpec DSL method add_class_method(method_name).to(class_object)

Examples:

RSpec.configure do |config|
  config.include Sinclair::Matchers
end

class MyModel
end

describe 'my test' do
  let(:klass)   { Class.new(MyModel) }

  let(:block) do
    proc do
      klass.define_singleton_method(:parent_name) { superclass.name }
    end
  end

  it do
    expect(&block).to add_class_method(:parent_name).to(klass)
  end
end

Author:

  • darthjee

Instance Method Summary collapse

Methods included from MethodTo

#failure_message, #failure_message_when_negated, #matches?

Methods inherited from Base

#equal?, #supports_block_expectations?

Constructor Details

#initialize(klass, method_name) ⇒ AddClassMethodTo

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AddClassMethodTo.

Parameters:

  • klass (Class)

    Class where the class method should be added to

  • method_name (SYmbol, String)

    method name



40
41
42
43
# File 'lib/sinclair/matchers/add_class_method_to.rb', line 40

def initialize(klass, method_name)
  @klass = klass
  super(method_name)
end

Instance Method Details

#descriptionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return expectaton description

Returns:

  • (String)


48
49
50
# File 'lib/sinclair/matchers/add_class_method_to.rb', line 48

def description
  "add class method '#{method_name}' to #{klass}"
end

#failure_message_for_shouldString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns message on expectation failure

Returns:

  • (String)


55
56
57
58
# File 'lib/sinclair/matchers/add_class_method_to.rb', line 55

def failure_message_for_should
  "expected class method '#{method_name}' to be added to #{klass} but " \
    "#{initial_state ? 'it already existed' : "it didn't"}"
end

#failure_message_for_should_notString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns message on expectation failure for negative expectation

Returns:

  • (String)


63
64
65
# File 'lib/sinclair/matchers/add_class_method_to.rb', line 63

def failure_message_for_should_not
  "expected class method '#{method_name}' not to be added to #{klass} but it was"
end