Module: Sinclair::Matchers::AddMethod Private

Included in:
AddClassMethod, AddInstanceMethod, ChangeClassMethod, ChangeInstanceMethod
Defined in:
lib/sinclair/matchers/add_method.rb

Overview

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

Commone methods for matchers

Instance Method Summary collapse

Instance Method Details

#matches?(_actual) ⇒ Boolean

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.

This method is abstract.

Raise a warning on the usage as this is only a builder

Returns:

  • (Boolean)

Raises:

  • SyntaxError



49
50
51
# File 'lib/sinclair/matchers/add_method.rb', line 49

def matches?(_actual)
  raise SyntaxError, matcher_error
end

#to(target = nil) ⇒ Sinclair::Matchers::Base

Builds final matcher

The matcher checks if a method was added to a class or instance

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

Parameters:

  • target (target) (defaults to: nil) —

    where the method will be added

Returns:



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

def to(target = nil)
  add_method_to_class.new(target, method_name)
end