Sha256: 85961096fd380c970c1a4c00d11c607f2400d3254aad069ce3beb3405c2863af

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

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

describe Advice::CommentAdvice do
  before do
    @class = Class.new(Warning) do
      include Advice::CommentAdvice

      def match?(body = self.body, settings={})
        body
      end
      remove_comments
    end
  end

  context '#remove_comments' do
    it 'Returns the empty string unmodified' do
      @class.new('(stdin)', '').match?('').should == ''
    end

    it 'Turns a comment into the empty string' do
      @class.new('(stdin)', '# hello').match?('# hello').should == ''
    end

    it 'strips the comments from the end of a string of code' do
      @class.new('(stdin)', 'a + b # adding').match?('a + b # adding').should == 'a + b'
    end

    SAMPLES = [['', ''], ['#hello', ''], [' # hello', ''],
               [' a + b # hello', ' a + b'], ['(a + b) #', '(a + b)'],
               ['"#" + number', '"#" + number'],
               ['" hello \\"mam\\"" # comment', '" hello \\"mam\\""']]
    SAMPLES.each do |input, output|
      it "should turn #{input} into #{output}" do
        @class.new('(stdin)', input).match?(input).should == output
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wool-0.5.1 spec/advice_specs/comment_advice_spec.rb