@api private Base class for `and` and `or` compound matchers.
@private
@private
# File lib/rspec/matchers/built_in/compound.rb, line 10 def initialize(matcher_1, matcher_2) @matcher_1 = matcher_1 @matcher_2 = matcher_2 end
@api private @return [String]
# File lib/rspec/matchers/built_in/compound.rb, line 23 def description singleline_message(matcher_1.description, matcher_2.description) end
@private
# File lib/rspec/matchers/built_in/compound.rb, line 16 def does_not_match?(actual) raise NotImplementedError, "`expect(...).not_to matcher.#{conjunction} matcher` is not supported" end
# File lib/rspec/matchers/built_in/compound.rb, line 41 def compound_failure_message message_1 = matcher_1.failure_message message_2 = matcher_2.failure_message if multiline?(message_1) || multiline?(message_2) multiline_message(message_1, message_2) else singleline_message(message_1, message_2) end end
# File lib/rspec/matchers/built_in/compound.rb, line 35 def indent_multiline_message(message) message.lines.map do |line| line =~ /\S/ ? ' ' + line : line end.join end
# File lib/rspec/matchers/built_in/compound.rb, line 29 def initialize_copy(other) @matcher_1 = @matcher_1.clone @matcher_2 = @matcher_2.clone super end
# File lib/rspec/matchers/built_in/compound.rb, line 60 def multiline?(message) message.lines.count > 1 end
# File lib/rspec/matchers/built_in/compound.rb, line 52 def multiline_message(message_1, message_2) [ indent_multiline_message(message_1.sub(/\n+\z/, '')), "...#{conjunction}:", indent_multiline_message(message_2.sub(/\A\n+/, '')) ].join("\n\n") end
# File lib/rspec/matchers/built_in/compound.rb, line 64 def singleline_message(message_1, message_2) [message_1, conjunction, message_2].join(' ') end