Add tests for unless build.with?
This commit is contained in:
		
							parent
							
								
									f968776e84
								
							
						
					
					
						commit
						ec2b0df10e
					
				@ -281,12 +281,12 @@ module RuboCop
 | 
				
			|||||||
            problem "Use if #{correct} instead of unless #{m.source}"
 | 
					            problem "Use if #{correct} instead of unless #{m.source}"
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          # find_instance_method_call(body_node, :build, :with?) do |m|
 | 
					          find_instance_method_call(body_node, :build, :with?) do |m|
 | 
				
			||||||
          #   next unless unless_modifier?(m.parent)
 | 
					            next unless unless_modifier?(m.parent)
 | 
				
			||||||
          #   correct = m.source.gsub("?", "out?").gsub("unless", "if")
 | 
					            correct = m.source.gsub("?", "out?")
 | 
				
			||||||
          #   problem "Use #{correct} instead of unless #{m.source}"
 | 
					            problem "Use if #{correct} instead of unless #{m.source}"
 | 
				
			||||||
          # end
 | 
					          end
 | 
				
			||||||
          #
 | 
					
 | 
				
			||||||
          # find_instance_method_call(body_node, :build, :with?) do |m|
 | 
					          # find_instance_method_call(body_node, :build, :with?) do |m|
 | 
				
			||||||
          #   next unless negation?(m)
 | 
					          #   next unless negation?(m)
 | 
				
			||||||
          #   problem "Don't negate 'build.with?': use 'build.without?'"
 | 
					          #   problem "Don't negate 'build.with?': use 'build.without?'"
 | 
				
			||||||
 | 
				
			|||||||
@ -643,6 +643,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
 | 
				
			|||||||
        expect_offense(expected, actual)
 | 
					        expect_offense(expected, actual)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it "with unless build.with?" do
 | 
				
			||||||
 | 
					      source = <<-EOS.undent
 | 
				
			||||||
 | 
					        class Foo < Formula
 | 
				
			||||||
 | 
					          desc "foo"
 | 
				
			||||||
 | 
					          url 'http://example.com/foo-1.0.tgz'
 | 
				
			||||||
 | 
					          def post_install
 | 
				
			||||||
 | 
					            return unless build.with? "bar"
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      EOS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      expected_offenses = [{  message: 'Use if build.without? "bar" instead of unless build.with? "bar"',
 | 
				
			||||||
 | 
					                              severity: :convention,
 | 
				
			||||||
 | 
					                              line: 5,
 | 
				
			||||||
 | 
					                              column: 18,
 | 
				
			||||||
 | 
					                              source: source }]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      inspect_source(cop, source)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      expected_offenses.zip(cop.offenses).each do |expected, actual|
 | 
				
			||||||
 | 
					        expect_offense(expected, actual)
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  def expect_offense(expected, actual)
 | 
					  def expect_offense(expected, actual)
 | 
				
			||||||
    expect(actual.message).to eq(expected[:message])
 | 
					    expect(actual.message).to eq(expected[:message])
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user