类: RSpec::Expectations::Configuration
- 继承
-
Object
- Object
- RSpec::Expectations::Configuration
- 定义于
- lib/rspec/expectations/configuration.rb
概述
提供 rspec-expectations 的配置选项。如果您正在使用 rspec-core,您可以通过传递给 RSpec::Core::Configuration#expect_with
的代码块访问它。否则,您可以通过 RSpec::Expectations.configuration 访问它。
常量摘要 折叠
- NullBacktraceFormatter =
此常量是私有 API 的一部分。 应尽量避免使用此常量,因为它将来可能被移除或更改。
当未加载 rspec-core 时,默认情况下使用的回溯格式化程序的空实现。不进行任何过滤。
Module.new do def self.format_backtrace(backtrace) backtrace end end
实例属性摘要 折叠
-
#backtrace_formatter ⇒ Object
设置或获取回溯格式化程序。
-
#color ⇒ Object 只写
指示是否应为差异着色。
-
#include_chain_clauses_in_custom_matcher_descriptions ⇒ Object 只写
设置自定义匹配器描述和失败消息是否应包含使用
chain
定义的方法中的子句。 -
#on_potential_false_positives ⇒ Object
指示 RSpec 如何处理可能导致测试中出现假阳性的匹配器使用情况,通常您希望避免此类情况,因此默认为
true
。 -
#strict_predicate_matchers ⇒ Object
返回属性 strict_predicate_matchers 的值。
实例方法摘要 折叠
-
#add_should_and_should_not_to(*modules) ⇒ Object
向给定类或模块添加
should
和should_not
。 -
#color? ⇒ Boolean
指示是否应为差异着色。
-
#include_chain_clauses_in_custom_matcher_descriptions? ⇒ Boolean
指示自定义匹配器描述和失败消息是否应包含使用
chain
定义的方法中的子句。 -
#initialize ⇒ Configuration 构造函数
Configuration 的新实例。
-
#max_formatted_output_length=(length) ⇒ Object
配置 RSpec 在格式化对象时将打印的最大字符长度。
- #strict_predicate_matchers? ⇒ Boolean
-
#syntax ⇒ Array<Symbol>
已配置语法的列表。
-
#syntax=(values) ⇒ Object
配置支持的语法。
-
#warn_about_potential_false_positives=(boolean) ⇒ Object
配置 RSpec 是否会警告可能导致测试中出现假阳性的匹配器使用情况。
-
#warn_about_potential_false_positives? ⇒ Boolean
指示 RSpec 是否会警告可能导致测试中出现假阳性的匹配器使用情况,通常您希望避免此类情况,因此默认为
true
。
构造函数详细信息
#initialize ⇒Configuration
返回 Configuration 的新实例。
29 30 31 32 |
# File 'lib/rspec/expectations/configuration.rb', line 29 def initialize @on_potential_false_positives = :warn @strict_predicate_matchers = false end |
实例属性详细信息
#backtrace_formatter ⇒Object
设置或获取回溯格式化程序。回溯格式化程序应实现 #format_backtrace(Array<String>)
。这用于格式化由 raise_error
匹配器处理的错误的回溯。
如果您正在使用 rspec-core,将使用 rspec-core 的回溯格式化(包括尊重 --backtrace
选项的存在与否)。
128 |
# File 'lib/rspec/expectations/configuration.rb', line 128 attr_writer :backtrace_formatter |
#color=(value) ⇒Object (只写)
指示是否应为差异着色。如果加载了 rspec-core,则委托给 rspec-core 的颜色选项;否则,您可以在此处设置它。
95 96 97 |
# File 'lib/rspec/expectations/configuration.rb', line 95 def color=(value) @color = value end |
#include_chain_clauses_in_custom_matcher_descriptions=(value) ⇒Object (只写)
设置自定义匹配器描述和失败消息是否应包含使用 chain
定义的方法中的子句。
140 141 142 |
# File 'lib/rspec/expectations/configuration.rb', line 140 def include_chain_clauses_in_custom_matcher_descriptions=(value) @include_chain_clauses_in_custom_matcher_descriptions = value end |
#on_potential_false_positives ⇒Object
指示 RSpec 如何处理可能导致测试中出现假阳性的匹配器使用情况,通常您希望避免此类情况,因此默认为 true
。
206 207 208 |
# File 'lib/rspec/expectations/configuration.rb', line 206 def on_potential_false_positives @on_potential_false_positives end |
#strict_predicate_matchers ⇒Object
返回属性 strict_predicate_matchers 的值。
197 198 199 |
# File 'lib/rspec/expectations/configuration.rb', line 197 def strict_predicate_matchers @strict_predicate_matchers end |
实例方法详细信息
#add_should_and_should_not_to(*modules) ⇒Object
向给定类或模块添加 should
和 should_not
。这可用于确保 should
在诸如代理对象(尤其是 1.8 上的 Delegator
子类对象)之类的事物上正常工作。
112 113 114 115 116 |
# File 'lib/rspec/expectations/configuration.rb', line 112 def add_should_and_should_not_to(*modules) modules.each do |mod| Expectations::Syntax.enable_should(mod) end end |
#color? ⇒Boolean
指示是否应为差异着色。如果加载了 rspec-core,则委托给 rspec-core 的颜色选项;否则,您可以在此处设置它。
100 101 102 |
# File 'lib/rspec/expectations/configuration.rb', line 100 def color? ::RSpec.configuration.color_enabled? end |
#include_chain_clauses_in_custom_matcher_descriptions? ⇒Boolean
指示自定义匹配器描述和失败消息是否应包含使用 chain
定义的方法中的子句。为了向后兼容,它默认情况下为 false。
145 146 147 |
# File 'lib/rspec/expectations/configuration.rb', line 145 def include_chain_clauses_in_custom_matcher_descriptions? @include_chain_clauses_in_custom_matcher_descriptions ||= false end |
#max_formatted_output_length=(length) ⇒Object
配置 RSpec 在格式化对象时将打印的最大字符长度。您可以将 length 设置为 nil 以防止 RSpec 进行截断。
70 71 72 |
# File 'lib/rspec/expectations/configuration.rb', line 70 def max_formatted_output_length=(length) RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = length end |
#strict_predicate_matchers? ⇒Boolean
199 200 201 |
# File 'lib/rspec/expectations/configuration.rb', line 199 def strict_predicate_matchers? @strict_predicate_matchers end |
#syntax ⇒Array<Symbol>
已配置语法的列表。
80 81 82 83 84 85 |
# File 'lib/rspec/expectations/configuration.rb', line 80 def syntax syntaxes = [] syntaxes << :should if Expectations::Syntax.should_enabled? syntaxes << :expect if Expectations::Syntax.expect_enabled? syntaxes end |
#syntax=(values) ⇒Object
配置支持的语法。
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rspec/expectations/configuration.rb', line 46 def syntax=(values) if Array(values).include?(:expect) Expectations::Syntax.enable_expect else Expectations::Syntax.disable_expect end if Array(values).include?(:should) Expectations::Syntax.enable_should else Expectations::Syntax.disable_should end end |
#warn_about_potential_false_positives=(boolean) ⇒Object
配置 RSpec 是否会警告可能导致测试中出现假阳性的匹配器使用情况。
168 169 170 171 172 173 174 175 176 |
# File 'lib/rspec/expectations/configuration.rb', line 168 def warn_about_potential_false_positives=(boolean) if boolean self.on_potential_false_positives = :warn elsif warn_about_potential_false_positives? self.on_potential_false_positives = :nothing else # no-op, handler is something else end end |
#warn_about_potential_false_positives? ⇒Boolean
指示 RSpec 是否会警告可能导致测试中出现假阳性的匹配器使用情况,通常您希望避免此类情况,因此默认为 true
。
211 212 213 |
# File 'lib/rspec/expectations/configuration.rb', line 211 def warn_about_potential_false_positives? on_potential_false_positives == :warn end |