@@ -168,67 +168,55 @@ def some_method
168168 end
169169 end
170170
171- describe 'sibling modules' do
172- let ( :sibling_modules_source ) do
173- <<-RUBY
174- module Foo
175- module Bar
176- end
177- module Baz
178- end
171+ describe 'siblings' do
172+ shared_examples 'sibling scopes' do |type |
173+ it "should place sibling #{ type } s at the same level" do
174+ foo = scope_parser . root_scope . children . first
175+ assert_equal ( 'Foo' , foo . name )
176+
177+ # Both Bar and Baz should be children of Foo, not Bar containing Baz
178+ children = foo . children
179+ assert_equal ( 2 , children . size , "Foo should have 2 children, but has #{ children . size } " )
180+
181+ bar = children . detect { |c | c . name == 'Bar' }
182+ baz = children . detect { |c | c . name == 'Baz' }
183+
184+ assert_not_nil ( bar , "Bar should be a child of Foo" )
185+ assert_not_nil ( baz , "Baz should be a child of Foo" )
186+
187+ # Verify Baz is not a child of Bar
188+ assert_equal ( 0 , bar . children . size , "Bar should have no children, but has #{ bar . children . size } " )
179189 end
180- RUBY
181- end
182- let ( :scope_parser ) { RubyLanguageServer ::ScopeParser . new ( sibling_modules_source ) }
183-
184- it 'should place sibling modules at the same level' do
185- foo = scope_parser . root_scope . children . first
186- assert_equal ( 'Foo' , foo . name )
187-
188- # Both Bar and Baz should be children of Foo, not Bar containing Baz
189- children = foo . children
190- assert_equal ( 2 , children . size , "Foo should have 2 children, but has #{ children . size } " )
191-
192- bar = children . detect { |c | c . name == 'Bar' }
193- baz = children . detect { |c | c . name == 'Baz' }
194-
195- assert_not_nil ( bar , "Bar should be a child of Foo" )
196- assert_not_nil ( baz , "Baz should be a child of Foo" )
197-
198- # Verify Baz is not a child of Bar
199- assert_equal ( 0 , bar . children . size , "Bar should have no children, but has #{ bar . children . size } " )
200190 end
201- end
202191
203- describe 'sibling classes' do
204- let ( :sibling_classes_source ) do
205- <<-RUBY
206- module Foo
207- class Bar
192+ describe 'modules' do
193+ let ( :scope_parser ) do
194+ RubyLanguageServer ::ScopeParser . new ( <<-RUBY )
195+ module Foo
196+ module Bar
197+ end
198+ module Baz
199+ end
208200 end
209- class Baz
201+ RUBY
202+ end
203+
204+ include_examples 'sibling scopes' , 'module'
205+ end
206+
207+ describe 'classes' do
208+ let ( :scope_parser ) do
209+ RubyLanguageServer ::ScopeParser . new ( <<-RUBY )
210+ module Foo
211+ class Bar
212+ end
213+ class Baz
214+ end
210215 end
216+ RUBY
211217 end
212- RUBY
213- end
214- let ( :scope_parser ) { RubyLanguageServer ::ScopeParser . new ( sibling_classes_source ) }
215-
216- it 'should place sibling classes at the same level' do
217- foo = scope_parser . root_scope . children . first
218- assert_equal ( 'Foo' , foo . name )
219-
220- # Both Bar and Baz should be children of Foo, not Bar containing Baz
221- children = foo . children
222- assert_equal ( 2 , children . size , "Foo should have 2 children, but has #{ children . size } " )
223-
224- bar = children . detect { |c | c . name == 'Bar' }
225- baz = children . detect { |c | c . name == 'Baz' }
226-
227- assert_not_nil ( bar , "Bar should be a child of Foo" )
228- assert_not_nil ( baz , "Baz should be a child of Foo" )
229-
230- # Verify Baz is not a child of Bar
231- assert_equal ( 0 , bar . children . size , "Bar should have no children, but has #{ bar . children . size } " )
218+
219+ include_examples 'sibling scopes' , 'class'
232220 end
233221 end
234222 end
0 commit comments