1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

Rename failure_message and negative_failure_message

* fixes #108 : RSpec 2.10 compatibility
* remove unnecessary attr_readr
This commit is contained in:
Brian Shaver 2013-01-08 12:29:01 -05:00 committed by Jason Draper
parent db83bb2cef
commit 4f8684c6db
44 changed files with 118 additions and 120 deletions

View file

@ -6,7 +6,7 @@ PATH
bourne (~> 1.2.0) bourne (~> 1.2.0)
GEM GEM
remote: http://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actionmailer (3.2.9) actionmailer (3.2.9)
actionpack (= 3.2.9) actionpack (= 3.2.9)

View file

@ -1,5 +1,5 @@
PATH PATH
remote: /vagrant remote: /Users/draper/Dropbox/Development/shoulda-matchers
specs: specs:
shoulda-matchers (1.4.2) shoulda-matchers (1.4.2)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)

View file

@ -1,5 +1,5 @@
PATH PATH
remote: /vagrant remote: /Users/draper/Dropbox/Development/shoulda-matchers
specs: specs:
shoulda-matchers (1.4.2) shoulda-matchers (1.4.2)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)

View file

@ -1,5 +1,5 @@
PATH PATH
remote: /vagrant remote: /Users/draper/Dropbox/Development/shoulda-matchers
specs: specs:
shoulda-matchers (1.4.2) shoulda-matchers (1.4.2)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)

View file

@ -19,7 +19,7 @@ module Shoulda # :nodoc:
end end
class AssignToMatcher # :nodoc: class AssignToMatcher # :nodoc:
attr_reader :failure_message, :negative_failure_message attr_reader :failure_message_for_should, :failure_message_for_should_not
def initialize(variable) def initialize(variable)
@variable = variable.to_s @variable = variable.to_s
@ -64,12 +64,12 @@ module Shoulda # :nodoc:
def assigned_value? def assigned_value?
if @controller.instance_variables.map(&:to_s).include?("@#{@variable}") if @controller.instance_variables.map(&:to_s).include?("@#{@variable}")
@negative_failure_message = @failure_message_for_should_not =
"Didn't expect action to assign a value for @#{@variable}, " << "Didn't expect action to assign a value for @#{@variable}, " <<
"but it was assigned to #{assigned_value.inspect}" "but it was assigned to #{assigned_value.inspect}"
true true
else else
@failure_message = @failure_message_for_should =
"Expected action to assign a value for @#{@variable}" "Expected action to assign a value for @#{@variable}"
false false
end end
@ -78,12 +78,12 @@ module Shoulda # :nodoc:
def kind_of_expected_class? def kind_of_expected_class?
if @options.key?(:expected_class) if @options.key?(:expected_class)
if assigned_value.kind_of?(@options[:expected_class]) if assigned_value.kind_of?(@options[:expected_class])
@negative_failure_message = @failure_message_for_should_not =
"Didn't expect action to assign a kind of #{@options[:expected_class]} " << "Didn't expect action to assign a kind of #{@options[:expected_class]} " <<
"for #{@variable}, but got one anyway" "for #{@variable}, but got one anyway"
true true
else else
@failure_message = @failure_message_for_should =
"Expected action to assign a kind of #{@options[:expected_class]} " << "Expected action to assign a kind of #{@options[:expected_class]} " <<
"for #{@variable}, but got #{assigned_value.inspect} " << "for #{@variable}, but got #{assigned_value.inspect} " <<
"(#{assigned_value.class.name})" "(#{assigned_value.class.name})"
@ -97,12 +97,12 @@ module Shoulda # :nodoc:
def equal_to_expected_value? def equal_to_expected_value?
if @options[:check_value] if @options[:check_value]
if @options[:expected_value] == assigned_value if @options[:expected_value] == assigned_value
@negative_failure_message = @failure_message_for_should_not =
"Didn't expect action to assign #{@options[:expected_value].inspect} " << "Didn't expect action to assign #{@options[:expected_value].inspect} " <<
"for #{@variable}, but got it anyway" "for #{@variable}, but got it anyway"
true true
else else
@failure_message = @failure_message_for_should =
"Expected action to assign #{@options[:expected_value].inspect} " << "Expected action to assign #{@options[:expected_value].inspect} " <<
"for #{@variable}, but got #{assigned_value.inspect}" "for #{@variable}, but got #{assigned_value.inspect}"
false false

View file

@ -19,11 +19,11 @@ module Shoulda # :nodoc:
filters_key? filters_key?
end end
def failure_message def failure_message_for_should
"Expected #{@key} to be filtered; filtered keys: #{filtered_keys.join(', ')}" "Expected #{@key} to be filtered; filtered keys: #{filtered_keys.join(', ')}"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{@key} to be filtered" "Did not expect #{@key} to be filtered"
end end

