Object
@private
Used internally to manage the shared example groups and constants. We want to limit the number of methods we add to objects we don’t own (main and Module) so this allows us to have helper methods that don’t get added to those objects.
# File lib/rspec/core/shared_example_group.rb, line 100 def add_const(source, 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) add_shared_example_group source, shared_const, block end
# File lib/rspec/core/shared_example_group.rb, line 82 def add_group(source, *args, &block) ensure_block_has_source_location(block, caller[1]) if key? args.first key = args.shift warn_if_key_taken source, key, block add_shared_example_group source, key, block end unless args.empty? mod = Module.new (class << mod; self; end).send :define_method, :extended do |host| host.class_eval(&block) end RSpec.configuration.extend mod, *args end end
Generated with the Darkfish Rdoc Generator 2.