Skip to content

Commit

Permalink
Added more cucumber features for bad config files
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jun 26, 2009
1 parent 849485c commit 715bbbc
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 12 deletions.
2 changes: 2 additions & 0 deletions History.txt
Expand Up @@ -6,6 +6,8 @@
* LargeClass is disabled when checking in-memory classes (fixed #28)
* Output now reports on all files examined, even if they have no smells
* Smell warnings are indented in the report to distinguish them from file headers
* Now reports an error for corrupt config files
* Empty config files are ignored

== 1.1.3 2009-05-19

Expand Down
20 changes: 14 additions & 6 deletions bin/reek
Expand Up @@ -10,10 +10,18 @@ require 'reek'
require 'reek/source'
require 'reek/options'

exitstatus = 0
source = Reek::Options.parse(ARGV)
if source.smelly?
puts source.report
exitstatus = 2
def reek(args)
begin
source = Reek::Options.parse(args)
if source.smelly?
puts source.report
return 2
end
return 0
rescue RuntimeError => error
$stderr.puts "Error: #{error}"
return 1
end
end
exit(exitstatus)

exit reek(ARGV)
1 change: 1 addition & 0 deletions features/correct_smells.feature
@@ -1,3 +1,4 @@
@samples
Feature: Basic smell detection
In order to write better software
As a developer
Expand Down
12 changes: 11 additions & 1 deletion features/masking_smells.feature
@@ -1,9 +1,10 @@
@masking
Feature: Masking smells using config files
In order to keep my reports meaningful
As a developer
I want to mask some smells using config files

Scenario: empty config file has no effect
Scenario: empty config file is ignored
When I run reek spec/samples/empty_config_file/dirty.rb
Then it fails with exit status 2
And it reports:
Expand All @@ -18,6 +19,15 @@ Feature: Masking smells using config files
"""

Scenario: corrupt config file prevents normal output
When I run reek spec/samples/corrupt_config_file/dirty.rb
Then it fails with exit status 1
And it displays the error message:
"""
Error: invalid configuration file "corrupt.reek"
"""

Scenario: switch off one smell
When I run reek spec/samples/masked/dirty.rb
Then it fails with exit status 2
Expand Down
9 changes: 6 additions & 3 deletions features/step_definitions/reek_steps.rb
@@ -1,12 +1,15 @@
When /^I run reek (.*)$/ do |args|
@last_output = `ruby -Ilib bin/reek #{args}`
@last_exit_status = $?.exitstatus
run args
end

Then /^it fails with exit status (\d+)$/ do |status|
@last_exit_status.should == status.to_i
end

Then /^it reports:$/ do |report|
@last_output.should == report
@last_stdout.should == report
end

Then /^it displays the error message:$/ do |string|
@last_stderr.should == string
end
19 changes: 19 additions & 0 deletions features/support/env.rb
@@ -0,0 +1,19 @@
require 'rubygems'
require 'tempfile'
require 'spec/expectations'
require 'fileutils'

class CucumberWorld

def run(args)
stderr_file = Tempfile.new('cucumber')
stderr_file.close
@last_stdout = `ruby -Ilib bin/reek #{args} 2> #{stderr_file.path}`
@last_exit_status = $?.exitstatus
@last_stderr = IO.read(stderr_file.path)
end
end

World do
CucumberWorld.new
end
5 changes: 4 additions & 1 deletion lib/reek/sniffer.rb
Expand Up @@ -76,7 +76,10 @@ def configure_along_path(filename)
# +config_file+.
#
def configure_with(config_file)
YAML.load_file(config_file).push_keys(@config)
hash = YAML.load_file(config_file)
return unless hash
raise "invalid configuration file \"#{File.basename(config_file)}\"" unless Hash === hash
hash.push_keys(@config)
end

def disable(smell)
Expand Down
1 change: 1 addition & 0 deletions spec/samples/corrupt_config_file/corrupt.reek
@@ -0,0 +1 @@
This is not a config file
7 changes: 7 additions & 0 deletions spec/samples/corrupt_config_file/dirty.rb
@@ -0,0 +1,7 @@
class Dirty
def a
puts @s.title
@s.map {|x| x.each {|key| key += 3}}
puts @s.title
end
end
2 changes: 1 addition & 1 deletion spec/samples/empty_config_file/dirty.rb
Expand Up @@ -4,4 +4,4 @@ def a
@s.map {|x| x.each {|key| key += 3}}
puts @s.title
end
end
end

0 comments on commit 715bbbc

Please sign in to comment.