View file

@ -12,7 +12,7 @@ module Shoulda # :nodoc:
end end
class RedirectToMatcher # :nodoc: class RedirectToMatcher # :nodoc:
attr_reader :failure_message, :negative_failure_message attr_reader :failure_message_for_should, :failure_message_for_should_not
def initialize(url_or_description, context, &block) def initialize(url_or_description, context, &block)
if block if block
@ -44,10 +44,10 @@ module Shoulda # :nodoc:
def redirects_to_url? def redirects_to_url?
begin begin
@context.send(:assert_redirected_to, url) @context.send(:assert_redirected_to, url)
@negative_failure_message = "Didn't expect to redirect to #{url}" @failure_message_for_should_not = "Didn't expect to redirect to #{url}"
true true
rescue Shoulda::Matchers::AssertionError => error rescue Shoulda::Matchers::AssertionError => error
@failure_message = error.message @failure_message_for_should = error.message
false false
end end
end end

View file

@ -20,7 +20,7 @@ module Shoulda # :nodoc:
end end
class RenderTemplateMatcher # :nodoc: class RenderTemplateMatcher # :nodoc:
attr_reader :failure_message, :negative_failure_message attr_reader :failure_message_for_should, :failure_message_for_should_not
def initialize(options, message, context) def initialize(options, message, context)
@options = options @options = options
@ -48,10 +48,10 @@ module Shoulda # :nodoc:
def renders_template? def renders_template?
begin begin
@context.send(:assert_template, @options, @message) @context.send(:assert_template, @options, @message)
@negative_failure_message = "Didn't expect to render #{@template}" @failure_message_for_should_not = "Didn't expect to render #{@template}"
true true
rescue Shoulda::Matchers::AssertionError => error rescue Shoulda::Matchers::AssertionError => error
@failure_message = error.message @failure_message_for_should = error.message
false false
end end
end end

View file

@ -33,11 +33,11 @@ module Shoulda # :nodoc:
rendered_with_layout? && rendered_with_expected_layout? rendered_with_layout? && rendered_with_expected_layout?
end end
def failure_message def failure_message_for_should
"Expected #{expectation}, but #{result}" "Expected #{expectation}, but #{result}"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{expectation}, but #{result}" "Did not expect #{expectation}, but #{result}"
end end

View file

@ -35,11 +35,11 @@ module Shoulda # :nodoc:
content_type_matches_regexp? || content_type_matches_string? content_type_matches_regexp? || content_type_matches_string?
end end
def failure_message def failure_message_for_should
"Expected #{expectation}" "Expected #{expectation}"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{expectation}" "Did not expect #{expectation}"
end end

View file

@ -30,11 +30,11 @@ module Shoulda # :nodoc:
correct_status_code? || correct_status_code_range? correct_status_code? || correct_status_code_range?
end end
def failure_message def failure_message_for_should
"Expected #{expectation}" "Expected #{expectation}"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{expectation}" "Did not expect #{expectation}"
end end

View file

@ -33,7 +33,7 @@ module Shoulda # :nodoc:
@context = context @context = context
end end
attr_reader :failure_message, :negative_failure_message attr_reader :failure_message_for_should, :failure_message_for_should_not
def to(params) def to(params)
@params = stringify_params(params) @params = stringify_params(params)
@ -80,13 +80,13 @@ module Shoulda # :nodoc:
{ :method => @method, :path => @path }, { :method => @method, :path => @path },
@params) @params)
@negative_failure_message = "Didn't expect to #{description}" @failure_message_for_should_not = "Didn't expect to #{description}"
true true
rescue ::ActionController::RoutingError => error rescue ::ActionController::RoutingError => error
@failure_message = error.message @failure_message_for_should = error.message
false false
rescue Shoulda::Matchers::AssertionError => error rescue Shoulda::Matchers::AssertionError => error
@failure_message = error.message @failure_message_for_should = error.message
false false
end end
end end

View file

@ -32,11 +32,11 @@ module Shoulda # :nodoc:
assigned_correct_value? || cleared_value? assigned_correct_value? || cleared_value?
end end
def failure_message def failure_message_for_should
"Expected #{expectation}, but #{result}" "Expected #{expectation}, but #{result}"
end end
def negative_failure_message def failure_message_for_should_not
"Didn't expect #{expectation}, but #{result}" "Didn't expect #{expectation}, but #{result}"
end end

View file

