Sha256: 2aa6959b70def08693333d2467b32e8bac85fdd9ac9dcd288f224d4713ddd844

Contents?: true

Size: 1.66 KB

Versions: 23

Compression:

Stored size: 1.66 KB

Contents

require_relative '../../spec_helper'
require_lib 'reek/context/code_context'
require_lib 'reek/context/ghost_context'

RSpec.describe Reek::Context::GhostContext do
  let(:exp) { instance_double('Reek::AST::Node') }
  let(:parent) { Reek::Context::CodeContext.new(exp) }

  describe '#register_with_parent' do
    it 'does not append itself to its parent' do
      ghost = described_class.new(nil)
      ghost.register_with_parent(parent)
      expect(parent.children).not_to include ghost
    end
  end

  describe '#append_child_context' do
    let(:ghost) { described_class.new(nil) }

    before do
      ghost.register_with_parent(parent)
    end

    it 'appends the child to the grandparent context' do
      child = Reek::Context::CodeContext.new(sexp(:foo))
      child.register_with_parent(ghost)

      expect(parent.children).to include child
    end

    it "sets the child's parent to the grandparent context" do
      child = Reek::Context::CodeContext.new(sexp(:foo))
      child.register_with_parent(ghost)

      expect(child.parent).to eq parent
    end

    it 'appends the child to the list of children' do
      child = Reek::Context::CodeContext.new(sexp(:foo))
      child.register_with_parent(ghost)

      expect(ghost.children).to include child
    end

    context 'when the grandparent is also a ghost' do
      let(:child_ghost) { described_class.new(nil) }

      before do
        child_ghost.register_with_parent(ghost)
      end

      it 'sets the childs parent to its remote ancestor' do
        child = Reek::Context::CodeContext.new(sexp(:foo))
        child.register_with_parent(child_ghost)

        expect(child.parent).to eq parent
      end
    end
  end
end

Version data entries

23 entries across 21 versions & 2 rubygems

Version Path
reek-6.0.3 spec/reek/context/ghost_context_spec.rb
reek-6.0.2 spec/reek/context/ghost_context_spec.rb
reek-6.0.1 spec/reek/context/ghost_context_spec.rb
reek-6.0.0 spec/reek/context/ghost_context_spec.rb
reek-5.6.0 spec/reek/context/ghost_context_spec.rb
reek-5.5.0 spec/reek/context/ghost_context_spec.rb
reek-5.4.1 spec/reek/context/ghost_context_spec.rb
reek-5.4.0 spec/reek/context/ghost_context_spec.rb
reek-5.3.2 spec/reek/context/ghost_context_spec.rb
reek-5.3.1 spec/reek/context/ghost_context_spec.rb
reek-5.3.0 spec/reek/context/ghost_context_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/context/ghost_context_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/context/ghost_context_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/context/ghost_context_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/spec/reek/context/ghost_context_spec.rb
reek-5.2.0 spec/reek/context/ghost_context_spec.rb
reek-5.1.0 spec/reek/context/ghost_context_spec.rb
reek-5.0.2 spec/reek/context/ghost_context_spec.rb
reek-5.0.1 spec/reek/context/ghost_context_spec.rb
reek-5.0.0 spec/reek/context/ghost_context_spec.rb