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

Done rewriting tests for belongs_to

This commit is contained in:
Elliot Winkler 2019-06-12 01:03:29 -06:00
parent b46db9a546
commit 46c049e98f
5 changed files with 2665 additions and 2313 deletions

View file

@ -93,6 +93,8 @@ Rails/Delegate:
Enabled: false Enabled: false
Rails/HttpPositionalArguments: Rails/HttpPositionalArguments:
Enabled: false Enabled: false
Rails/SkipsModelValidations:
Enabled: false
Style/Alias: Style/Alias:
Enabled: false Enabled: false
Style/ArrayJoin: Style/ArrayJoin:

View file

@ -95,6 +95,10 @@ module Shoulda
end end
end end
end end
def self.unwrap(message)
message.tr("\n", ' ').squeeze(' ')
end
end end
end end
end end

View file

@ -16,29 +16,15 @@ module UnitTests
@should_be_negated = nil @should_be_negated = nil
end end
def and_fail_with(message, wrap: false) def and_fail_with(message, wrap: false, unwrap: false)
@expected_message = @expected_message = format_message(message, wrap: wrap, unwrap: unwrap)
if wrap
Shoulda::Matchers.word_wrap(message.strip_heredoc.strip)
else
message.strip_heredoc.strip
end
@should_be_negated = true @should_be_negated = true
self self
end end
def or_fail_with(message, wrap: false) def or_fail_with(message, wrap: false, unwrap: false)
@expected_message = @expected_message = format_message(message, wrap: wrap, unwrap: unwrap)
if wrap
Shoulda::Matchers.word_wrap(message.strip_heredoc.strip)
else
message.strip_heredoc.strip
end
@should_be_negated = false @should_be_negated = false
self self
end end
@ -80,9 +66,11 @@ Expected the matcher to match in the positive, but it failed with this message:
if matcher_fails_in_positive? if matcher_fails_in_positive?
if ( if (
negative_matcher.respond_to?(:does_not_match?) && !negative_matcher.respond_to?(:does_not_match?) ||
!negative_matcher.does_not_match?(object) negative_matcher.does_not_match?(object)
) )
true
else
@failure_message_when_negated = <<-MESSAGE @failure_message_when_negated = <<-MESSAGE
Expected the matcher to match in the negative, but it failed with this message: Expected the matcher to match in the negative, but it failed with this message:
@ -91,8 +79,6 @@ Expected the matcher to match in the negative, but it failed with this message:
#{DIVIDER} #{DIVIDER}
MESSAGE MESSAGE
false false
else
true
end end
end end
end end
@ -211,6 +197,18 @@ Diff:
def differ def differ
@_differ ||= RSpec::Support::Differ.new @_differ ||= RSpec::Support::Differ.new
end end
def format_message(message, wrap:, unwrap:)
stripped_message = message.strip_heredoc.strip
if wrap
Shoulda::Matchers.word_wrap(stripped_message)
elsif unwrap
Shoulda::Matchers::Util.unwrap(stripped_message)
else
stripped_message
end
end
end end
end end
end end

File diff suppressed because it is too large Load diff