Skip to content

Commit

Permalink
Inline unhappy check.
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviershay committed Aug 25, 2012
1 parent 83e691b commit a8975f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
49 changes: 38 additions & 11 deletions spec/cane_spec.rb
Expand Up @@ -172,17 +172,44 @@ def complex_method(a)
exitstatus.should == 1
end

it 'allows custom checks' do
fn = make_file(":(")

out, exitstatus = run(%(
-r unhappy.rb
--check UnhappyCheck
--unhappy-file #{fn}
))
out.should include("Files are unhappy")
out.should include(fn)
exitstatus.should == 1
describe 'user-defined checks' do
let(:class_name) { "C#{rand(10 ** 10)}" }

it 'allows custom checks' do
fn = make_file(":(")
check_file = make_file <<-RUBY
class #{class_name} < Struct.new(:opts)
def self.options
{
unhappy_file: ["File to check", default: [nil]]
}
end
def violations
[
description: "Files are unhappy",
file: opts.fetch(:unhappy_file),
label: ":("
]
end
end
RUBY

out, exitstatus = run(%(
-r #{check_file}
--check #{class_name}
--unhappy-file #{fn}
))
out.should include("Files are unhappy")
out.should include(fn)
exitstatus.should == 1
end

after do
if Object.const_defined?(class_name)
Object.send(:remove_const, class_name)
end
end
end

it 'works with rake' do
Expand Down
22 changes: 0 additions & 22 deletions spec/unhappy.rb

This file was deleted.

0 comments on commit a8975f5

Please sign in to comment.