@ -22,8 +22,6 @@ module Shoulda # :nodoc:
@options = {} @options = {}
end end
attr_reader :failure_message, :negative_failure_message
def to(value) def to(value)
if !value.is_a?(String) && !value.is_a?(Regexp) if !value.is_a?(String) && !value.is_a?(Regexp)
raise "cannot match against #{value.inspect}" raise "cannot match against #{value.inspect}"
@ -53,11 +51,11 @@ module Shoulda # :nodoc:
description description
end end
def failure_message def failure_message_for_should
"Expected #{expectation}" "Expected #{expectation}"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{expectation}" "Did not expect #{expectation}"
end end

View file

@ -106,11 +106,11 @@ module Shoulda # :nodoc:
end end
end end
def failure_message def failure_message_for_should
"Expected #{expectation}" "Expected #{expectation}"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{expectation}" "Did not expect #{expectation}"
end end

View file

@ -16,7 +16,7 @@ module Shoulda # :nodoc:
end end
class AllowMassAssignmentOfMatcher # :nodoc: class AllowMassAssignmentOfMatcher # :nodoc:
attr_reader :failure_message, :negative_failure_message attr_reader :failure_message_for_should, :failure_message_for_should_not
def initialize(attribute) def initialize(attribute)
@attribute = attribute.to_s @attribute = attribute.to_s
@ -35,12 +35,12 @@ module Shoulda # :nodoc:
@subject = subject @subject = subject
if attr_mass_assignable? if attr_mass_assignable?
if whitelisting? if whitelisting?
@negative_failure_message = "#{@attribute} was made accessible" @failure_message_for_should_not = "#{@attribute} was made accessible"
else else
if protected_attributes.empty? if protected_attributes.empty?
@negative_failure_message = 'no attributes were protected' @failure_message_for_should_not = 'no attributes were protected'
else else
@negative_failure_message = "#{class_name} is protecting " << @failure_message_for_should_not = "#{class_name} is protecting " <<
"#{protected_attributes.to_a.to_sentence}, " << "#{protected_attributes.to_a.to_sentence}, " <<
"but not #{@attribute}." "but not #{@attribute}."
end end
@ -48,9 +48,9 @@ module Shoulda # :nodoc:
true true
else else
if whitelisting? if whitelisting?
@failure_message = "Expected #{@attribute} to be accessible" @failure_message_for_should = "Expected #{@attribute} to be accessible"
else else
@failure_message = "Did not expect #{@attribute} to be protected" @failure_message_for_should = "Did not expect #{@attribute} to be protected"
end end
false false
end end

View file

@ -60,11 +60,11 @@ module Shoulda # :nodoc:
end end
end end
def failure_message def failure_message_for_should
"Did not expect #{expectation}, got error: #{@matched_error}" "Did not expect #{expectation}, got error: #{@matched_error}"
end end
def negative_failure_message def failure_message_for_should_not
"Expected #{expectation}, got #{error_description}" "Expected #{expectation}, got #{error_description}"
end end

View file

@ -20,8 +20,8 @@ module Shoulda # :nodoc:
self self
end end
def failure_message def failure_message_for_should
@allow_matcher.negative_failure_message @allow_matcher.failure_message_for_should_not
end end
def allowed_types def allowed_types

View file

@ -88,7 +88,7 @@ module Shoulda # :nodoc:
if allows_all_values_in_array? && allows_blank_value? && allows_nil_value? && disallows_value_outside_of_array? if allows_all_values_in_array? && allows_blank_value? && allows_nil_value? && disallows_value_outside_of_array?
true true
else else
@failure_message = "#{@array} doesn't match array in validation" @failure_message_for_should = "#{@array} doesn't match array in validation"
false false
end end
end end

View file

@ -24,8 +24,8 @@ module Shoulda # :nodoc:
'integer' 'integer'
end end
def failure_message def failure_message_for_should
@disallow_value_matcher.failure_message @disallow_value_matcher.failure_message_for_should
end end
end end
end end

View file

@ -48,7 +48,7 @@ module Shoulda # :nodoc:
"only allow #{allowed_types} values for #{@attribute}" "only allow #{allowed_types} values for #{@attribute}"
end end
def failure_message def failure_message_for_should
submatcher_failure_messages.last submatcher_failure_messages.last
end end
@ -71,7 +71,7 @@ module Shoulda # :nodoc:
end end
def submatcher_failure_messages def submatcher_failure_messages
failing_submatchers.map(&:failure_message) failing_submatchers.map(&:failure_message_for_should)
end end
def failing_submatchers def failing_submatchers

View file

@ -96,7 +96,7 @@ module Shoulda # :nodoc:
@subject.send(setter, existing.send(scope)) @subject.send(setter, existing.send(scope))
true true
else else
@failure_message = "#{class_name} doesn't seem to have a #{scope} attribute." @failure_message_for_should = "#{class_name} doesn't seem to have a #{scope} attribute."
false false
end end
end end
@ -133,11 +133,11 @@ module Shoulda # :nodoc:
if allows_value_of(existing_value, @expected_message) if allows_value_of(existing_value, @expected_message)
@subject.send("#{scope}=", previous_value) @subject.send("#{scope}=", previous_value)
@negative_failure_message << @failure_message_for_should_not <<
" (with different value of #{scope})" " (with different value of #{scope})"
true true
else else
@failure_message << " (with different value of #{scope})" @failure_message_for_should << " (with different value of #{scope})"
false false
end end
end end

