add test for inspecting version
This commit is contained in:
		
							parent
							
								
									cfc423e183
								
							
						
					
					
						commit
						5744cd9066
					
				@ -157,11 +157,11 @@ module RuboCop
 | 
			
		||||
            problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
          # find_instance_method_call(body_node, :version, :==) do |m|
 | 
			
		||||
          #   next unless parameters_passed?(m, "HEAD")
 | 
			
		||||
          #   problem "Use 'build.head?' instead of inspecting 'version'"
 | 
			
		||||
          # end
 | 
			
		||||
          #
 | 
			
		||||
          find_instance_method_call(body_node, :version, :==) do |m|
 | 
			
		||||
            next unless parameters_passed?(m, "HEAD")
 | 
			
		||||
            problem "Use 'build.head?' instead of inspecting 'version'"
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
          # find_instance_method_call(body_node, :ENV, :fortran) do
 | 
			
		||||
          #   next if depends_on?(:fortran)
 | 
			
		||||
          #   problem "Use `depends_on :fortran` instead of `ENV.fortran`"
 | 
			
		||||
 | 
			
		||||
@ -1117,6 +1117,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "with inspecting version" do
 | 
			
		||||
      source = <<-EOS.undent
 | 
			
		||||
        class Foo < Formula
 | 
			
		||||
          desc "foo"
 | 
			
		||||
          url 'http://example.com/foo-1.0.tgz'
 | 
			
		||||
          if version == "HEAD"
 | 
			
		||||
            foo()
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      EOS
 | 
			
		||||
 | 
			
		||||
      expected_offenses = [{  message: "Use 'build.head?' instead of inspecting 'version'",
 | 
			
		||||
                              severity: :convention,
 | 
			
		||||
                              line: 4,
 | 
			
		||||
                              column: 5,
 | 
			
		||||
                              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