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:
		
							parent
							
								
									b46db9a546
								
							
						
					
					
						commit
						46c049e98f
					
				
					 5 changed files with 2665 additions and 2313 deletions
				
			
		| 
						 | 
				
			
			@ -93,6 +93,8 @@ Rails/Delegate:
 | 
			
		|||
  Enabled: false
 | 
			
		||||
Rails/HttpPositionalArguments:
 | 
			
		||||
  Enabled: false
 | 
			
		||||
Rails/SkipsModelValidations:
 | 
			
		||||
  Enabled: false
 | 
			
		||||
Style/Alias:
 | 
			
		||||
  Enabled: false
 | 
			
		||||
Style/ArrayJoin:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -95,6 +95,10 @@ module Shoulda
 | 
			
		|||
          end
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      def self.unwrap(message)
 | 
			
		||||
        message.tr("\n", ' ').squeeze(' ')
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,29 +16,15 @@ module UnitTests
 | 
			
		|||
        @should_be_negated = nil
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      def and_fail_with(message, wrap: false)
 | 
			
		||||
        @expected_message =
 | 
			
		||||
          if wrap
 | 
			
		||||
            Shoulda::Matchers.word_wrap(message.strip_heredoc.strip)
 | 
			
		||||
          else
 | 
			
		||||
            message.strip_heredoc.strip
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
      def and_fail_with(message, wrap: false, unwrap: false)
 | 
			
		||||
        @expected_message = format_message(message, wrap: wrap, unwrap: unwrap)
 | 
			
		||||
        @should_be_negated = true
 | 
			
		||||
 | 
			
		||||
        self
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      def or_fail_with(message, wrap: false)
 | 
			
		||||
        @expected_message =
 | 
			
		||||
          if wrap
 | 
			
		||||
            Shoulda::Matchers.word_wrap(message.strip_heredoc.strip)
 | 
			
		||||
          else
 | 
			
		||||
            message.strip_heredoc.strip
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
      def or_fail_with(message, wrap: false, unwrap: false)
 | 
			
		||||
        @expected_message = format_message(message, wrap: wrap, unwrap: unwrap)
 | 
			
		||||
        @should_be_negated = false
 | 
			
		||||
 | 
			
		||||
        self
 | 
			
		||||
      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 (
 | 
			
		||||
            negative_matcher.respond_to?(:does_not_match?) &&
 | 
			
		||||
            !negative_matcher.does_not_match?(object)
 | 
			
		||||
            !negative_matcher.respond_to?(:does_not_match?) ||
 | 
			
		||||
            negative_matcher.does_not_match?(object)
 | 
			
		||||
          )
 | 
			
		||||
            true
 | 
			
		||||
          else
 | 
			
		||||
            @failure_message_when_negated = <<-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}
 | 
			
		||||
            MESSAGE
 | 
			
		||||
            false
 | 
			
		||||
          else
 | 
			
		||||
            true
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -211,6 +197,18 @@ Diff:
 | 
			
		|||
      def differ
 | 
			
		||||
        @_differ ||= RSpec::Support::Differ.new
 | 
			
		||||
      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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										1708
									
								
								spec/unit/shoulda/matchers/active_record/belong_to_spec.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1708
									
								
								spec/unit/shoulda/matchers/active_record/belong_to_spec.rb
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue