class RSpec::Expectations::Configuration
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.
@example
RSpec.configure do |rspec| rspec.expect_with :rspec do |c| # c is the config object end end # or RSpec::Expectations.configuration
Constants
- FALSE_POSITIVE_BEHAVIOURS
-
@private
- NullBacktraceFormatter
-
@api private Null implementation of a backtrace formatter used by default when rspec-core is not loaded. Does no filtering.
Attributes
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).
@!attribute [rw] backtrace_formatter
Configures what RSpec will do about matcher use which would potentially cause false positives in tests. Defaults to ‘:warn` since this is generally the desired behavior, but can also be set to `:raise` or `:nothing`.
@overload on_potential_false_positives
@return [Symbol] the behavior setting
@overload on_potential_false_positives=(value)
@param [Symbol] behavior can be set to `:warn`, `:raise` or `:nothing` @return [Symbol] the behavior setting
Configures RSpec to check predicate matchers to ‘be(true)` / `be(false)` (strict), or `be_truthy` / `be_falsey` (not strict). Historically, the default was `false`, but `true` is recommended.
@overload strict_predicate_matchers
@return [Boolean]
@overload strict_predicate_matchers?
@return [Boolean]
@overload strict_predicate_matchers=(value)
@param [Boolean] value
Public Class Methods
# File rspec-expectations/lib/rspec/expectations/configuration.rb, line 29 def initialize @on_potential_false_positives = :warn @strict_predicate_matchers = true end
Public Instance Methods
# File rspec-expectations/lib/rspec/expectations/configuration.rb, line 79 def backtrace_formatter @backtrace_formatter ||= if defined?(::RSpec.configuration.backtrace_formatter) ::RSpec.configuration.backtrace_formatter else NullBacktraceFormatter end end
# File rspec-expectations/lib/rspec/expectations/configuration.rb, line 49 def color? ::RSpec.configuration.color_enabled? end
@private
# File rspec-expectations/lib/rspec/expectations/configuration.rb, line 136 def false_positives_handler FALSE_POSITIVE_BEHAVIOURS.fetch(@on_potential_false_positives) end
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. @param [Fixnum] length the number of characters to limit the formatted output to. @example
RSpec.configure do |rspec| rspec.expect_with :rspec do |c| c.max_formatted_output_length = 200 end end
# File rspec-expectations/lib/rspec/expectations/configuration.rb, line 44 def max_formatted_output_length=(length) RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = length end
# File rspec-expectations/lib/rspec/expectations/configuration.rb, line 107 def on_potential_false_positives=(behavior) unless FALSE_POSITIVE_BEHAVIOURS.key?(behavior) raise ArgumentError, "Supported values are: #{FALSE_POSITIVE_BEHAVIOURS.keys}" end @on_potential_false_positives = behavior end
# File rspec-expectations/lib/rspec/expectations/configuration.rb, line 126 def strict_predicate_matchers=(value) raise ArgumentError, "Pass `true` or `false`" unless value == true || value == false @strict_predicate_matchers = value end
# File rspec-expectations/lib/rspec/expectations/configuration.rb, line 131 def strict_predicate_matchers? @strict_predicate_matchers end