Sha256: 09e6ff09c7ada53c93d1ba012593c2491cdd820dd8d361d7eb4aa02d4a2b20e1

Contents?: true

Size: 1.7 KB

Versions: 24

Compression:

Stored size: 1.7 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) { double('exp') }
  let(:parent) { Reek::Context::CodeContext.new(nil, exp) }

  describe '#register_with_parent' do
    it 'does not append itself to its parent' do
      ghost = described_class.new(parent, 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(parent, nil) }

    before do
      ghost.register_with_parent(parent)
    end

    it 'appends the child to the grandparent context' do
      child = Reek::Context::CodeContext.new(ghost, 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(ghost, 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(ghost, sexp(:foo))
      child.register_with_parent(ghost)

      expect(ghost.children).to include child
    end

    context 'if the grandparent is also a ghost' do
      let(:child_ghost) { described_class.new(ghost, 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(child_ghost, sexp(:foo))
        child.register_with_parent(child_ghost)

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

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
reek-4.4.1 spec/reek/context/ghost_context_spec.rb
reek-4.4.0 spec/reek/context/ghost_context_spec.rb
reek-4.3.0 spec/reek/context/ghost_context_spec.rb
reek-4.2.5 spec/reek/context/ghost_context_spec.rb
reek-4.2.4 spec/reek/context/ghost_context_spec.rb
reek-4.2.3 spec/reek/context/ghost_context_spec.rb
reek-4.2.2 spec/reek/context/ghost_context_spec.rb
reek-4.2.1 spec/reek/context/ghost_context_spec.rb
reek-4.2.0 spec/reek/context/ghost_context_spec.rb
reek-4.1.1 spec/reek/context/ghost_context_spec.rb
reek-4.1.0 spec/reek/context/ghost_context_spec.rb
reek-4.0.5 spec/reek/context/ghost_context_spec.rb
reek-4.0.4 spec/reek/context/ghost_context_spec.rb
reek-4.0.3 spec/reek/context/ghost_context_spec.rb
reek-4.0.2 spec/reek/context/ghost_context_spec.rb
reek-4.0.1 spec/reek/context/ghost_context_spec.rb
reek-4.0.0 spec/reek/context/ghost_context_spec.rb
reek-4.0.0.pre1 spec/reek/context/ghost_context_spec.rb
reek-3.11 spec/reek/context/ghost_context_spec.rb
reek-3.10.2 spec/reek/context/ghost_context_spec.rb