Module: RSpec::Matchers

Defined in:
lib/saharspec/matchers/eq_multiline.rb,
lib/saharspec/matchers/send_message.rb

Instance Method Summary collapse

Instance Method Details

#eq_multiline(expected) ⇒ Object

Allows to pretty test multiline strings with complex indentation (for example, results of code generation).

In provided string, removes first and last empty line, trailing spaces and leading spaces up to | character.

If you need to preserve trailing spaces, end them with another |.

Examples:

require 'saharspec/matchers/eq_multiline'

expect(some_code_gen).to eq_multiline(%{
  |def something
  |  a = 5
  |  a**2
  |end
})

Parameters:

  • (String)


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

def eq_multiline(expected)
  Saharspec::Matchers::EqMultiline.new(expected)
end

#send_message(target, method) ⇒ Object

Checks if the (block) subject sends specified message to specified object.

Examples:

# before:
specify {
   allow(double).to receive(:fetch)
   code_being_tested
   expect(double).to have_received(:fetch).with(something)
}

# after:
require 'saharspec/matchers/send_message'
it { expect { code_being_tested }.to send_message(double, :fetch).with(something) }
# after + its_call
require 'saharspec/its/call'
subject { code_being_tested }
its_call { is_expected.to send_message(double, :fetch).with(something) }

Parameters:

  • target

    Object which expects message, double or real object

  • method (Symbol)

    Message being expected

Returns:

  • Instance of a matcher, allowing the following additional methods:

    • once, twice, exactly(n).times;
    • with(arguments);
    • calling_original;
    • returning(response).


134
135
136
# File 'lib/saharspec/matchers/send_message.rb', line 134

def send_message(target, method)
  Saharspec::Matchers::SendMessage.new(target, method)
end