Sha256: 604b4302025485d443c79b7fc0be638babb378c2cf4586591d21582e15806a71

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

# 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(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

3 entries across 3 versions & 1 rubygems

Version Path
danger-wcc-0.0.4 spec/wcc/jshint_spec.rb
danger-wcc-0.0.3 spec/wcc/jshint_spec.rb
danger-wcc-0.0.2 spec/wcc/jshint_spec.rb