class RSpec::Rails::Matchers::BeANew
@api private
Matcher class for `be_a_new`. Should not be instantiated directly.
Public Class Methods
new(expected)
click to toggle source
@private
# File lib/rspec/rails/matchers/be_a_new.rb, line 11 def initialize(expected) @expected = expected end
Public Instance Methods
failure_message()
click to toggle source
@private
# File lib/rspec/rails/matchers/be_a_new.rb, line 29 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) if unmatched_attributes.size > 1 message << "attributes #{unmatched_attributes.inspect} were not set on #{actual.inspect}" else message << "attribute #{unmatched_attributes.inspect} was not set on #{actual.inspect}" end end end.join(' and ') end
matches?(actual)
click to toggle source
@private
# File lib/rspec/rails/matchers/be_a_new.rb, line 16 def matches?(actual) @actual = actual actual.is_a?(expected) && actual.new_record? && attributes_match?(actual) end
with(expected_attributes)
click to toggle source
@api public @see RSpec::Rails::Matchers#be_a_new
# File lib/rspec/rails/matchers/be_a_new.rb, line 23 def with(expected_attributes) attributes.merge!(expected_attributes) self end
Private Instance Methods
attributes()
click to toggle source
# File lib/rspec/rails/matchers/be_a_new.rb, line 46 def attributes @attributes ||= {} end
attributes_match?(actual)
click to toggle source
# File lib/rspec/rails/matchers/be_a_new.rb, line 50 def attributes_match?(actual) attributes.stringify_keys.all? do |key, value| actual.attributes[key].eql?(value) end end
unmatched_attributes()
click to toggle source
# File lib/rspec/rails/matchers/be_a_new.rb, line 56 def unmatched_attributes attributes.stringify_keys.reject do |key, value| actual.attributes[key].eql?(value) end end