Class: Sinclair::Matchers::ChangeInstanceMethod Private

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

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

#on(target = nil) ⇒ ChangeInstanceMethodOn

Builds final matcher

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

Examples:

Checking if an instance method has changed

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

class MyModel
end

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

  before do
    builder.add_method(:the_method) { 10 }
    builder.build
    builder.add_method(:the_method) { 20 }
  end

  it do
    expect{ builder.build }.to change_method(:the_method).on(klass)
  end
end

Checking if an instance method has changed on an instance

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

class MyModel
end

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

  before do
    builder.add_method(:the_method) { 10 }
    builder.build
    builder.add_method(:the_method) { 20 }
  end

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

Parameters:

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

    where the method will be added

Returns:



57
# File 'lib/sinclair/matchers/change_instance_method.rb', line 57

with_final_matcher :on, ChangeInstanceMethodOn