Sha256: 9e028ed1c10eb472c3bbda5abf20e98af10e6735b8c017bc230567275b814a84

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

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

require 'json'
require 'stringio'

RSpec.describe Reek::Report::CodeClimateReport 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 an empty string' 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
      expected = <<~HERE.delete("\n")
        {"type":"issue",
        "check_name":"UncommunicativeParameterName",
        "description":"simple has the parameter name 'a'",
        "categories":["Complexity"],
        "location":{"path":"string","lines":{"begin":1,"end":1}},
        "remediation_points":150000,
        "content":{"body":"An `Uncommunicative Parameter Name` is a parameter name that
         doesn't communicate its intent well enough.\\n\\nPoor names make it hard for the reader
         to build a mental picture of what's going on in the code. They can also be
         mis-interpreted; and they hurt the flow of reading, because the reader must slow down
         to interpret the names.\\n"},
        "fingerprint":"09970037d92b5a628bf682a3e2bb126d"}\u0000
        {"type":"issue",
        "check_name":"UtilityFunction",
        "description":"simple doesn't depend on instance state (maybe move it to another class?)",
        "categories":["Complexity"],
        "location":{"path":"string","lines":{"begin":1,"end":1}},
        "remediation_points":250000,
        "content":{"body":"A _Utility Function_ is any instance method that has no
         dependency on the state of the instance.\\n"},
        "fingerprint":"db456db7cb344bb5a98b8fc54a2f382e"}\u0000
      HERE

      expect { instance.show }.to output(expected).to_stdout
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reek-6.0.3 spec/reek/report/code_climate/code_climate_report_spec.rb
reek-6.0.2 spec/reek/report/code_climate/code_climate_report_spec.rb
reek-6.0.1 spec/reek/report/code_climate/code_climate_report_spec.rb
reek-6.0.0 spec/reek/report/code_climate/code_climate_report_spec.rb
reek-5.6.0 spec/reek/report/code_climate/code_climate_report_spec.rb