View file

@ -2,7 +2,7 @@ module Shoulda # :nodoc:
module Matchers module Matchers
module ActiveModel # :nodoc: module ActiveModel # :nodoc:
class ValidationMatcher # :nodoc: class ValidationMatcher # :nodoc:
attr_reader :failure_message attr_reader :failure_message_for_should
def initialize(attribute) def initialize(attribute)
@attribute = attribute @attribute = attribute
@ -14,8 +14,8 @@ module Shoulda # :nodoc:
self self
end end
def negative_failure_message def failure_message_for_should_not
@negative_failure_message || @failure_message @failure_message_for_should_not || @failure_message_for_should
end end
def matches?(subject) def matches?(subject)
@ -29,10 +29,10 @@ module Shoulda # :nodoc:
allow = allow_value_matcher(value, message) allow = allow_value_matcher(value, message)
if allow.matches?(@subject) if allow.matches?(@subject)
@negative_failure_message = allow.failure_message @failure_message_for_should_not = allow.failure_message_for_should
true true
else else
@failure_message = allow.negative_failure_message @failure_message_for_should = allow.failure_message_for_should_not
false false
end end
end end
@ -41,10 +41,10 @@ module Shoulda # :nodoc:
disallow = allow_value_matcher(value, message) disallow = allow_value_matcher(value, message)
if disallow.matches?(@subject) if disallow.matches?(@subject)
@failure_message = disallow.negative_failure_message @failure_message_for_should = disallow.failure_message_for_should_not
false false
else else
@negative_failure_message = disallow.failure_message @failure_message_for_should_not = disallow.failure_message_for_should
true true
end end
end end

View file

@ -50,11 +50,11 @@ module Shoulda
update_only_correct? update_only_correct?
end end
def failure_message def failure_message_for_should
"Expected #{expectation} (#{@problem})" "Expected #{expectation} (#{@problem})"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{expectation}" "Did not expect #{expectation}"
end end

View file

@ -124,11 +124,11 @@ module Shoulda # :nodoc:
validate_correct? validate_correct?
end end
def failure_message def failure_message_for_should
"Expected #{expectation} (#{@missing})" "Expected #{expectation} (#{@missing})"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{expectation}" "Did not expect #{expectation}"
end end

View file

@ -51,11 +51,11 @@ module Shoulda # :nodoc:
correct_primary? correct_primary?
end end
def failure_message def failure_message_for_should
"Expected #{expectation} (#{@missing})" "Expected #{expectation} (#{@missing})"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{expectation}" "Did not expect #{expectation}"
end end

View file

@ -37,11 +37,11 @@ module Shoulda # :nodoc:
index_exists? && correct_unique? index_exists? && correct_unique?
end end
def failure_message def failure_message_for_should
"Expected #{expectation} (#{@missing})" "Expected #{expectation} (#{@missing})"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{expectation}" "Did not expect #{expectation}"
end end

View file

@ -16,19 +16,19 @@ module Shoulda # :nodoc:
@attribute = attribute.to_s @attribute = attribute.to_s
end end
attr_reader :failure_message, :negative_failure_message attr_reader :failure_message_for_should, :failure_message_for_should_not
def matches?(subject) def matches?(subject)
@subject = subject @subject = subject
if readonly_attributes.include?(@attribute) if readonly_attributes.include?(@attribute)
@negative_failure_message = "Did not expect #{@attribute} to be read-only" @failure_message_for_should_not = "Did not expect #{@attribute} to be read-only"
true true
else else
if readonly_attributes.empty? if readonly_attributes.empty?
@failure_message = "#{class_name} attribute #{@attribute} " << @failure_message_for_should = "#{class_name} attribute #{@attribute} " <<
'is not read-only' 'is not read-only'
else else
@failure_message = "#{class_name} is making " << @failure_message_for_should = "#{class_name} is making " <<
"#{readonly_attributes.to_a.to_sentence} " << "#{readonly_attributes.to_a.to_sentence} " <<
"read-only, but not #{@attribute}." "read-only, but not #{@attribute}."
end end

View file

