Sha256: 63a6a0584a0725d848cdd8501d3e17ff586c42c754b718cd51bcaf2e7c8a81ba

Contents?: true

Size: 1.93 KB

Versions: 7

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

require File.expand_path('../spec_helper', __dir__)

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(subject).to receive(:run)
        .with(/npm/)
        .and_return('')
      allow(subject).to receive(:run_and_diff)
        .and_return(load_fixture('jshint/jshint.diff'))
      allow(subject).to receive(:run)
        .with(/\/tmp\/.+\/jshint/)
        .and_return(load_fixture('jshint/out.jshint'))
      allow(Dir).to receive(:exist?)
        .with('app/assets/javascripts')
        .and_return(true)
    end

    describe 'jshint' do
      let(:subject) { Danger::DangerWCC::Jshint.new(@my_plugin) }

      after do
        File.delete('.jshint') if File.file?('.jshint')
      end

      it 'runs jshint and parses diff' do
        # act
        subject.perform

        # assert
        warnings = @dangerfile.violation_report[:warnings]
        expect(warnings.length).to eq(2)

        expect(warnings[0].message)
          .to eq("Misleading line break before '+'; readers may interpret this"\
          ' as an expression boundary.')
        expect(warnings[0].file).to eq('app/assets/javascripts/comment.js')
        expect(warnings[0].line).to eq(42)

        expect(warnings.last.message)
          .to eq("['AM'] is better written in dot notation.")
        expect(warnings.last.file).to eq('app/assets/javascripts/mobiscroll.js')
        expect(warnings.last.line).to eq(3)
      end

      it 'writes .jshint only if .jshint doesnt exist' do
        begin
          File.write('.jshint', '{}')

          subject.perform

          expect(File.read('.jshint')).to eq('{}')
        ensure
          File.delete('.jshint')
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
danger-wcc-0.1.4 spec/wcc/jshint_spec.rb
danger-wcc-0.1.3 spec/wcc/jshint_spec.rb
danger-wcc-0.1.2 spec/wcc/jshint_spec.rb
danger-wcc-0.1.1 spec/wcc/jshint_spec.rb
danger-wcc-0.1.0 spec/wcc/jshint_spec.rb
danger-wcc-0.0.6 spec/wcc/jshint_spec.rb
danger-wcc-0.0.5 spec/wcc/jshint_spec.rb