Class: Sinclair::Matchers::AddClassMethod Private

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

AddClassMethod is able to build an instance of AddClassMethodTo

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

Builds final matcher

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

Examples:

Checking if a class had a class method added

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

class MyModel
end

RSpec.describe 'MyBuilder' do
  let(:clazz)   { Class.new(MyModel) }

  let(:block) do
    proc do
      clazz.define_singleton_method(:new_method) { 2 }
    end
  end

  it do
    expect(&block).to add_class_method(:new_method).to(clazz)
  end
end

# outputs
# should add method class_method 'new_method' to #<Class:0x000055b4d0a25c80>

Parameters:

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

    where the method will be added

Returns:



34
# File 'lib/sinclair/matchers/add_class_method.rb', line 34

with_final_matcher :to, AddClassMethodTo