From b85e2ef93269bdaa4a8c2282637135da3b60b41b Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 28 Dec 2024 17:30:55 +0100 Subject: [PATCH] Run Rubocop autocorrect on spec/extensions --- spec/extensions/tree_spec.rb | 44 +++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/spec/extensions/tree_spec.rb b/spec/extensions/tree_spec.rb index 6629197..328158d 100644 --- a/spec/extensions/tree_spec.rb +++ b/spec/extensions/tree_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2024 Manuel Bustillo require 'rails_helper' @@ -5,66 +7,66 @@ require 'rails_helper' module Tree RSpec.describe TreeNode do describe '#distance_to_common_ancestor' do - def assert_distance(node_1, node_2, distance) + def assert_distance(node1, node2, distance) aggregate_failures do - expect(node_1.distance_to_common_ancestor(node_2)).to eq(distance) - expect(node_2.distance_to_common_ancestor(node_1)).to eq(distance) + expect(node1.distance_to_common_ancestor(node2)).to eq(distance) + expect(node2.distance_to_common_ancestor(node1)).to eq(distance) end end context 'when the two nodes are the same' do it 'returns 0 when comparing the root itself' do - root = Tree::TreeNode.new('root') + root = described_class.new('root') assert_distance(root, root, 0) end it 'returns 0 when comparing a child to itself' do - root = Tree::TreeNode.new('root') - child = root << Tree::TreeNode.new('child') + root = described_class.new('root') + child = root << described_class.new('child') assert_distance(child, child, 0) end end context 'when the two nodes are siblings' do it 'returns 1 when comparing siblings' do - root = Tree::TreeNode.new('root') - child1 = root << Tree::TreeNode.new('child1') - child2 = root << Tree::TreeNode.new('child2') + root = described_class.new('root') + child1 = root << described_class.new('child1') + child2 = root << described_class.new('child2') assert_distance(child1, child2, 1) end end context 'when one node is parent of the other' do it 'returns 1 when comparing parent to child' do - root = Tree::TreeNode.new('root') - child = root << Tree::TreeNode.new('child') + root = described_class.new('root') + child = root << described_class.new('child') assert_distance(root, child, 1) end end context 'when one node is grandparent of the other' do it 'returns 2 when comparing grandparent to grandchild' do - root = Tree::TreeNode.new('root') - child = root << Tree::TreeNode.new('child') - grandchild = child << Tree::TreeNode.new('grandchild') + root = described_class.new('root') + child = root << described_class.new('child') + grandchild = child << described_class.new('grandchild') assert_distance(root, grandchild, 2) end end context 'when the two nodes are cousins' do it 'returns 2 when comparing cousins' do - root = Tree::TreeNode.new('root') - child1 = root << Tree::TreeNode.new('child1') - child2 = root << Tree::TreeNode.new('child2') - grandchild1 = child1 << Tree::TreeNode.new('grandchild1') - grandchild2 = child2 << Tree::TreeNode.new('grandchild2') + root = described_class.new('root') + child1 = root << described_class.new('child1') + child2 = root << described_class.new('child2') + grandchild1 = child1 << described_class.new('grandchild1') + grandchild2 = child2 << described_class.new('grandchild2') assert_distance(grandchild1, grandchild2, 2) end end context 'when the two nodes are not related' do it 'returns nil' do - root = Tree::TreeNode.new('root') - another_root = Tree::TreeNode.new('another_root') + root = described_class.new('root') + another_root = described_class.new('another_root') assert_distance(root, another_root, nil) end end