12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/rspec/core/shared_example_group.rb', line 12
def share_as(name, &block)
if Object.const_defined?(name)
mod = Object.const_get(name)
raise_name_error unless mod.created_from_caller(caller)
end
mod = Module.new do
@shared_block = block
@caller_line = caller.last
def self.created_from_caller(other_caller)
@caller_line == other_caller.last
end
def self.included(kls)
kls.describe(&@shared_block)
kls.children.first.metadata[:shared_group_name] = name
end
end
shared_const = Object.const_set(name, mod)
RSpec.world.shared_example_groups[shared_const] = block
end
|