Class: RSpec::Expectations::Configuration
- Inherits:
-
Object
- Object
- RSpec::Expectations::Configuration
- Defined in:
- lib/rspec/expectations/configuration.rb
Overview
Provides configuration options for rspec-expectations.
If you are using rspec-core, you can access this via a
block passed to RSpec::Core::Configuration#expect_with
.
Otherwise, you can access it via RSpec::Expectations.configuration.
Constant Summary
- NullBacktraceFormatter =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Null implementation of a backtrace formatter used by default when rspec-core is not loaded. Does no filtering.
Module.new do def self.format_backtrace(backtrace) backtrace end end
Instance Attribute Summary (collapse)
-
- (Object) backtrace_formatter
Sets or gets the backtrace formatter.
-
- (Object) color
writeonly
Indicates whether or not diffs should be colored.
-
- (Object) include_chain_clauses_in_custom_matcher_descriptions
writeonly
Sets if custom matcher descriptions and failure messages should include clauses from methods defined using
chain
. -
- (Object) warn_about_potential_false_positives
writeonly
Configures whether RSpec will warn about matcher use which will potentially cause false positives in tests.
Instance Method Summary (collapse)
-
- (Object) add_should_and_should_not_to(*modules)
Adds
should
andshould_not
to the given classes or modules. -
- (Boolean) color?
Indicates whether or not diffs should be colored.
-
- (Boolean) include_chain_clauses_in_custom_matcher_descriptions?
Indicates whether or not custom matcher descriptions and failure messages should include clauses from methods defined using
chain
. -
- (Configuration) initialize
constructor
A new instance of Configuration.
-
- (Array<Symbol>) syntax
The list of configured syntaxes.
-
- (Object) syntax=(values)
Configures the supported syntax.
-
- (Boolean) warn_about_potential_false_positives?
Indicates whether RSpec will warn about matcher use which will potentially cause false positives in tests, generally you want to avoid such scenarios so this defaults to
true
.
Constructor Details
- (Configuration) initialize
Returns a new instance of Configuration
21 22 23 |
# File 'lib/rspec/expectations/configuration.rb', line 21 def initialize @warn_about_potential_false_positives = true end |
Instance Attribute Details
- (Object) backtrace_formatter
Sets or gets the backtrace formatter. The backtrace formatter should
implement #format_backtrace(Array<String>)
. This is used
to format backtraces of errors handled by the raise_error
matcher.
If you are using rspec-core, rspec-core's backtrace formatting
will be used (including respecting the presence or absence of
the --backtrace
option).
105 |
# File 'lib/rspec/expectations/configuration.rb', line 105 attr_writer :backtrace_formatter |
- (Object) color=(value) (writeonly)
Indicates whether or not diffs should be colored. Delegates to rspec-core's color option if rspec-core is loaded; otherwise you can set it here.
72 73 74 |
# File 'lib/rspec/expectations/configuration.rb', line 72 def color=(value) @color = value end |
- (Object) include_chain_clauses_in_custom_matcher_descriptions=(value) (writeonly)
Sets if custom matcher descriptions and failure messages
should include clauses from methods defined using chain
.
117 118 119 |
# File 'lib/rspec/expectations/configuration.rb', line 117 def include_chain_clauses_in_custom_matcher_descriptions=(value) @include_chain_clauses_in_custom_matcher_descriptions = value end |
- (Object) warn_about_potential_false_positives=(value) (writeonly)
Configures whether RSpec will warn about matcher use which will potentially cause false positives in tests.
145 146 147 |
# File 'lib/rspec/expectations/configuration.rb', line 145 def warn_about_potential_false_positives=(value) @warn_about_potential_false_positives = value end |
Instance Method Details
- (Object) add_should_and_should_not_to(*modules)
Adds should
and should_not
to the given classes
or modules. This can be used to ensure should
works
properly on things like proxy objects (particular
Delegator
-subclassed objects on 1.8).
89 90 91 92 93 |
# File 'lib/rspec/expectations/configuration.rb', line 89 def add_should_and_should_not_to(*modules) modules.each do |mod| Expectations::Syntax.enable_should(mod) end end |
- (Boolean) color?
Indicates whether or not diffs should be colored. Delegates to rspec-core's color option if rspec-core is loaded; otherwise you can set it here.
77 78 79 |
# File 'lib/rspec/expectations/configuration.rb', line 77 def color? ::RSpec.configuration.color_enabled? end |
- (Boolean) include_chain_clauses_in_custom_matcher_descriptions?
Indicates whether or not custom matcher descriptions and failure messages
should include clauses from methods defined using chain
. It is
false by default for backwards compatibility.
122 123 124 |
# File 'lib/rspec/expectations/configuration.rb', line 122 def include_chain_clauses_in_custom_matcher_descriptions? @include_chain_clauses_in_custom_matcher_descriptions ||= false end |
- (Array<Symbol>) syntax
The list of configured syntaxes.
57 58 59 60 61 62 |
# File 'lib/rspec/expectations/configuration.rb', line 57 def syntax syntaxes = [] syntaxes << :should if Expectations::Syntax.should_enabled? syntaxes << :expect if Expectations::Syntax.expect_enabled? syntaxes end |
- (Object) syntax=(values)
Configures the supported syntax.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rspec/expectations/configuration.rb', line 37 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 |
- (Boolean) warn_about_potential_false_positives?
Indicates whether RSpec will warn about matcher use which will
potentially cause false positives in tests, generally you want to
avoid such scenarios so this defaults to true
.
150 151 152 |
# File 'lib/rspec/expectations/configuration.rb', line 150 def warn_about_potential_false_positives? @warn_about_potential_false_positives end |