模块: RSpec::Core::SharedExampleGroup
- 包含于
- ExampleGroup
- 定义于
- lib/rspec/core/shared_example_group.rb
概述
共享示例组允许您定义希望在多个示例组中使用的通用上下文和/或通用示例。
定义后,共享组块将被存储以供以后评估。它稍后可以显式地 (使用 include_examples
、include_context
或 it_behaves_like
) 或隐式地 (通过匹配元数据) 包含在示例组中。
命名共享示例组的范围基于其定义位置。在示例组中定义的共享组可用于包含在该示例组或任何子示例组中,但不可用于任何父示例组或同级示例组。在顶层定义的共享示例组可以从任何示例组中包含。
在命名空间下定义
模块: TopLevelDSL
实例方法概要 收起
-
#shared_examples(name, *args, &block) ⇒ void (也称为: #shared_context, #shared_examples_for)
存储块以供以后使用。
实例方法详情
#shared_examples(name, &block) ⇒ void #shared_examples(name, metadata, &block) ⇒ void 也称为: ,
存储块以供以后使用。该块将在示例组的上下文中通过 include_examples
、include_context
或 it_behaves_like
评估。
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rspec/core/shared_example_group.rb', line 90 def shared_examples(name, *args, &block) top_level = self == ExampleGroup if top_level && RSpec::Support.thread_local_data[:in_example_group] raise "Creating isolated shared examples from within a context is " \ "not allowed. Remove `RSpec.` prefix or move this to a " \ "top-level scope." end RSpec.world.shared_example_group_registry.add(self, name, *args, &block) end |