Sha256: 371d59684562b753e51c8931d37bbef30288265e64ea7194a86b41892a827ed7

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

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

describe Simplabs::Excellent::Checks::SingletonVariableCheck do

  before(:each) do
    @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::SingletonVariableCheck.new)
  end

  describe '#evaluate' do

    it 'should reject singleton variables' do
      code = <<-END
        @@foo
      END
      @excellent.check_code(code)
      warnings = @excellent.warnings

      warnings.should_not be_empty
      warnings[0].info.should        == { :variable => 'foo' }
      warnings[0].line_number.should == 1
      warnings[0].message.should     == 'Singleton variable foo used.'
    end

    it 'should also work for namespaced classes' do
      code = <<-END
        module Outer
          module Inner
            class Class
              @@foo
            end
          end
        end
      END
      @excellent.check_code(code)
      warnings = @excellent.warnings

      warnings.should_not be_empty
      warnings[0].info.should        == { :variable => 'Outer::Inner::Class.foo' }
      warnings[0].line_number.should == 4
      warnings[0].message.should     == 'Singleton variable Outer::Inner::Class.foo used.'
    end

    it 'should also work for singleton variables that occur within methods' do
      code = <<-END
        module Outer
          module Inner
            class Class
              def method
                @@foo
              end
            end
          end
        end
      END
      @excellent.check_code(code)
      warnings = @excellent.warnings

      warnings.should_not be_empty
      warnings[0].info.should        == { :variable => 'Outer::Inner::Class.foo' }
      warnings[0].line_number.should == 5
      warnings[0].message.should     == 'Singleton variable Outer::Inner::Class.foo used.'
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
excellent-1.7.2 spec/checks/singleton_variable_check_spec.rb
excellent-1.7.1 spec/checks/singleton_variable_check_spec.rb
excellent-1.7.0 spec/checks/singleton_variable_check_spec.rb