Sha256: a2f914b091752757cd4838644410121a286182c66cb55e95f494a2377d41dc34

Contents?: true

Size: 1.37 KB

Versions: 23

Compression:

Stored size: 1.37 KB

Contents

require_relative '../../spec_helper'
require_lib 'reek/ast/reference_collector'

RSpec.describe Reek::AST::ReferenceCollector do
  describe '#num_refs_to_self' do
    def refs_to_self(src)
      syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
      described_class.new(syntax_tree).num_refs_to_self
    end

    it 'with no refs to self' do
      expect(refs_to_self('def no_envy(arga) arga.barg end')).to eq(0)
    end

    it 'counts a call to super' do
      expect(refs_to_self('def simple() super; end')).to eq(1)
    end

    it 'counts a call to super with arguments' do
      expect(refs_to_self('def simple() super(); end')).to eq(1)
    end

    it 'counts a local call' do
      expect(refs_to_self('def simple() to_s; end')).to eq(1)
    end

    it 'counts a use of self' do
      expect(refs_to_self('def simple() lv = self; end')).to eq(1)
    end

    it 'counts a call with self as receiver' do
      expect(refs_to_self('def simple() self.to_s; end')).to eq(1)
    end

    it 'counts uses of an ivar' do
      expect(refs_to_self('def no_envy() @item.to_a; @item = 4; @item end')).to eq(3)
    end

    it 'counts an ivar passed to a method' do
      expect(refs_to_self('def no_envy(arga) arga.barg(@item); arga end')).to eq(1)
    end

    it 'ignores global variables' do
      expect(refs_to_self('def no_envy(arga) $s2.to_a; $s2[arga] end')).to eq(0)
    end
  end
end

Version data entries

23 entries across 21 versions & 2 rubygems

Version Path
reek-6.0.3 spec/reek/ast/reference_collector_spec.rb
reek-6.0.2 spec/reek/ast/reference_collector_spec.rb
reek-6.0.1 spec/reek/ast/reference_collector_spec.rb
reek-6.0.0 spec/reek/ast/reference_collector_spec.rb
reek-5.6.0 spec/reek/ast/reference_collector_spec.rb
reek-5.5.0 spec/reek/ast/reference_collector_spec.rb
reek-5.4.1 spec/reek/ast/reference_collector_spec.rb
reek-5.4.0 spec/reek/ast/reference_collector_spec.rb
reek-5.3.2 spec/reek/ast/reference_collector_spec.rb
reek-5.3.1 spec/reek/ast/reference_collector_spec.rb
reek-5.3.0 spec/reek/ast/reference_collector_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/ast/reference_collector_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/ast/reference_collector_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/ast/reference_collector_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/ast/reference_collector_spec.rb
reek-5.2.0 spec/reek/ast/reference_collector_spec.rb
reek-5.1.0 spec/reek/ast/reference_collector_spec.rb
reek-5.0.2 spec/reek/ast/reference_collector_spec.rb
reek-5.0.1 spec/reek/ast/reference_collector_spec.rb
reek-5.0.0 spec/reek/ast/reference_collector_spec.rb