class RSpec::Rails::Matchers::BeANew
@see RSpec::Rails::Matchers#be_a_new
Matcher class for ‘be_a_new`. Should not be instantiated directly.
@api private
def attributes
def attributes @attributes ||= {} end
def attributes_match?(actual)
def attributes_match?(actual) attributes.stringify_keys.all? do |key, value| values_match?(value, actual.attributes[key]) end end
def failure_message
- Private: -
def failure_message [].tap do |message| unless actual.is_a?(expected) && actual.new_record? message << "expected #{actual.inspect} to be a new #{expected.inspect}" end unless attributes_match?(actual) describe_unmatched_attributes = surface_descriptions_in(unmatched_attributes) if unmatched_attributes.size > 1 message << "attributes #{describe_unmatched_attributes.inspect} were not set on #{actual.inspect}" else message << "attribute #{describe_unmatched_attributes.inspect} was not set on #{actual.inspect}" end end end.join(' and ') end
def initialize(expected)
- Private: -
def initialize(expected) @expected = expected end
def matches?(actual)
- Private: -
def matches?(actual) @actual = actual actual.is_a?(expected) && actual.new_record? && attributes_match?(actual) end
def unmatched_attributes
def unmatched_attributes attributes.stringify_keys.reject do |key, value| values_match?(value, actual.attributes[key]) end end
def with(expected_attributes)
- See: RSpec::Rails::Matchers#be_a_new -
Other tags:
- Api: - public
def with(expected_attributes) attributes.merge!(expected_attributes) self end