模块:RSpec
- 定义于
- lib/rspec/core.rb,
lib/rspec/core/drb.rb,
lib/rspec/core/dsl.rb,
lib/rspec/core/set.rb,
lib/rspec/core/hooks.rb,
lib/rspec/core/world.rb,
lib/rspec/core/runner.rb,
lib/rspec/core/example.rb,
lib/rspec/core/pending.rb,
lib/rspec/core/sandbox.rb,
lib/rspec/core/version.rb,
lib/rspec/core/flat_map.rb,
lib/rspec/core/metadata.rb,
lib/rspec/core/ordering.rb,
lib/rspec/core/profiler.rb,
lib/rspec/core/warnings.rb,
lib/rspec/core/rake_task.rb,
lib/rspec/core/invocations.rb,
lib/rspec/core/did_you_mean.rb,
lib/rspec/core/ruby_project.rb,
lib/rspec/core/shell_escape.rb,
lib/rspec/core/bisect/server.rb,
lib/rspec/core/configuration.rb,
lib/rspec/core/example_group.rb,
lib/rspec/core/filter_manager.rb,
lib/rspec/core/output_wrapper.rb,
lib/rspec/core/shared_context.rb,
lib/rspec/core/metadata_filter.rb,
lib/rspec/core/bisect/utilities.rb,
lib/rspec/core/memoized_helpers.rb,
lib/rspec/core/bisect/coordinator.rb,
lib/rspec/core/bisect/fork_runner.rb,
lib/rspec/core/formatters/helpers.rb,
lib/rspec/core/backtrace_formatter.rb,
lib/rspec/core/bisect/shell_runner.rb,
lib/rspec/core/formatters/protocol.rb,
lib/rspec/core/mocking_adapters/rr.rb,
lib/rspec/core/project_initializer.rb,
lib/rspec/core/bisect/shell_command.rb,
lib/rspec/core/shared_example_group.rb,
lib/rspec/core/configuration_options.rb,
lib/rspec/core/mocking_adapters/null.rb,
lib/rspec/core/mocking_adapters/mocha.rb,
lib/rspec/core/mocking_adapters/rspec.rb,
lib/rspec/core/formatters/html_printer.rb,
lib/rspec/core/bisect/example_minimizer.rb,
lib/rspec/core/example_status_persister.rb,
lib/rspec/core/formatters/console_codes.rb,
lib/rspec/core/formatters/base_formatter.rb,
lib/rspec/core/formatters/html_formatter.rb,
lib/rspec/core/formatters/json_formatter.rb,
lib/rspec/core/mocking_adapters/flexmock.rb,
lib/rspec/core/minitest_assertions_adapter.rb,
lib/rspec/core/formatters/profile_formatter.rb,
lib/rspec/core/formatters/snippet_extractor.rb,
lib/rspec/core/test_unit_assertions_adapter.rb,
lib/rspec/core/formatters/progress_formatter.rb,
lib/rspec/core/formatters/syntax_highlighter.rb,
lib/rspec/core/formatters/base_text_formatter.rb,
lib/rspec/core/formatters/exception_presenter.rb,
lib/rspec/core/formatters/bisect_drb_formatter.rb,
lib/rspec/core/formatters/base_bisect_formatter.rb,
lib/rspec/core/formatters/deprecation_formatter.rb,
lib/rspec/core/formatters/failure_list_formatter.rb,
lib/rspec/core/formatters/html_snippet_extractor.rb,
lib/rspec/core/formatters/documentation_formatter.rb,
lib/rspec/core/formatters/bisect_progress_formatter.rb,
lib/rspec/core/formatters/fallback_message_formatter.rb
概述
这部分借鉴(略作修改)自 Scott Taylor 的 project_path 项目:http://github.com/smtlaissezfaire/project_path
定义在命名空间下
模块: Core
类属性摘要 折叠
-
.configuration ⇒ void
返回全局 Configuration 对象。
-
.world ⇒ void 只写 私有
共享全局对象的设置器。
类方法摘要 折叠
-
.clear_examples ⇒ void
用于确保在同一进程中的多次运行之间重新加载示例,并确保用户配置持久化。
-
.configure {|Configuration| ... } ⇒ void
将全局配置传递给一个块。
-
.current_example ⇒ void
正在执行的示例。
-
.current_example=(example) ⇒ void 私有
设置正在执行的当前示例。
-
.current_scope ⇒ Symbol
获取当前 RSpec 执行范围。
-
.current_scope=(scope) ⇒ void 私有
设置 rspec 正在执行的当前范围。
-
.reset ⇒ void
用于确保在同一进程中的多次运行之间重新加载示例,并将用户配置重置为默认值。
类属性详细信息
.configuration ⇒void
返回全局 Configuration 对象。虽然您可以使用此方法访问配置,但更常见的约定是使用 RSpec.configure。
85 86 87 |
# File 'lib/rspec/core.rb', line 85 def self.configuration @configuration ||= RSpec::Core::Configuration.new end |
.world=(value) ⇒void
此方法是私有 API 的一部分。 应尽可能避免使用此方法,因为它可能会在将来被移除或更改。
共享全局对象的设置器
49 50 51 |
# File 'lib/rspec/core.rb', line 49 def world=(value) @world = value end |
类方法详细信息
.clear_examples ⇒void
用于确保在同一进程中的多次运行之间重新加载示例,并确保用户配置持久化。
如果用户希望清除所有示例,但在同一进程中多次使用运行器时保留当前配置,则必须调用此方法。
70 71 72 73 74 75 |
# File 'lib/rspec/core.rb', line 70 def self.clear_examples world.reset configuration.reset_reporter configuration.start_time = ::RSpec::Core::Time.now configuration.reset_filters end |
.configure {|Configuration| ... } ⇒void
将全局配置传递给一个块。
97 98 99 |
# File 'lib/rspec/core.rb', line 97 def self.configure yield configuration if block_given? end |
.current_example ⇒void
正在执行的示例。
此方法的主要受众是库作者,他们需要访问当前正在执行的示例,并且还希望支持所有版本的 RSpec 2 和 3。
122 123 124 |
# File 'lib/rspec/core.rb', line 122 def self.current_example RSpec::Support.thread_local_data[:current_example] end |
.current_example=(example) ⇒void
此方法是私有 API 的一部分。 应尽可能避免使用此方法,因为它可能会在将来被移除或更改。
设置正在执行的当前示例。
128 129 130 |
# File 'lib/rspec/core.rb', line 128 def self.current_example=(example) RSpec::Support.thread_local_data[:current_example] = example end |
.current_scope ⇒Symbol
获取当前 RSpec 执行范围
返回(按生命周期的顺序)
:suite
作为初始值,这在测试生命周期之外。:before_suite_hook
在before(:suite)
钩子期间。:before_context_hook
在before(:context)
钩子期间。:before_example_hook
在before(:example)
钩子期间,以及around(:example)
在example.run
之前。:example
在示例运行中。:after_example_hook
在after(:example)
钩子期间,以及around(:example)
在example.run
之后。:after_context_hook
在after(:context)
钩子期间。:after_suite_hook
在after(:suite)
钩子期间。:suite
作为最终值,再次在测试生命周期之外。
提醒一下,:context
钩子有 :all
别名,:example
钩子有 :each
别名。
154 155 156 |
# File 'lib/rspec/core.rb', line 154 def self.current_scope RSpec::Support.thread_local_data[:current_scope] end |
.current_scope=(scope) ⇒void
此方法是私有 API 的一部分。 应尽可能避免使用此方法,因为它可能会在将来被移除或更改。
设置 rspec 正在执行的当前范围
134 135 136 |
# File 'lib/rspec/core.rb', line 134 def self.current_scope=(scope) RSpec::Support.thread_local_data[:current_scope] = scope end |
.reset ⇒void
用于确保在同一进程中的多次运行之间重新加载示例,并将用户配置重置为默认值。
如果用户希望在同一进程中多次使用运行器时重置配置,则必须调用此方法。用户必须在运行之前自行处理 RSpec 的重新配置。
58 59 60 61 62 |
# File 'lib/rspec/core.rb', line 58 def self.reset RSpec::ExampleGroups.remove_all_constants @world = nil @configuration = nil end |