Class: Sinclair::Matchers::AddInstanceMethodTo Private

Inherits:
AddMethodTo
  • Object
show all
Defined in:
lib/sinclair/matchers/add_instance_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.

AddInstanceMethodTo checks whether a method was or not added by the call of a block

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

Examples:

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

class MyModel
end

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

  before do
    builder.add_method(:class_name, 'self.class.name')
  end

  it do
    expect { builder.build }.to add_method(:class_name).to(klass)
  end
end

Author:

  • darthjee

Instance Method Summary collapse

Methods inherited from AddMethodTo

#equal?, #matches?, #supports_block_expectations?

Constructor Details

#initialize(klass, method) ⇒ AddInstanceMethodTo #initialize(instance, method) ⇒ AddInstanceMethodTo

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 AddInstanceMethodTo



44
45
46
47
48
49
50
51
# File 'lib/sinclair/matchers/add_instance_method_to.rb', line 44

def initialize(target, method)
  if target.is_a?(Class)
    @klass = target
  else
    @instance = target
  end
  super(method)
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.

Returnst expectaton description



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

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

#failure_message_for_shouldString Also known as: failure_message

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



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

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

#failure_message_for_should_notString Also known as: failure_message_when_negated

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



71
72
73
# File 'lib/sinclair/matchers/add_instance_method_to.rb', line 71

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