Class: Sinclair::Matchers::ChangeClassMethod Private

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

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) ⇒ ChangeClassMethodOn

Builds final matcher

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

Examples:

Checking if a class 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_class_method(:the_method) { 10 }
    builder.build
    builder.add_class_method(:the_method) { 20 }
  end

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

Parameters:

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

    where the method will be added

Returns:



33
# File 'lib/sinclair/matchers/change_class_method.rb', line 33

with_final_matcher :on, ChangeClassMethodOn