Module: Surrogate::RSpec::MessagesFor

Extended by:
MessagesFor
Included in:
MessagesFor
Defined in:
lib/surrogate/rspec/api_method_matchers.rb,
lib/surrogate/rspec/substitutability_matchers.rb

Constant Summary collapse

MESSAGES =
{
  verb: {
    should: {
      default:    "was never told to <%= subject %>",
      with:       "should have been told to <%= subject %> with <%= inspect_arguments expected_arguments %>, but <%= actual_invocation %>",
      times:      "should have been told to <%= subject %> <%= times_msg expected_times_invoked %> but was told to <%= subject %> <%= times_msg times_invoked %>",
      with_times: "should have been told to <%= subject %> <%= times_msg expected_times_invoked %> with <%= inspect_arguments expected_arguments %>, but <%= actual_invocation %>",
    },
    should_not: {
      default:    "shouldn't have been told to <%= subject %>, but was told to <%= subject %> <%= times_msg times_invoked %>",
      with:       "should not have been told to <%= subject %> with <%= inspect_arguments expected_arguments %>, but <%= actual_invocation %>",
      times:      "shouldn't have been told to <%= subject %> <%= times_msg expected_times_invoked %>, but was",
      with_times: "should not have been told to <%= subject %> <%= times_msg expected_times_invoked %> with <%= inspect_arguments expected_arguments %>, but <%= actual_invocation %>",
    },
    other: {
      not_invoked: "was never told to",
      invoked_description: "got it",
    },
  },
  noun: {
    should: {
      default:    "was never asked for its <%= subject %>",
      with:       "should have been asked for its <%= subject %> with <%= inspect_arguments expected_arguments %>, but <%= actual_invocation %>",
      times:      "should have been asked for its <%= subject %> <%= times_msg expected_times_invoked %>, but was asked <%= times_msg times_invoked %>",
      with_times: "should have been asked for its <%= subject %> <%= times_msg expected_times_invoked %> with <%= inspect_arguments expected_arguments %>, but <%= actual_invocation %>",
    },
    should_not: {
      default:    "shouldn't have been asked for its <%= subject %>, but was asked <%= times_msg times_invoked %>",
      with:       "should not have been asked for its <%= subject %> with <%= inspect_arguments expected_arguments %>, but <%= actual_invocation %>",
      times:      "shouldn't have been asked for its <%= subject %> <%= times_msg expected_times_invoked %>, but was",
      with_times: "should not have been asked for its <%= subject %> <%= times_msg expected_times_invoked %> with <%= inspect_arguments expected_arguments %>, but <%= actual_invocation %>",
    },
    other: {
      not_invoked: "was never asked",
      invoked_description: "was asked",
    },
  },
}

Instance Method Summary collapse

Instance Method Details

#inspect_argument(to_inspect) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/surrogate/rspec/api_method_matchers.rb', line 58

def inspect_argument(to_inspect)
  if to_inspect.kind_of? ::RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
    "no_args"
  else
    to_inspect.inspect
  end
end

#inspect_arguments(arguments) ⇒ Object



52
53
54
55
56
# File 'lib/surrogate/rspec/api_method_matchers.rb', line 52

def inspect_arguments(arguments)
  inspected_arguments = arguments.map { |argument| MessagesFor.inspect_argument argument }
  inspected_arguments << 'no_args' if inspected_arguments.empty?
  %Q(`#{inspected_arguments.join ", "}')
end

#message_for(language_type, message_category, message_type, binding) ⇒ Object



47
48
49
50
# File 'lib/surrogate/rspec/api_method_matchers.rb', line 47

def message_for(language_type, message_category, message_type, binding)
  message = MESSAGES[language_type][message_category].fetch(message_type)
  ERB.new(message).result(binding)
end