add test for build.include? having dashed args
This commit is contained in:
		
							parent
							
								
									3ff8be1216
								
							
						
					
					
						commit
						dc4d10ff6a
					
				@ -314,12 +314,12 @@ module RuboCop
 | 
			
		||||
            next unless match = regex_match_group(arg, %r{with(out)?-(.*)})
 | 
			
		||||
            problem "Use build.with#{match[1]}? \"#{match[2]}\" instead of build.include? 'with#{match[1]}-#{match[2]}'"
 | 
			
		||||
          end
 | 
			
		||||
          #
 | 
			
		||||
          # find_instance_method_call(body_node, :build, :include?) do |m|
 | 
			
		||||
          #   arg = parameters(m).first
 | 
			
		||||
          #   next unless match = regex_match_group(arg, %r{\-\-(.*)})
 | 
			
		||||
          #   problem "Reference '#{match[1]}' without dashes"
 | 
			
		||||
          # end
 | 
			
		||||
 | 
			
		||||
          find_instance_method_call(body_node, :build, :include?) do |m|
 | 
			
		||||
            arg = parameters(m).first
 | 
			
		||||
            next unless match = regex_match_group(arg, %r{\-\-(.*)})
 | 
			
		||||
            problem "Reference '#{match[1]}' without dashes"
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -787,6 +787,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
 | 
			
		||||
        expect_offense(expected, actual)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "with build.include? with dashed args" do
 | 
			
		||||
      source = <<-EOS.undent
 | 
			
		||||
        class Foo < Formula
 | 
			
		||||
          desc "foo"
 | 
			
		||||
          url 'http://example.com/foo-1.0.tgz'
 | 
			
		||||
          def post_install
 | 
			
		||||
            return if build.include? "--bar"
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      EOS
 | 
			
		||||
 | 
			
		||||
      expected_offenses = [{  message: "Reference 'bar' without dashes",
 | 
			
		||||
                              severity: :convention,
 | 
			
		||||
                              line: 5,
 | 
			
		||||
                              column: 30,
 | 
			
		||||
                              source: source }]
 | 
			
		||||
 | 
			
		||||
      inspect_source(cop, source)
 | 
			
		||||
 | 
			
		||||
      expected_offenses.zip(cop.offenses).each do |expected, actual|
 | 
			
		||||
        expect_offense(expected, actual)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  def expect_offense(expected, actual)
 | 
			
		||||
    expect(actual.message).to eq(expected[:message])
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user