Sha256: b7a5d6d681d8b805d72fcc2f790e7360d5fe57a3f3f4bdedf278372cd9df1bd9

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'spec_helper'

module Skeptic
  module Rules
    describe NoSemicolons do
      describe "detecting semicolons" do
        it "complains if it finds a semicolon in the code" do
          expect_complaint 'foo; bar'
          expect_complaint 'this; that; other'
          expect_complaint '"#{foo;bar}"'
        end

        it "does not complain for semicolons in literals" do
          expect_fine_and_dandy '"foo;"'
          expect_fine_and_dandy '";"'
          expect_fine_and_dandy '/;/'
        end

        it "can tell the locations of the semicolons" do
          analyze("foo;\n;bar").semicolon_locations.should =~ [[1, 3], [2, 0]]
        end
      end

      describe "reporting" do
        it "points out file locations with semicolons" do
          analyzer = analyze 'foo; bar'

          analyzer.violations.should include 'You have a semicolon at line 1, column 3'
        end

        it "reports under 'No semicolons'" do
          NoSemicolons.new(true).name.should eq 'No semicolons as expression separators'
        end
      end

      def expect_fine_and_dandy(code)
        analyze(code).semicolon_locations.should be_empty
      end

      def expect_complaint(code)
        analyze(code).semicolon_locations.should_not be_empty
      end

      def analyze(code)
        NoSemicolons.new(true).apply_to Ripper.lex(code), nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skeptic-0.0.0 spec/skeptic/rules/no_semicolons_spec.rb