Class | RSpec::Core::Configuration |
In: |
lib/rspec/core/configuration.rb
|
Parent: | Object |
CONDITIONAL_FILTERS | = | { :if => lambda { |value, metadata| metadata.has_key?(:if) && !value }, :unless => lambda { |value| value } |
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
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.
E.g. alias_example_to :crazy_slow, :speed => ‘crazy_slow’ defines crazy_slow as an example variant that has the crazy_slow speed option
Define an alias for it_should_behave_like that allows different language (like "it_has_behavior" or "it_behaves_like") to be employed when including shared examples.
alias_it_should_behave_like_to(:it_has_behavior, 'has behavior:')
allows the user to include a shared example group like:
describe Entity do it_has_behavior 'sortability' do let(:sortable) { Entity.new } end end
which is reported in the output as:
Entity has behavior: sortability # sortability examples here
Sets the expectation framework module(s).
frameworks can be :rspec, :stdlib, or both
Given :rspec, configures rspec/expectations. Given :stdlib, configures test/unit/assertions Given both, configures both
Sets the mock framework adapter module.
framework can be a Symbol or a Module.
Given any of :rspec, :mocha, :flexmock, or :rr, configures the named framework.
Given :nothing, configures no framework. Use this if you don‘t use any mocking framework to save a little bit of overhead.
Given a Module, includes that module in every example group. The module should adhere to RSpec‘s mock framework adapter API:
setup_mocks_for_rspec - called before each example verify_mocks_for_rspec - called after each example. Framework should raise an exception when expectations fail teardown_mocks_for_rspec - called after verify_mocks_for_rspec (even if there are errors)