spec/lib/fasterer/file_traverser_spec.rb in fasterer-0.4.2 vs spec/lib/fasterer/file_traverser_spec.rb in fasterer-0.5.0
- old
+ new
@@ -332,6 +332,26 @@
it 'should have errors' do
expect(file_traverser.parse_error_paths)
.to match_array(['user.rb - RubyParser::SyntaxError - unterminated string meets end of file. near line 1: ""'])
end
end
+
+ describe 'output' do
+ let(:test_file_path) { RSpec.root.join('support', 'output', 'sample_code.rb') }
+ let(:analyzer) { Fasterer::Analyzer.new(test_file_path) }
+ let(:file_traverser) { Fasterer::FileTraverser.new('.') }
+
+ before do
+ analyzer.scan
+ end
+
+ context "when print offenses" do
+ let(:explanation) { Fasterer::Offense::EXPLANATIONS[:for_loop_vs_each] }
+
+ it 'should print offense' do
+ match = "\e[0;31;49m#{test_file_path}:1\e[0m #{explanation}.\n\n"
+
+ expect { file_traverser.send(:output, analyzer) }.to output(match).to_stdout
+ end
+ end
+ end
end