Class: Sinclair::Matchers::AddInstanceMethod Private

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

AddInstanceMethod is able to build an instance of AddInstanceMethodTo

Author:

  • darthjee

Instance Method Summary collapse

Methods inherited from AddMethod

#matches?

Methods inherited from Base

#equal?, #initialize, #supports_block_expectations?

Constructor Details

This class inherits a constructor from Sinclair::Matchers::Base

Instance Method Details

#to(target = nil) ⇒ AddInstanceMethodTo

Builds final matcher

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

Examples:

Using inside RSpec and checking an instance method being added

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

class MyModel
end

RSpec.describe "MyBuilder" do
  let(:clazz)   { Class.new(MyModel) }
  let(:builder) { Sinclair.new(clazz) }

  before do
    builder.add_method(:new_method, "2")
  end

  it do
    expect { builder.build }.to add_method(:new_method).to(clazz)
  end
end

# Outputs
# 'should add method 'new_method' to #<Class:0x000056441bf46608> instances'

Using inside RSpec and checking instance

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

class MyModel
end

RSpec.describe "MyBuilder" do
  let(:clazz)    { Class.new(MyModel) }
  let(:builder)  { Sinclair.new(clazz) }
  let(:instance) { clazz.new }

  before do
    builder.add_method(:the_method, "true")
  end

  it do
    expect { builder.build }.to add_method(:the_method).to(instance)
  end
end

# Outputs
# 'should add method 'the_method' to #<Class:0x000056441bf46608> instances'

Parameters:

  • target (Class, Object) (defaults to: nil)

    where the method will be added

Returns:



59
# File 'lib/sinclair/matchers/add_instance_method.rb', line 59

with_final_matcher :to, AddInstanceMethodTo