# frozen_string_literal: true require File.expand_path('../../spec_helper', __FILE__) module Danger describe Danger::DangerWCC do before do @dangerfile = testing_dangerfile @my_plugin = @dangerfile.wcc @git = @dangerfile.git @github = @dangerfile.github allow(@github).to receive(:pr_json) .and_return(JSON.parse(load_fixture('github_pr.json'))) allow(@github).to receive(:html_link) do |text| "#{text}" end end describe 'reek' do let(:subject) { Danger::DangerWCC::Reek.new(@my_plugin) } after do File.delete('defaults.reek') if File.file?('defaults.reek') end it 'runs reek and parses diff' do allow(subject).to receive(:run_and_diff) .and_return(load_fixture('reek/reek.diff')) allow(subject).to receive(:run) .with(/^bundle exec reek/) .and_return(load_fixture('reek/line_numbers.reek')) # act subject.perform # expect warnings = @dangerfile.violation_report[:warnings] expect(warnings.length).to eq(6) expect(warnings[0].message) .to eq('TooManyStatements: Danger::DangerWCC#reek has approx 7 '\ 'statements [https://github.com/troessner/reek/blob/master/docs/'\ 'Too-Many-Statements.md](https://github.com/troessner/reek/blob/'\ 'master/docs/Too-Many-Statements.md)') expect(warnings[0].file).to eq('lib/wcc/plugin.rb') expect(warnings[0].line).to eq(53) expect(warnings.last.message) .to eq('IrresponsibleModule: Danger has no descriptive comment '\ '[https://github.com/troessner/reek/blob/master/docs/'\ 'Irresponsible-Module.md](https://github.com/troessner/reek/blob/'\ 'master/docs/Irresponsible-Module.md)') expect(warnings.last.file).to eq('spec/wcc/plugin_spec.rb') expect(warnings.last.line).to eq(5) end it 'writes defaults.reek only if .reek doesnt exist' do begin File.write('.reek', '') subject.perform expect(File.file?('defaults.reek')).to be false ensure File.delete('.reek') end end end end end