Skip to content

Commit

Permalink
Push down acceptance tests to lower levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviershay committed Aug 26, 2012
1 parent cf35313 commit 066a2f6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 53 deletions.
59 changes: 6 additions & 53 deletions spec/cane_spec.rb
Expand Up @@ -22,8 +22,8 @@ def run(cli_args)
[output, result ? 0 : 1]
end

it 'fails if ABC metric does not meet requirements' do
file_name = make_file(<<-RUBY)
it 'returns a non-zero exit code and a details of checks that failed' do
fn = make_file(<<-RUBY + " ")
class Harness
def complex_method(a)
if a < 2
Expand All @@ -35,59 +35,12 @@ def complex_method(a)
end
RUBY

_, exitstatus = run("--abc-glob #{file_name} --abc-max 1")

exitstatus.should == 1
end

it 'fails if style metrics do not meet requirements' do
file_name = make_file("whitespace ")

output, exitstatus = run("--style-glob #{file_name}")
output, exitstatus =
run("--style-glob #{fn} --doc-glob #{fn} --abc-glob #{fn} --abc-max 1")
output.should include("Lines violated style requirements")
exitstatus.should == 1
end

it 'allows upper bound of failed checks' do
file_name = make_file("whitespace ")

output, exitstatus = run("--style-glob #{file_name} --max-violations 1")
exitstatus.should == 0
output.should include("Lines violated style requirements")
end

it 'allows checking of a value in a file' do
file_name = make_file("89")

output, exitstatus = run("--gte #{file_name},90")
output.should include("Quality threshold crossed")
exitstatus.should == 1
end

it 'allows checking of class documentation' do
file_name = make_file("class NoDoc")

output, exitstatus = run("--doc-glob #{file_name}")
exitstatus.should == 1
output.should include("Classes are not documented")
end

context 'with a .cane file' do
before(:each) do
file_name = make_file("class NoDoc")
make_dot_cane("--doc-glob #{file_name}")
end

after(:each) do
unmake_dot_cane
end

it 'loads options from a .cane file' do
output, exitstatus = run('')

exitstatus.should == 1
output.should include("Classes are not documented")
end
output.should include("Methods exceeded maximum allowed ABC complexity")
exitstatus.should == 1
end

it 'handles invalid unicode input' do
Expand Down
28 changes: 28 additions & 0 deletions spec/parser_spec.rb
Expand Up @@ -17,6 +17,16 @@ def run(cli_args)
result[:style_measure].should == 3
end

it 'allows checking of a value in a file' do
output, result = run("--gte myfile,90")
result[:gte].should == [['myfile', '90']]
end

it 'allows upper bound of failed checks' do
output, result = run("--max-violations 1")
result[:max_violations].should == 1
end

it 'displays a help message' do
output, result = run("--help")

Expand Down Expand Up @@ -58,4 +68,22 @@ def run(cli_args)
result[:no_doc].should_not be
end
end

it 'loads default options from .cane file' do
defaults = <<-EOS
--no-doc
--abc-glob myfile
--style-glob myfile
EOS
file = double("Cane::File")
stub_const("Cane::File", file)
file.should_receive(:exists?).with('./.cane').and_return(true)
file.should_receive(:contents).with('./.cane').and_return(defaults)

_, result = run("--style-glob myotherfile")

result[:no_doc].should be
result[:abc_glob].should == 'myfile'
result[:style_glob].should == 'myotherfile'
end
end
12 changes: 12 additions & 0 deletions spec/runner_spec.rb
@@ -0,0 +1,12 @@
require 'spec_helper'

require 'cane'

describe Cane::Runner do
describe '#run' do
it 'returns true iff fewer violations than max allowed' do
described_class.new(checks: [], max_violations: 0).run.should be
described_class.new(checks: [], max_violations: -1).run.should_not be
end
end
end

0 comments on commit 066a2f6

Please sign in to comment.