Skip to content

Commit

Permalink
move specs to top
Browse files Browse the repository at this point in the history
  • Loading branch information
moofkit committed Nov 5, 2020
1 parent adeb5ff commit 5e0b9d1
Showing 1 changed file with 49 additions and 48 deletions.
97 changes: 49 additions & 48 deletions core/module/const_source_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,99 +8,100 @@
end

ruby_version_is "2.7" do
describe "with statically assigned constants" do
it "searches location path the immediate class or module first" do
ConstantSpecs::ClassA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, 78]
ConstantSpecs::ModuleA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, 36]
ConstantSpecs::ParentA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, 100]
ConstantSpecs::ContainerA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, 120]
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, 137]
end

it "searches location path a module included in the immediate class before the superclass" do
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST15).should == [@constants_fixture_path, 52]
end

it "searches location path the superclass before a module included in the superclass" do
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST11).should == [@constants_fixture_path, 101]
end

it "searches location path a module included in the superclass" do
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST12).should == [@constants_fixture_path, 46]
end

it "searches location path the superclass chain" do
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST13).should == [@constants_fixture_path, 38]
end

it "returns location path a toplevel constant when the receiver is a Class" do
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST1).should == [@constants_fixture_path, 30]
end

it "returns location path a toplevel constant when the receiver is a Module" do
ConstantSpecs.const_source_location(:CS_CONST1).should == [@constants_fixture_path, 30]
ConstantSpecs::ModuleA.const_source_location(:CS_CONST1).should == [@constants_fixture_path, 30]
end
end

# NOTE: please keep this specs on the top to avoid breaking specs
describe "with dynamically assigned constants" do
it "searches a path in the immediate class or module first" do
ConstantSpecs::ClassA::CS_CONST301 = :const301_1
ConstantSpecs::ClassA.const_source_location(:CS_CONST301).should == [__FILE__, 48]
ConstantSpecs::ClassA.const_source_location(:CS_CONST301).should == [__FILE__, 14]

ConstantSpecs::ModuleA::CS_CONST301 = :const301_2
ConstantSpecs::ModuleA.const_source_location(:CS_CONST301).should == [__FILE__, 51]
ConstantSpecs::ModuleA.const_source_location(:CS_CONST301).should == [__FILE__, 17]

ConstantSpecs::ParentA::CS_CONST301 = :const301_3
ConstantSpecs::ParentA.const_source_location(:CS_CONST301).should == [__FILE__, 54]
ConstantSpecs::ParentA.const_source_location(:CS_CONST301).should == [__FILE__, 20]

ConstantSpecs::ContainerA::ChildA::CS_CONST301 = :const301_5
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST301).should == [__FILE__, 57]
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST301).should == [__FILE__, 23]
end

it "searches a path in a module included in the immediate class before the superclass" do
ConstantSpecs::ParentB::CS_CONST302 = :const302_1
ConstantSpecs::ModuleF::CS_CONST302 = :const302_2
ConstantSpecs::ContainerB::ChildB.const_source_location(:CS_CONST302).should == [__FILE__, 63]
ConstantSpecs::ContainerB::ChildB.const_source_location(:CS_CONST302).should == [__FILE__, 29]
end

it "searches a path in the superclass before a module included in the superclass" do
ConstantSpecs::ModuleE::CS_CONST303 = :const303_1
ConstantSpecs::ParentB::CS_CONST303 = :const303_2
ConstantSpecs::ContainerB::ChildB.const_source_location(:CS_CONST303).should == [__FILE__, 69]
ConstantSpecs::ContainerB::ChildB.const_source_location(:CS_CONST303).should == [__FILE__, 35]
end

it "searches a path in a module included in the superclass" do
ConstantSpecs::ModuleA::CS_CONST304 = :const304_1
ConstantSpecs::ModuleE::CS_CONST304 = :const304_2
ConstantSpecs::ContainerB::ChildB.const_source_location(:CS_CONST304).should == [__FILE__, 75]
ConstantSpecs::ContainerB::ChildB.const_source_location(:CS_CONST304).should == [__FILE__, 41]
end

it "searches a path in the superclass chain" do
ConstantSpecs::ModuleA::CS_CONST305 = :const305
ConstantSpecs::ContainerB::ChildB.const_source_location(:CS_CONST305).should == [__FILE__, 80]
ConstantSpecs::ContainerB::ChildB.const_source_location(:CS_CONST305).should == [__FILE__, 46]
end

it "returns path to a toplevel constant when the receiver is a Class" do
Object::CS_CONST306 = :const306
ConstantSpecs::ContainerB::ChildB.const_source_location(:CS_CONST306).should == [__FILE__, 85]
ConstantSpecs::ContainerB::ChildB.const_source_location(:CS_CONST306).should == [__FILE__, 51]
end

it "returns path to a toplevel constant when the receiver is a Module" do
Object::CS_CONST308 = :const308
ConstantSpecs.const_source_location(:CS_CONST308).should == [__FILE__, 90]
ConstantSpecs::ModuleA.const_source_location(:CS_CONST308).should == [__FILE__, 90]
ConstantSpecs.const_source_location(:CS_CONST308).should == [__FILE__, 56]
ConstantSpecs::ModuleA.const_source_location(:CS_CONST308).should == [__FILE__, 56]
end

it "returns path to the updated value of a constant" do
ConstantSpecs::ClassB::CS_CONST309 = :const309_1
ConstantSpecs::ClassB.const_source_location(:CS_CONST309).should == [__FILE__, 96]
ConstantSpecs::ClassB.const_source_location(:CS_CONST309).should == [__FILE__, 62]

-> {
ConstantSpecs::ClassB::CS_CONST309 = :const309_2
}.should complain(/already initialized constant/)

ConstantSpecs::ClassB.const_source_location(:CS_CONST309).should == [__FILE__, 100]
ConstantSpecs::ClassB.const_source_location(:CS_CONST309).should == [__FILE__, 66]
end
end

describe "with statically assigned constants" do
it "searches location path the immediate class or module first" do
ConstantSpecs::ClassA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, 78]
ConstantSpecs::ModuleA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, 36]
ConstantSpecs::ParentA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, 100]
ConstantSpecs::ContainerA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, 120]
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, 137]
end

it "searches location path a module included in the immediate class before the superclass" do
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST15).should == [@constants_fixture_path, 52]
end

it "searches location path the superclass before a module included in the superclass" do
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST11).should == [@constants_fixture_path, 101]
end

it "searches location path a module included in the superclass" do
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST12).should == [@constants_fixture_path, 46]
end

it "searches location path the superclass chain" do
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST13).should == [@constants_fixture_path, 38]
end

it "returns location path a toplevel constant when the receiver is a Class" do
ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST1).should == [@constants_fixture_path, 30]
end

it "returns location path a toplevel constant when the receiver is a Module" do
ConstantSpecs.const_source_location(:CS_CONST1).should == [@constants_fixture_path, 30]
ConstantSpecs::ModuleA.const_source_location(:CS_CONST1).should == [@constants_fixture_path, 30]
end
end
end
Expand Down

0 comments on commit 5e0b9d1

Please sign in to comment.