Sha256: dcdb1a23fb9ff98368e27ca14c3924e6dab0e5ef3b0fbef8b7b2131624acb1c2

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'
require 'plugins/pre_commit/checks/checkstyle'

describe PreCommit::Checks::Checkstyle do
  let(:config) {double(PreCommit::Configuration, get: '')}
  let(:check) {PreCommit::Checks::Checkstyle.new(nil, config, [])}

  it "succeds if nothing changed" do
    expect(check.call([])).to be_nil
  end

  it "succeeds for good code" do
    files = [fixture_file('good.java')]
    expect(check.call(files)).to be_nil
  end

  it "should fail for bad formatted code" do
    file = fixture_file("bad.java")

    result = check.call([file])
    
    expect(result).to include "File errors: #{file}"
    expect(result).to include "line: 1: error:"
    expect(result).to include "line: 1:1 error:"
    expect(result).to include "line: 2:3 error:"
    expect(result).to include "line: 2:27 error:"
  end


  it "should accept multiple fails" do
    # given
    file = fixture_file("bad.java")
    file2 = fixture_file("bad2.java")
    
    # when 
    result = check.call([file, file2]) 
    
    # then
    expect(result).to include "File errors: #{file}"
    expect(result).to include "File errors: #{file2}"
  end

  it "should accept custom checkstyle" do
    # given
    files = [fixture_file('good.java')]
    custom_config = double(PreCommit::Configuration,
                           get: fixture_file('google_checks.xml'))
    # when
    check.config = custom_config
    # then
    expect(check.call(files)).to be_nil
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
java-checkstyle-0.0.2 spec/plugins/pre_commit/checks/checkstyle_spec.rb