@ -67,7 +67,7 @@ module Shoulda # :nodoc:
end end
end end
def failure_message def failure_message_for_should
if @options.key?(:expected_query_count) if @options.key?(:expected_query_count)
"Expected ##{@options[:method_name]} to cause #{@options[:expected_query_count]} database queries but it actually caused #{@queries.length} queries:" + friendly_queries "Expected ##{@options[:method_name]} to cause #{@options[:expected_query_count]} database queries but it actually caused #{@queries.length} queries:" + friendly_queries
else else
@ -75,7 +75,7 @@ module Shoulda # :nodoc:
end end
end end
def negative_failure_message def failure_message_for_should_not
if @options[:expected_query_count] if @options[:expected_query_count]
"Expected ##{@options[:method_name]} to not cause #{@options[:expected_query_count]} database queries but it actually caused #{@queries.length} queries:" + friendly_queries "Expected ##{@options[:method_name]} to not cause #{@options[:expected_query_count]} database queries but it actually caused #{@queries.length} queries:" + friendly_queries
else else

View file

@ -36,11 +36,11 @@ module Shoulda # :nodoc:
serialization_valid? && type_valid? serialization_valid? && type_valid?
end end
def failure_message def failure_message_for_should
"Expected #{expectation} (#{@missing})" "Expected #{expectation} (#{@missing})"
end end
def negative_failure_message def failure_message_for_should_not
"Did not expect #{expectation}" "Did not expect #{expectation}"
end end

View file

@ -70,7 +70,7 @@ module Shoulda # :nodoc:
self self
end end
def failure_message def failure_message_for_should
base = "Expected #{delegating_method_name} to delegate to #{target_method_name}" base = "Expected #{delegating_method_name} to delegate to #{target_method_name}"
add_clarifications_to(base) add_clarifications_to(base)
end end

View file

@ -12,7 +12,7 @@ describe Shoulda::Matchers::ActionController::AssignToMatcher do
matcher = assign_to(:var).with_kind_of(Fixnum) matcher = assign_to(:var).with_kind_of(Fixnum)
matcher.matches?(controller) matcher.matches?(controller)
matcher.failure_message.should =~ /but got wrong class \(WrongClass\)$/ matcher.failure_message_for_should.should =~ /but got wrong class \(WrongClass\)$/
end end
context 'a controller that assigns to an instance variable' do context 'a controller that assigns to an instance variable' do

View file

@ -13,7 +13,7 @@ describe Shoulda::Matchers::ActionController::FilterParamMatcher do
matcher.matches?(nil).should be_false matcher.matches?(nil).should be_false
matcher.failure_message.should =~ /Expected other to be filtered.*secret/ matcher.failure_message_for_should.should =~ /Expected other to be filtered.*secret/
end end
def filter(param) def filter(param)

View file

