Sha256: 61e207afe1dee647fe347c09f18b509adb0a1179d7de021b0d38ece1ebc9e39d

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe InlineCommentSpaceWarning do
  SETTINGS = {InlineCommentSpaceWarning::OPTION_KEY => 2, :indent_size => 2}
  it 'is a line-based warning' do
    InlineCommentSpaceWarning.new('(stdin)', 'hello').should be_a(LineWarning)
  end

  it 'matches when there are less than 2 spaces between code and comment' do
    InlineCommentSpaceWarning.should warn('a + b#comment', SETTINGS)
    InlineCommentSpaceWarning.should warn('a + b # comment', SETTINGS)
    InlineCommentSpaceWarning.should_not warn('a + b  # comment', SETTINGS)
    InlineCommentSpaceWarning.should_not warn('a +b  # wool: ignore OperatorSpacing', SETTINGS)
  end

  it 'has an option to specify the necessary spacing' do
    InlineCommentSpaceWarning.options.size.should be > 0
    InlineCommentSpaceWarning.options[0].first.should ==
        InlineCommentSpaceWarning::OPTION_KEY
  end

  it 'respects the option for specifying the necessary spacing' do
    settings = {InlineCommentSpaceWarning::OPTION_KEY => 0}
    InlineCommentSpaceWarning.should warn('a + b # comment', settings)
    InlineCommentSpaceWarning.should_not warn('a + b# comment', settings)
  end

  it 'has a remotely useful description' do
    InlineCommentSpaceWarning.new('(stdin)', 'hello  #').desc.should =~ /inline.*comment/i
  end

  context 'when fixing' do
    before do
      @settings = {InlineCommentSpaceWarning::OPTION_KEY => 2}
    end

    after do
      InlineCommentSpaceWarning.should correct_to(@input, @output, @settings)
    end

    it 'adds spaces when necessary' do
      @input = 'a + b#comment'
      @output = 'a + b  #comment'
    end

    it 'removes spaces when necessary' do
      @input = 'a + b        #comment'
      @output = 'a + b  #comment'
    end

    it 'respects the option for spacing' do
      @settings = {InlineCommentSpaceWarning::OPTION_KEY => 0}
      @input = 'a + b        #comment'
      @output = 'a + b#comment'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wool-0.5.1 spec/warning_specs/comment_spacing_spec.rb