Module: Sinclair::Matchers

Defined in:
lib/sinclair/matchers.rb,
lib/sinclair/matchers/add_method.rb,
lib/sinclair/matchers/add_method_to.rb,
lib/sinclair/matchers/add_class_method.rb,
lib/sinclair/matchers/add_class_method_to.rb,
lib/sinclair/matchers/add_instance_method.rb,
lib/sinclair/matchers/add_instance_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: AddClassMethod, AddClassMethodTo, AddInstanceMethod, AddInstanceMethodTo, AddMethod, AddMethodTo

Instance Method Summary collapse

Instance Method Details

#add_class_method(method) ⇒ AddClassMethod

DSL to AddClassMethod

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

Returns:



54
55
56
# File 'lib/sinclair/matchers.rb', line 54

def add_class_method(method)
  Sinclair::Matchers::AddClassMethod.new(method)
end

#add_method(method) ⇒ AddInstanceMethod

DSL to AddInstanceMethod

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

Returns:



44
45
46
# File 'lib/sinclair/matchers.rb', line 44

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