@ -120,7 +120,7 @@ describe Shoulda::Matchers::ActionMailer::HaveSentEmailMatcher do
should_not have_sent_email.multipart should_not have_sent_email.multipart
matcher = have_sent_email.multipart(true) matcher = have_sent_email.multipart(true)
matcher.matches?(Mailer.the_email(nil)) matcher.matches?(Mailer.the_email(nil))
matcher.failure_message.should =~ /Expected sent email being multipart/ matcher.failure_message_for_should.should =~ /Expected sent email being multipart/
end end
it 'matches the body with a regexp' do it 'matches the body with a regexp' do
@ -155,98 +155,98 @@ describe Shoulda::Matchers::ActionMailer::HaveSentEmailMatcher do
should have_sent_email.with_subject(/is spam$/) should have_sent_email.with_subject(/is spam$/)
matcher = have_sent_email.with_subject(/totally safe/) matcher = have_sent_email.with_subject(/totally safe/)
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email with subject/ matcher.failure_message_for_should.should =~ /Expected sent email with subject/
end end
it 'accepts sent e-mail based on a string sender' do it 'accepts sent e-mail based on a string sender' do
should have_sent_email.from('do-not-reply@example.com') should have_sent_email.from('do-not-reply@example.com')
matcher = have_sent_email.from('you@example.com') matcher = have_sent_email.from('you@example.com')
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email from/ matcher.failure_message_for_should.should =~ /Expected sent email from/
end end
it 'accepts sent e-mail based on a regexp sender' do it 'accepts sent e-mail based on a regexp sender' do
should have_sent_email.from(/@example\.com/) should have_sent_email.from(/@example\.com/)
matcher = have_sent_email.from(/you@/) matcher = have_sent_email.from(/you@/)
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email from/ matcher.failure_message_for_should.should =~ /Expected sent email from/
end end
it 'accepts sent e-mail based on the body' do it 'accepts sent e-mail based on the body' do
should have_sent_email.with_body(/is spam\./) should have_sent_email.with_body(/is spam\./)
matcher = have_sent_email.with_body(/totally safe/) matcher = have_sent_email.with_body(/totally safe/)
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email with body/ matcher.failure_message_for_should.should =~ /Expected sent email with body/
end end
it 'accepts sent e-mail based on a text/plain part' do it 'accepts sent e-mail based on a text/plain part' do
should have_sent_email.with_part('text/plain', /is spam\./) should have_sent_email.with_part('text/plain', /is spam\./)
matcher = have_sent_email.with_part('text/plain', /HTML is spam/) matcher = have_sent_email.with_part('text/plain', /HTML is spam/)
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email with a text\/plain part containing/ matcher.failure_message_for_should.should =~ /Expected sent email with a text\/plain part containing/
end end
it 'accepts sent e-mail based on a text/html part' do it 'accepts sent e-mail based on a text/html part' do
should have_sent_email.with_part('text/html', /HTML is spam/) should have_sent_email.with_part('text/html', /HTML is spam/)
matcher = have_sent_email.with_part('text/html', /HTML is not spam\./) matcher = have_sent_email.with_part('text/html', /HTML is not spam\./)
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email with a text\/html part containing/ matcher.failure_message_for_should.should =~ /Expected sent email with a text\/html part containing/
end end
it 'accept sent e-mail based on the recipient' do it 'accept sent e-mail based on the recipient' do
should have_sent_email.to('myself@me.com') should have_sent_email.to('myself@me.com')
matcher = have_sent_email.to('you@example.com') matcher = have_sent_email.to('you@example.com')
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email to/ matcher.failure_message_for_should.should =~ /Expected sent email to/
end end
it 'accepts sent e-mail based on cc string' do it 'accepts sent e-mail based on cc string' do
should have_sent_email.cc('joe@bob.com') should have_sent_email.cc('joe@bob.com')
matcher = have_sent_email.cc('you@example.com') matcher = have_sent_email.cc('you@example.com')
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email cc/ matcher.failure_message_for_should.should =~ /Expected sent email cc/
end end
it 'accepts sent-email based on cc regex' do it 'accepts sent-email based on cc regex' do
should have_sent_email.cc(/@bob\.com/) should have_sent_email.cc(/@bob\.com/)
matcher = have_sent_email.cc(/us@/) matcher = have_sent_email.cc(/us@/)
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email cc/ matcher.failure_message_for_should.should =~ /Expected sent email cc/
end end
it 'accepts sent e-mail based on cc list' do it 'accepts sent e-mail based on cc list' do
should have_sent_email.with_cc(['you@you.com', 'joe@bob.com']) should have_sent_email.with_cc(['you@you.com', 'joe@bob.com'])
matcher = have_sent_email.with_cc(['you@example.com']) matcher = have_sent_email.with_cc(['you@example.com'])
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email with cc/ matcher.failure_message_for_should.should =~ /Expected sent email with cc/
end end
it 'accepts sent e-mail based on bcc string' do it 'accepts sent e-mail based on bcc string' do
should have_sent_email.bcc('goodbye@hello.com') should have_sent_email.bcc('goodbye@hello.com')
matcher = have_sent_email.bcc('test@hello.com') matcher = have_sent_email.bcc('test@hello.com')
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email bcc/ matcher.failure_message_for_should.should =~ /Expected sent email bcc/
end end
it 'accepts sent e-mail based on bcc regex' do it 'accepts sent e-mail based on bcc regex' do
should have_sent_email.bcc(/@example\.com/) should have_sent_email.bcc(/@example\.com/)
matcher = have_sent_email.bcc(/you@/) matcher = have_sent_email.bcc(/you@/)
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email bcc/ matcher.failure_message_for_should.should =~ /Expected sent email bcc/
end end
it 'accepts sent e-mail based on bcc list' do it 'accepts sent e-mail based on bcc list' do
should have_sent_email.with_bcc(['sam@bob.com', 'test@example.com']) should have_sent_email.with_bcc(['sam@bob.com', 'test@example.com'])
matcher = have_sent_email.with_bcc(['you@you.com', 'joe@bob.com']) matcher = have_sent_email.with_bcc(['you@you.com', 'joe@bob.com'])
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email with bcc/ matcher.failure_message_for_should.should =~ /Expected sent email with bcc/
end end
it 'accepts sent-email when it is multipart' do it 'accepts sent-email when it is multipart' do
should have_sent_email.multipart should have_sent_email.multipart
matcher = have_sent_email.multipart(false) matcher = have_sent_email.multipart(false)
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Expected sent email not being multipart/ matcher.failure_message_for_should.should =~ /Expected sent email not being multipart/
end end
it 'lists all the deliveries within failure message' do it 'lists all the deliveries within failure message' do
@ -254,7 +254,7 @@ describe Shoulda::Matchers::ActionMailer::HaveSentEmailMatcher do
matcher = have_sent_email.to('you@example.com') matcher = have_sent_email.to('you@example.com')
matcher.matches?(nil) matcher.matches?(nil)
matcher.failure_message.should =~ /Deliveries:\n"This is spam" to \["myself@me\.com"\]\n"This is spam" to \["myself@me\.com"\]/ matcher.failure_message_for_should.should =~ /Deliveries:\n"This is spam" to \["myself@me\.com"\]\n"This is spam" to \["myself@me\.com"\]/
end end
it 'allows chaining' do it 'allows chaining' do

