2017-11-01 12:42:58 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
2017-11-07 21:50:25 +00:00
|
|
|
module Ameba::Rule
|
2017-11-01 12:42:58 +00:00
|
|
|
subject = DebuggerStatement.new
|
|
|
|
|
|
|
|
describe DebuggerStatement do
|
|
|
|
it "passes if there is no debugger statement" do
|
|
|
|
s = Source.new %(
|
|
|
|
"this is not a debugger statement"
|
|
|
|
s = "debugger"
|
|
|
|
|
|
|
|
def debugger(program)
|
|
|
|
end
|
|
|
|
debugger ""
|
|
|
|
|
|
|
|
class A
|
|
|
|
def debugger
|
|
|
|
end
|
|
|
|
end
|
|
|
|
A.new.debugger
|
|
|
|
)
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(s).should be_valid
|
2017-11-01 12:42:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is a debugger statement" do
|
|
|
|
s = Source.new %(
|
|
|
|
a = 2
|
|
|
|
debugger
|
|
|
|
a = a + 1
|
|
|
|
)
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(s).should_not be_valid
|
2017-11-01 12:42:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, pos and message" do
|
2017-11-07 20:02:51 +00:00
|
|
|
s = Source.new "debugger", "source.cr"
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(s).should_not be_valid
|
2017-11-01 12:42:58 +00:00
|
|
|
|
|
|
|
error = s.errors.first
|
|
|
|
error.rule.should_not be_nil
|
2017-11-07 20:02:51 +00:00
|
|
|
error.location.to_s.should eq "source.cr:1:1"
|
2017-11-01 12:42:58 +00:00
|
|
|
error.message.should eq "Possible forgotten debugger statement detected"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|