Method: RSpec::Core::Configuration#add_setting

Defined in:
lib/rspec/core/configuration.rb

#add_setting(name, opts = {}) ⇒ Object

:call-seq:

add_setting(:name)
add_setting(:name, :default => "default_value")
add_setting(:name, :alias => :other_setting)

Use this to add custom settings to the RSpec.configuration object.

RSpec.configuration.add_setting :foo

Creates three methods on the configuration object, a setter, a getter, and a predicate:

RSpec.configuration.foo=(value)
RSpec.configuration.foo()
RSpec.configuration.foo?() # returns true if foo returns anything but nil or false

Intended for extension frameworks like rspec-rails, so they can add config settings that are domain specific. For example:

RSpec.configure do |c|
  c.add_setting :use_transactional_fixtures, :default => true
  c.add_setting :use_transactional_examples, :alias => :use_transactional_fixtures
end

Options

add_setting takes an optional hash that supports the following keys:

:default => "default value"

This sets the default value for the getter and the predicate (which will return true as long as the value is not false or nil).

:alias => :other_setting

Aliases its setter, getter, and predicate, to those for the other_setting.



112
113
114
# File 'lib/rspec/core/configuration.rb', line 112

def add_setting(name, opts={})
  self.class.add_setting(name, opts)
end