提交 ed88767d 编写于 作者: J Justin Collins

Add tests for expected number of warnings

上级 d238376d
......@@ -8,6 +8,7 @@ require 'set'
require 'test/unit'
require 'scanner'
#Helper methods for running scans
module BrakemanTester
class << self
#Set environment for scan
......@@ -56,6 +57,7 @@ module BrakemanTester
end
end
#Helpers for finding warnings in the report
module BrakemanTester::FindWarning
def assert_warning opts
warnings = find opts
......@@ -92,6 +94,22 @@ module BrakemanTester::FindWarning
end
end
#Check that the number of warnings reported are as expected.
#This is mainly to look for new warnings that are not being tested.
module BrakemanTester::CheckExpected
def test_number_of_warnings
expected.each do |type, number|
if type == :warning
warnings = report[:warnings]
else
warnings = report[(type.to_s << "_warnings").to_sym]
end
assert_equal number, warnings.length, "Expected #{number} #{type} warnings, but found #{warnings.length}"
end
end
end
Dir.glob "#{TEST_PATH}/tests/*.rb" do |file|
require file
end
......@@ -4,6 +4,15 @@ Rails2 = BrakemanTester.run_scan "rails2", "Rails 2"
class Rails2Tests < Test::Unit::TestCase
include BrakemanTester::FindWarning
include BrakemanTester::CheckExpected
def expected
@expected ||= {
:controller => 1,
:model => 2,
:template => 16,
:warning => 17 }
end
def report
Rails2
......
......@@ -4,11 +4,21 @@ Rails3 = BrakemanTester.run_scan "rails3", "Rails 3", :rails3 => true
class Rails3Tests < Test::Unit::TestCase
include BrakemanTester::FindWarning
include BrakemanTester::CheckExpected
def report
Rails3
end
def expected
@expected ||= {
:controller => 1,
:model => 4,
:template => 18,
:warning => 15
}
end
def test_no_errors
assert_equal 0, report[:errors].length
end
......
......@@ -4,11 +4,20 @@ Rails31 = BrakemanTester.run_scan "rails3.1", "Rails 3.1", :rails3 => true
class Rails31Tests < Test::Unit::TestCase
include BrakemanTester::FindWarning
include BrakemanTester::CheckExpected
def report
Rails31
end
def expected
@expected ||= {
:model => 0,
:template => 0,
:controller => 1,
:warning => 2 }
end
def test_without_protection
assert_warning :type => :warning,
:warning_type => "Mass Assignment",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册