Sha256: d4a9527f03f5d5756347de940dd07799aa584575b8d656a10fcf4fece8fbe495

Contents?: true

Size: 1.63 KB

Versions: 8

Compression:

Stored size: 1.63 KB

Contents

require_relative '../../spec_helper'
require_lib 'reek/context/module_context'
require_lib 'reek/context/root_context'

RSpec.describe Reek::Context::ModuleContext do
  it 'reports module name for smell in method' do
    expect('
      module Fred
        def simple(x) x + 1; end
      end
    ').to reek_of(:UncommunicativeParameterName, name: 'x')
  end

  it 'does not report module with empty class' do
    expect('
      # module for test
      module Fred
        # module for test
        class Jim; end; end').not_to reek
  end

  it 'recognises global constant' do
    expect('
      # module for test
      module ::Global
        # module for test
        class Inside; end; end').not_to reek
  end

  describe '#track_visibility' do
    let(:context) { described_class.new(nil, double('exp1')) }
    let(:first_child) { Reek::Context::MethodContext.new(context, double('exp2', type: :def, name: :foo)) }
    let(:second_child) { Reek::Context::MethodContext.new(context, double('exp3', type: :def)) }

    it 'sets visibility on subsequent child contexts' do
      context.append_child_context first_child
      context.track_visibility :private, []
      context.append_child_context second_child
      expect(first_child.visibility).to eq :public
      expect(second_child.visibility).to eq :private
    end

    it 'sets visibility on specifically mentioned child contexts' do
      context.append_child_context first_child
      context.track_visibility :private, [first_child.name]
      context.append_child_context second_child
      expect(first_child.visibility).to eq :private
      expect(second_child.visibility).to eq :public
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reek-4.5.6 spec/reek/context/module_context_spec.rb
reek-4.5.5 spec/reek/context/module_context_spec.rb
reek-4.5.4 spec/reek/context/module_context_spec.rb
reek-4.5.3 spec/reek/context/module_context_spec.rb
reek-4.5.2 spec/reek/context/module_context_spec.rb
reek-4.5.1 spec/reek/context/module_context_spec.rb
reek-4.5.0 spec/reek/context/module_context_spec.rb
reek-4.4.2 spec/reek/context/module_context_spec.rb