Sha256: 6350b30744368d764e105964d99d569404228ec438ad800f6e2cd580461a6bf3

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require File.expand_path("spec_helper", __dir__)

module Danger
  describe Danger::DangerPhpmd do
    it "should be a plugin" do
      expect(Danger::DangerPhpmd.new(nil)).to be_a Danger::Plugin
    end

    describe "with Dangerfile" do
      before do
        @dangerfile = testing_dangerfile
        @my_plugin = @dangerfile.phpmd
      end

      context "with a file included no warnings" do
        before do
          allow(@my_plugin).to receive(:target_files).and_return(
            [File.expand_path("fixtures/no_warnings.php", __dir__)]
          )
        end

        it "warns nothing" do
          @my_plugin.run({ ruleset: "cleancode" })

          expect(@dangerfile.status_report[:warnings]).to eq([])
        end
      end

      context "with a file included some warnings" do
        let(:expected_message) { "The method bar uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them." }
        before do
          allow(@my_plugin).to receive(:target_files).and_return(
            [File.expand_path("fixtures/cleancode_warnings.php", __dir__)]
          )
        end

        it "warns nothing" do
          @my_plugin.run({ ruleset: "cleancode" })

          expect(@dangerfile.status_report[:warnings]).to eq([expected_message])

          violation_report = @dangerfile.violation_report[:warnings].first
          expect(violation_report.file).to eq("spec/fixtures/cleancode_warnings.php")
          expect(violation_report.line).to eq(7)
          expect(violation_report.message).to eq(expected_message)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
danger-phpmd-0.2.0 spec/phpmd_spec.rb
danger-phpmd-0.1.1 spec/phpmd_spec.rb
danger-phpmd-0.1.0 spec/phpmd_spec.rb