View file

@ -70,7 +70,7 @@ describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher do
matcher.matches?(no_protected_attributes).should be_true matcher.matches?(no_protected_attributes).should be_true
matcher.negative_failure_message.should_not be_nil matcher.failure_message_for_should_not.should_not be_nil
end end
end end

View file

@ -116,7 +116,7 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
matcher.matches?(validating_format(:with => /abc/, :strict => true)) matcher.matches?(validating_format(:with => /abc/, :strict => true))
matcher.negative_failure_message.should == 'Expected exception to include /abc/ ' + matcher.failure_message_for_should_not.should == 'Expected exception to include /abc/ ' +
'when attr is set to "xyz", got Attr is invalid' 'when attr is set to "xyz", got Attr is invalid'
end end
end end

View file

@ -22,13 +22,13 @@ describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher do
end end
it "delegates its failure message to its allow matcher's negative failure message" do it "delegates its failure message to its allow matcher's negative failure message" do
allow_matcher = stub_everything(:negative_failure_message => 'allow matcher failure') allow_matcher = stub_everything(:failure_message_for_should_not => 'allow matcher failure')
Shoulda::Matchers::ActiveModel::AllowValueMatcher.stubs(:new).returns(allow_matcher) Shoulda::Matchers::ActiveModel::AllowValueMatcher.stubs(:new).returns(allow_matcher)
matcher = matcher('abcde').for(:attr).with_message('good message') matcher = matcher('abcde').for(:attr).with_message('good message')
matcher.matches?(validating_format(:with => /abc/, :message => 'good message')) matcher.matches?(validating_format(:with => /abc/, :message => 'good message'))
matcher.failure_message.should == 'allow matcher failure' matcher.failure_message_for_should.should == 'allow matcher failure'
end end
it 'matches if the message is correct but the value is not' do it 'matches if the message is correct but the value is not' do

View file

@ -38,7 +38,7 @@ describe Shoulda::Matchers::ActiveModel::OnlyIntegerMatcher do
matcher.matches?(define_model(:example, :attr => :string).new) matcher.matches?(define_model(:example, :attr => :string).new)
matcher.failure_message.should include 'Expected errors to include "must be an integer"' matcher.failure_message_for_should.should include 'Expected errors to include "must be an integer"'
end end
end end

View file

@ -27,7 +27,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher do
the_matcher.matches?(define_model(:example, :attr => :string).new) the_matcher.matches?(define_model(:example, :attr => :string).new)
the_matcher.failure_message.should include 'Expected errors to include "must be an integer"' the_matcher.failure_message_for_should.should include 'Expected errors to include "must be an integer"'
end end
end end
@ -45,7 +45,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher do
the_matcher.matches?(validating_numericality) the_matcher.matches?(validating_numericality)
the_matcher.failure_message.should include 'Expected errors to include "must be an integer"' the_matcher.failure_message_for_should.should include 'Expected errors to include "must be an integer"'
end end
end end

View file

@ -10,7 +10,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
matcher.matches?(rejecting_children).should be_false matcher.matches?(rejecting_children).should be_false
matcher.failure_message.should == 'Expected Parent to accept nested attributes for children (is not declared)' matcher.failure_message_for_should.should == 'Expected Parent to accept nested attributes for children (is not declared)'
end end
context 'allow_destroy' do context 'allow_destroy' do
@ -31,7 +31,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
matching = accepting_children(:allow_destroy => true) matching = accepting_children(:allow_destroy => true)
matcher.allow_destroy(false).matches?(matching).should be_false matcher.allow_destroy(false).matches?(matching).should be_false
matcher.failure_message.should =~ /should not allow destroy/ matcher.failure_message_for_should.should =~ /should not allow destroy/
end end
it 'rejects an invalid falsey value' do it 'rejects an invalid falsey value' do
@ -39,7 +39,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
matching = accepting_children(:allow_destroy => false) matching = accepting_children(:allow_destroy => false)
matcher.allow_destroy(true).matches?(matching).should be_false matcher.allow_destroy(true).matches?(matching).should be_false
matcher.failure_message.should =~ /should allow destroy/ matcher.failure_message_for_should.should =~ /should allow destroy/
end end
end end
@ -53,7 +53,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
rejecting = accepting_children(:limit => 3) rejecting = accepting_children(:limit => 3)
matcher.limit(2).matches?(rejecting).should be_false matcher.limit(2).matches?(rejecting).should be_false
matcher.failure_message.should =~ /limit should be 2, got 3/ matcher.failure_message_for_should.should =~ /limit should be 2, got 3/
end end
end end
@ -73,7 +73,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
rejecting = accepting_children(:update_only => true) rejecting = accepting_children(:update_only => true)
matcher.matches?(rejecting).should be_false matcher.matches?(rejecting).should be_false
matcher.failure_message.should =~ /should not be update only/ matcher.failure_message_for_should.should =~ /should not be update only/
end end
it 'rejects an invalid falsey value' do it 'rejects an invalid falsey value' do
@ -81,7 +81,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
rejecting = accepting_children(:update_only => false) rejecting = accepting_children(:update_only => false)
matcher.matches?(rejecting).should be_false matcher.matches?(rejecting).should be_false
matcher.failure_message.should =~ /should be update only/ matcher.failure_message_for_should.should =~ /should be update only/
end end
end end

