Class: RSpec::Matchers::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/matchers/configuration.rb

Overview

Provides configuration options for rspec-expectations.

Constant Summary collapse

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.

Module.new do
  def self.format_backtrace(backtrace)
    backtrace
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backtrace_formatterObject



82
83
84
85
86
87
88
# File 'lib/rspec/matchers/configuration.rb', line 82

def backtrace_formatter
  @backtrace_formatter ||= if defined?(::RSpec::Core::BacktraceFormatter)
    ::RSpec::Core::BacktraceFormatter
  else
    NullBacktraceFormatter
  end
end

#color=(value) ⇒ Object (writeonly)

Sets the attribute color

Parameters:

  • value

    the value to set the attribute color to.



49
50
51
# File 'lib/rspec/matchers/configuration.rb', line 49

def color=(value)
  @color = value
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).

Parameters:

  • modules (Array<Module>)

    the list of classes or modules to add should and should_not to.



62
63
64
65
66
# File 'lib/rspec/matchers/configuration.rb', line 62

def add_should_and_should_not_to(*modules)
  modules.each do |mod|
    Expectations::Syntax.enable_should(mod)
  end
end

#color?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/rspec/matchers/configuration.rb', line 45

def color?
  ::RSpec.configuration.color_enabled?
end

#syntaxArray<Symbol>

The list of configured syntaxes.

Returns:

  • (Array<Symbol>)

    the list of configured syntaxes.



35
36
37
38
39
40
# File 'lib/rspec/matchers/configuration.rb', line 35

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.

Examples:

RSpec.configure do |rspec|
  rspec.expect_with :rspec do |c|
    c.syntax = :should
    # or
    c.syntax = :expect
    # or
    c.syntax = [:should, :expect]
  end
end

Parameters:

  • values (Array<Symbol>, Symbol)

    the syntaxes to enable



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rspec/matchers/configuration.rb', line 19

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