Sha256: 25ee8274c33c6dfdc7a8eeface9048155a15b9e1e6e3bc142e56c0f10869f19e

Contents?: true

Size: 1.71 KB

Versions: 11

Compression:

Stored size: 1.71 KB

Contents

require_relative '../../spec_helper'
require_lib 'reek/examiner'
require_lib 'reek/report/json_report'

require 'json'
require 'stringio'

RSpec.describe Reek::Report::JSONReport do
  let(:options) { {} }
  let(:instance) { described_class.new(options) }
  let(:examiner) { Reek::Examiner.new(source) }

  before do
    instance.add_examiner examiner
  end

  context 'with empty source' do
    let(:source) { '' }

    it 'prints empty json' do
      expect { instance.show }.to output(/^\[\]$/).to_stdout
    end
  end

  context 'with smelly source' do
    let(:source) { 'def simple(a) a[3] end' }

    it 'prints smells as json' do
      out = StringIO.new
      instance.show(out)
      out.rewind
      result = JSON.parse(out.read)
      expected = JSON.parse <<-EOS
        [
          {
            "context":            "simple",
            "lines":              [1],
            "message":            "has the parameter name 'a'",
            "smell_type":         "UncommunicativeParameterName",
            "source":             "string",
            "name":               "a",
            "documentation_link": "https://github.com/troessner/reek/blob/v#{Reek::Version::STRING}/docs/Uncommunicative-Parameter-Name.md"
          },
          {
            "context":            "simple",
            "lines":              [1],
            "message":            "doesn't depend on instance state (maybe move it to another class?)",
            "smell_type":         "UtilityFunction",
            "source":             "string",
            "documentation_link": "https://github.com/troessner/reek/blob/v#{Reek::Version::STRING}/docs/Utility-Function.md"
          }
        ]
      EOS

      expect(result).to eq expected
    end
  end
end

Version data entries

11 entries across 9 versions & 2 rubygems

Version Path
reek-5.3.1 spec/reek/report/json_report_spec.rb
reek-5.3.0 spec/reek/report/json_report_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/report/json_report_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/report/json_report_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/report/json_report_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/report/json_report_spec.rb
reek-5.2.0 spec/reek/report/json_report_spec.rb
reek-5.1.0 spec/reek/report/json_report_spec.rb
reek-5.0.2 spec/reek/report/json_report_spec.rb
reek-5.0.1 spec/reek/report/json_report_spec.rb
reek-5.0.0 spec/reek/report/json_report_spec.rb