Module: Sinclair::Matchers

Defined in:
lib/sinclair/matchers.rb,
lib/sinclair/matchers/add_method.rb,
lib/sinclair/matchers/add_method_to.rb

Overview

Matchers module will have the DSL to be included in RSpec in order to have access to the matchers

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

Author:

  • darthjee

Defined Under Namespace

Classes: AddMethod, AddMethodTo

Instance Method Summary collapse

Instance Method Details

#add_method(method) ⇒ AddMethod

DSL to AddMethod

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

Using inside RSpec and checking Class

RSpec.describe "MyBuilder" do
  let(:clazz)   { Class.new }
  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.describe "MyBuilder" do
  let(:clazz)    { Class.new }
  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'

Returns:



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

def add_method(method)
  Sinclair::Matchers::AddMethod.new(method)
end