View file

@ -173,7 +173,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
matcher.matches?(having_many_children).should be_false matcher.matches?(having_many_children).should be_false
matcher.failure_message.should =~ /does not have any relationship to conceptions/ matcher.failure_message_for_should.should =~ /does not have any relationship to conceptions/
end end
it 'rejects an association that has the wrong :through option' do it 'rejects an association that has the wrong :through option' do
@ -190,7 +190,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
matcher = have_many(:children).through(:relationships) matcher = have_many(:children).through(:relationships)
matcher.matches?(Parent.new).should be_false matcher.matches?(Parent.new).should be_false
matcher.failure_message.should =~ /through relationships, but got it through conceptions/ matcher.failure_message_for_should.should =~ /through relationships, but got it through conceptions/
end end
it 'accepts an association with a valid :dependent option' do it 'accepts an association with a valid :dependent option' do

View file

@ -29,7 +29,7 @@ describe Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher do
matcher.matches?(model) matcher.matches?(model)
matcher.failure_message.should_not be_nil matcher.failure_message_for_should.should_not be_nil
end end
end end

View file

@ -15,7 +15,7 @@ describe Shoulda::Matchers::ActiveRecord::SerializeMatcher do
matcher.matches?(unserialized_model) matcher.matches?(unserialized_model)
matcher.failure_message.should =~ /to serialize the attribute called :attr/ matcher.failure_message_for_should.should =~ /to serialize the attribute called :attr/
end end
it 'assigns a helpful failure message when using #as' do it 'assigns a helpful failure message when using #as' do
@ -23,7 +23,7 @@ describe Shoulda::Matchers::ActiveRecord::SerializeMatcher do
matcher.matches?(unserialized_model) matcher.matches?(unserialized_model)
matcher.failure_message.should =~ /with a type of Hash/ matcher.failure_message_for_should.should =~ /with a type of Hash/
end end
it 'assigns a helpful failure message when using #as_instance_of' do it 'assigns a helpful failure message when using #as_instance_of' do
@ -31,7 +31,7 @@ describe Shoulda::Matchers::ActiveRecord::SerializeMatcher do
matcher.matches?(unserialized_model) matcher.matches?(unserialized_model)
matcher.failure_message.should =~ /with an instance of Hash/ matcher.failure_message_for_should.should =~ /with an instance of Hash/
end end
def unserialized_model def unserialized_model

View file

@ -79,7 +79,7 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
matcher.matches?(post_office) matcher.matches?(post_office)
message = 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman' message = 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman'
matcher.failure_message.should == message matcher.failure_message_for_should.should == message
end end
it 'uses the proper syntax for class methods in errors' do it 'uses the proper syntax for class methods in errors' do
@ -88,7 +88,7 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
matcher.matches?(PostOffice) matcher.matches?(PostOffice)
message = 'Expected PostOffice.deliver_mail to delegate to PostOffice.mailman' message = 'Expected PostOffice.deliver_mail to delegate to PostOffice.mailman'
matcher.failure_message.should == message matcher.failure_message_for_should.should == message
end end
end end
@ -143,7 +143,7 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
matcher.matches?(post_office) matcher.matches?(post_office)
message = 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman with arguments: ["123 Nowhere Ln."]' message = 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman with arguments: ["123 Nowhere Ln."]'
matcher.failure_message.should == message matcher.failure_message_for_should.should == message
end end
end end
end end
@ -183,7 +183,7 @@ describe Shoulda::Matchers::Independent::DelegateMatcher do
matcher.matches?(post_office) matcher.matches?(post_office)
message = 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman as #watch_tv' message = 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman as #watch_tv'
matcher.failure_message.should == message matcher.failure_message_for_should.should == message
end end
end end
end end