Sha256: 77f6948ebff5aab3dc46d3abe014d0d641dda3b55b052a49f425fe023958d237

Contents?: true

Size: 1.8 KB

Versions: 12

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 == 2
      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 == 5
      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 == 6
      warnings[0].message.should     == 'Singleton variable Outer::Inner::Class.foo used.'
    end

  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
simplabs-excellent-1.2.2 spec/checks/singleton_variable_check_spec.rb
simplabs-excellent-1.3.0 spec/checks/singleton_variable_check_spec.rb
simplabs-excellent-1.3.1 spec/checks/singleton_variable_check_spec.rb
simplabs-excellent-1.4.0 spec/checks/singleton_variable_check_spec.rb
simplabs-excellent-1.4.1 spec/checks/singleton_variable_check_spec.rb
simplabs-excellent-1.4.2 spec/checks/singleton_variable_check_spec.rb
simplabs-excellent-1.5.0 spec/checks/singleton_variable_check_spec.rb
simplabs-excellent-1.5.1 spec/checks/singleton_variable_check_spec.rb
simplabs-excellent-1.5.2 spec/checks/singleton_variable_check_spec.rb
simplabs-excellent-1.5.3 spec/checks/singleton_variable_check_spec.rb
excellent-1.6.0 spec/checks/singleton_variable_check_spec.rb
excellent-1.5.4 spec/checks/singleton_variable_check_spec.rb