spec/reek/report/yaml_report_spec.rb in reek-3.3.1 vs spec/reek/report/yaml_report_spec.rb in reek-3.4.0
- old
+ new
@@ -1,20 +1,90 @@
require_relative '../../spec_helper'
require_relative '../../../lib/reek/examiner'
require_relative '../../../lib/reek/report/report'
require_relative '../../../lib/reek/report/formatter'
+require 'yaml'
+require 'stringio'
+
RSpec.describe Reek::Report::YAMLReport do
- let(:instance) { Reek::Report::YAMLReport.new }
+ let(:options) { {} }
+ let(:instance) { Reek::Report::YAMLReport.new(options) }
+ let(:examiner) { Reek::Examiner.new(source) }
- context 'empty source' do
- let(:examiner) { Reek::Examiner.new('') }
+ before do
+ instance.add_examiner examiner
+ end
- before do
- instance.add_examiner examiner
- end
+ context 'with empty source' do
+ let(:source) { '' }
it 'prints empty yaml' do
expect { instance.show }.to output(/^--- \[\]\n.*$/).to_stdout
+ end
+ end
+
+ context 'with smelly source' do
+ let(:source) { 'def simple(a) a[3] end' }
+
+ it 'prints smells as yaml' do
+ out = StringIO.new
+ instance.show(out)
+ out.rewind
+ result = YAML.load(out.read)
+ expected = YAML.load <<-EOS
+---
+- context: "simple"
+ lines:
+ - 1
+ message: "doesn't depend on instance state (maybe move it to another class?)"
+ smell_category: "LowCohesion"
+ smell_type: "UtilityFunction"
+ source: "string"
+ name: "simple"
+- context: "simple"
+ lines:
+ - 1
+ message: "has the parameter name 'a'"
+ smell_category: "UncommunicativeName"
+ smell_type: "UncommunicativeParameterName"
+ source: "string"
+ name: "a"
+ EOS
+
+ expect(result).to eq expected
+ end
+ context 'with link formatter' do
+ let(:options) { { warning_formatter: Reek::Report::WikiLinkWarningFormatter.new } }
+
+ it 'prints documentation links' do
+ out = StringIO.new
+ instance.show(out)
+ out.rewind
+ result = YAML.load(out.read)
+ expected = YAML.load <<-EOS
+---
+- context: "simple"
+ lines:
+ - 1
+ message: "doesn't depend on instance state (maybe move it to another class?)"
+ smell_category: "LowCohesion"
+ smell_type: "UtilityFunction"
+ source: "string"
+ name: "simple"
+ wiki_link: "https://github.com/troessner/reek/blob/master/docs/Utility-Function.md"
+- context: "simple"
+ lines:
+ - 1
+ message: "has the parameter name 'a'"
+ smell_category: "UncommunicativeName"
+ smell_type: "UncommunicativeParameterName"
+ source: "string"
+ name: "a"
+ wiki_link: "https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Parameter-Name.md"
+ EOS
+
+ expect(result).to eq expected
+ end
end
end
end