diff --git a/features/stdin.feature b/features/stdin.feature new file mode 100644 index 000000000..dcb095cbe --- /dev/null +++ b/features/stdin.feature @@ -0,0 +1,33 @@ +@stdin +Feature: Reek reads from $stdin when no files are given + In order to use reek with pipelines + As a developer + I want to pipe source code on stdin + + Scenario: return zero status with no smells + When I pass "def simple() @fred = 3 end" to reek + Then it succeeds + + Scenario: outputs nothing on empty stdin + When I pass "" to reek + Then it succeeds + And stdout equals "" + + Scenario: return non-zero status when there are smells + When I pass "def x() 3; end" to reek + Then it fails with exit status 2 + + Scenario: output nothing when no smells + When I pass "def simple() @fred = 3; end" to reek + Then it succeeds + And stdout equals "" + + Scenario: report smells correctly + When I pass "class Turn; def y() @x = 3; end end" to reek + Then it fails with exit status 2 + And it reports: + """ + Turn has the variable name '@x' (Uncommunicative Name) + Turn#y has the name 'y' (Uncommunicative Name) + + """ diff --git a/features/step_definitions/reek_steps.rb b/features/step_definitions/reek_steps.rb index cbdaf4243..6b05a178d 100644 --- a/features/step_definitions/reek_steps.rb +++ b/features/step_definitions/reek_steps.rb @@ -2,6 +2,14 @@ run args end +When /^I pass "([^\"]*)" to reek$/ do |stdin| + run_with_pipe stdin +end + +Then /^stdout equals "([^\"]*)"$/ do |report| + @last_stdout.should == report +end + Then /^it succeeds$/ do @last_exit_status.should == 0 end diff --git a/features/support/env.rb b/features/support/env.rb index 2915b4f63..315640238 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -15,6 +15,14 @@ def run(args) @last_exit_status = $?.exitstatus @last_stderr = IO.read(stderr_file.path) end + + def run_with_pipe(stdin) + stderr_file = Tempfile.new('cucumber') + stderr_file.close + @last_stdout = `echo \"#{stdin}\" | ruby -Ilib bin/reek 2> #{stderr_file.path}` + @last_exit_status = $?.exitstatus + @last_stderr = IO.read(stderr_file.path) + end end World do diff --git a/spec/slow/script_spec.rb b/spec/slow/script_spec.rb deleted file mode 100644 index c9d029059..000000000 --- a/spec/slow/script_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'reek' - -describe 'exit status', 'when reek is used correctly' do - it 'should return non-zero status when smells are reported' do - `echo "def x() 3; end" | ruby -Ilib bin/reek` - $?.exitstatus.should == 2 - end - - it 'should return zero status with no smells' do - `echo "def simple() @fred = 3 end" | ruby -Ilib bin/reek` - $?.exitstatus.should == 0 - end -end - -describe 'report format', 'with one source' do - it 'should output nothing with empty source' do - `echo "" | ruby -Ilib bin/reek`.should be_empty - end - - it 'should output nothing when no smells' do - `echo "def simple() @fred = 3; end" | ruby -Ilib bin/reek`.should be_empty - end - - it 'should not adorn the list of warnings' do - report = `echo "class Turn; def y() @x = 3; end end" | ruby -Ilib bin/reek` - report.split(/\n/).length.should == 2 - report.should_not match(/\n\n/) - end -end