Class: RSpec::Expectations::Configuration
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/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 collapse
- FALSE_POSITIVE_BEHAVIOURS =
{ :warn => lambda { || RSpec.warning }, :raise => lambda { || raise ArgumentError, }, :nothing => lambda { |_| true }, }
- 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
-
#backtrace_formatter ⇒ Object
Sets or gets the backtrace formatter.
-
#color ⇒ Object
writeonly
Indicates whether or not diffs should be colored.
-
#include_chain_clauses_in_custom_matcher_descriptions ⇒ Object
writeonly
Sets if custom matcher descriptions and failure messages should include clauses from methods defined using ‘chain`.
-
#on_potential_false_positives ⇒ Object
Indicates what RSpec will do about matcher use which will potentially cause false positives in tests, generally you want to avoid such scenarios so this defaults to ‘true`.
-
#strict_predicate_matchers ⇒ Object
Returns the value of attribute strict_predicate_matchers.
Instance Method Summary collapse
-
#add_should_and_should_not_to(*modules) ⇒ Object
Adds ‘should` and `should_not` to the given classes or modules.
-
#color? ⇒ Boolean
Indicates whether or not diffs should be colored.
- #false_positives_handler ⇒ Object
-
#include_chain_clauses_in_custom_matcher_descriptions? ⇒ Boolean
Indicates whether or not custom matcher descriptions and failure messages should include clauses from methods defined using ‘chain`.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#max_formatted_output_length=(length) ⇒ Object
Configures the maximum character length that RSpec will print while formatting an object.
- #reset_syntaxes_to_default ⇒ Object
- #strict_predicate_matchers? ⇒ Boolean
-
#syntax ⇒ Array<Symbol>
The list of configured syntaxes.
-
#syntax=(values) ⇒ Object
Configures the supported syntax.
-
#warn_about_potential_false_positives=(boolean) ⇒ Object
Configures whether RSpec will warn about matcher use which will potentially cause false positives in tests.
-
#warn_about_potential_false_positives? ⇒ Boolean
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
#initialize ⇒ Configuration
Returns a new instance of Configuration.
29 30 31 32 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 29 def initialize @on_potential_false_positives = :warn @strict_predicate_matchers = false end |
Instance Attribute Details
#backtrace_formatter ⇒ Object
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).
128 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 128 attr_writer :backtrace_formatter |
#color=(value) ⇒ Object (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.
95 96 97 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 95 def color=(value) @color = value end |
#include_chain_clauses_in_custom_matcher_descriptions=(value) ⇒ Object (writeonly)
Sets if custom matcher descriptions and failure messages should include clauses from methods defined using ‘chain`.
140 141 142 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/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
Indicates what RSpec will do about matcher use which will potentially cause false positives in tests, generally you want to avoid such scenarios so this defaults to ‘true`.
206 207 208 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 206 def on_potential_false_positives @on_potential_false_positives end |
#strict_predicate_matchers ⇒ Object
Returns the value of attribute strict_predicate_matchers.
197 198 199 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 197 def strict_predicate_matchers @strict_predicate_matchers end |
Instance Method Details
#add_should_and_should_not_to(*modules) ⇒ Object
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).
112 113 114 115 116 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/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
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.
100 101 102 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 100 def color? ::RSpec.configuration.color_enabled? end |
#false_positives_handler ⇒ Object
216 217 218 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 216 def false_positives_handler FALSE_POSITIVE_BEHAVIOURS.fetch(@on_potential_false_positives) end |
#include_chain_clauses_in_custom_matcher_descriptions? ⇒ Boolean
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.
145 146 147 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/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
Configures the maximum character length that RSpec will print while formatting an object. You can set length to nil to prevent RSpec from doing truncation.
70 71 72 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 70 def max_formatted_output_length=(length) RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = length end |
#reset_syntaxes_to_default ⇒ Object
150 151 152 153 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 150 def reset_syntaxes_to_default self.syntax = [:should, :expect] RSpec::Expectations::Syntax.warn_about_should! end |
#strict_predicate_matchers? ⇒ Boolean
199 200 201 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 199 def strict_predicate_matchers? @strict_predicate_matchers end |
#syntax ⇒ Array<Symbol>
The list of configured syntaxes.
80 81 82 83 84 85 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/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
Configures the supported syntax.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/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
Configures whether RSpec will warn about matcher use which will potentially cause false positives in tests.
168 169 170 171 172 173 174 175 176 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/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
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`.
211 212 213 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/configuration.rb', line 211 def warn_about_potential_false_positives? on_potential_false_positives == :warn end |