Module: DrLight::Matchers

Defined in:
lib/dr_light/matchers.rb,
lib/dr_light/matchers/close_to.rb
more...

Overview

Rspec matchers DSL to be included in rspec

Examples:

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

Defined Under Namespace

Classes: CloseTo

Instance Method Summary collapse

Instance Method Details

#be_close_to(expected, deviance: nil) ⇒ CloseTo #be_close_to(expected) ⇒ CloseTo

Checks if value is close to expected value

Examples:

describe DrLight::Matchers do
  describe 'be_close_to' do
    subject(:value) { 10.0 }

    context 'when they are close' do
      it do
        expect(value).to be_close_to(11, deviance: 1)
      end
    end

    context 'when they are not close' do
      let(:expected) { DrLight::ScientificNumber.new(9, 0.5) }

      it do
        expect(value).not_to be_close_to(expected)
      end
    end
  end
end

Overloads:

  • #be_close_to(expected, deviance: nil) ⇒ CloseTo

    Parameters:

    • expected (Number)

      Target to be close to

    • deviance (Number) (defaults to: nil)

      Closeness deviance

  • #be_close_to(expected) ⇒ CloseTo

    Parameters:

Returns:

[View source]

46
47
48
# File 'lib/dr_light/matchers.rb', line 46

def be_close_to(expected, deviance: nil)
  CloseTo.new(expected, deviance)
end