Class: Spec::Runner::Configuration
- Includes:
- Example::ArgsAndOptions
- Defined in:
- lib/spec/runner/configuration.rb
Instance Method Summary collapse
-
#append_after(scope = :each, options = {}, &proc) ⇒ Object
Appends a global
after
block to all example groups. -
#append_before(scope = :each, options = {}, &proc) ⇒ Object
(also: #before)
Appends a global
before
block to all example groups. -
#extend(*modules_and_options) ⇒ Object
:call-seq: extend(Some::Helpers) extend(Some::Helpers, More::Helpers) extend(My::Helpers, :type => :key).
-
#ignore_backtrace_patterns(*patterns) ⇒ Object
Adds patterns to the list of patterns ignored in the backtrace when a failure is output by rspec.
-
#ignored_backtrace_patterns ⇒ Object
:nodoc:.
-
#include(*modules_and_options) ⇒ Object
:call-seq: include(Some::Helpers) include(Some::Helpers, More::Helpers) include(My::Helpers, :type => :key).
-
#mock_framework ⇒ Object
:nodoc:.
-
#mock_with(mock_framework) ⇒ Object
Chooses what mock framework to use.
-
#predicate_matchers ⇒ Object
DEPRECATED - use Spec::Matchers::DSL instead.
-
#prepend_after(scope = :each, options = {}, &proc) ⇒ Object
(also: #after)
Prepends a global
after
block to all example groups. -
#prepend_before(scope = :each, options = {}, &proc) ⇒ Object
Prepends a global
before
block to all example groups. - #suppress_deprecation_warnings! ⇒ Object
- #suppress_deprecation_warnings? ⇒ Boolean
Methods included from Example::ArgsAndOptions
#add_options, #args_and_options, #set_location
Instance Method Details
#append_after(scope = :each, options = {}, &proc) ⇒ Object
Appends a global after
block to all example groups.
See append_before
for scoping semantics.
123 124 125 |
# File 'lib/spec/runner/configuration.rb', line 123 def append_after(scope = :each, ={}, &proc) add_callback(:append_after, scope, , &proc) end |
#append_before(scope = :each, options = {}, &proc) ⇒ Object Also known as: before
Appends a global before
block to all example groups. scope
can be any of :each
(default), :all
, or :suite
. When :each
, the block is executed before each example. When :all
, the block is executed once per example group, before any of its examples are run. When :suite
the block is run once before the entire suite is run.
100 101 102 |
# File 'lib/spec/runner/configuration.rb', line 100 def append_before(scope = :each, ={}, &proc) add_callback(:append_before, scope, , &proc) end |
#extend(*modules_and_options) ⇒ Object
:call-seq:
extend(Some::Helpers)
extend(Some::Helpers, More::Helpers)
extend(My::Helpers, :type => :key)
Works just like #include, but extends the example groups with the modules rather than including them.
90 91 92 |
# File 'lib/spec/runner/configuration.rb', line 90 def extend(*) include_or_extend(:extend, *) end |
#ignore_backtrace_patterns(*patterns) ⇒ Object
Adds patterns to the list of patterns ignored in the backtrace when a failure is output by rspec. Example:
config.ignore_backtrace_patterns /spork/, /shoulda/, "/some/weird/path/"
When quiet backtraces are turned on (default), this will exclude any lines that match any of the Regexps and Strings passed.
149 150 151 152 |
# File 'lib/spec/runner/configuration.rb', line 149 def ignore_backtrace_patterns(*patterns) @ignored_backtrace_patterns ||= [] @ignored_backtrace_patterns += patterns end |
#ignored_backtrace_patterns ⇒ Object
:nodoc:
154 155 156 |
# File 'lib/spec/runner/configuration.rb', line 154 def ignored_backtrace_patterns # :nodoc: @ignored_backtrace_patterns ||= [] end |
#include(*modules_and_options) ⇒ Object
:call-seq:
include(Some::Helpers)
include(Some::Helpers, More::Helpers)
include(My::Helpers, :type => :key)
Declares modules to be included in multiple example groups (describe
blocks). With no :type
, the modules listed will be included in all example groups.
Use :type
to restrict the inclusion to a subset of example groups. The value assigned to :type
should be a key that maps to a class that is either a subclass of Spec::Example::ExampleGroup or extends Spec::Example::ExampleGroupMethods and includes Spec::Example::ExampleMethods.
For example, the rspec-rails gem/plugin extends Test::Unit::TestCase with Spec::Example::ExampleGroupMethods and includes Spec::Example::ExampleMethods in it. So if you have a module of helper methods for controller examples, you could do this:
config.include(ControllerExampleHelpers, :type => :controller)
Only example groups that have that type will get the modules included:
describe Account, :type => :model do
# Will *not* include ControllerExampleHelpers
end
describe AccountsController, :type => :controller do
# *Will* include ControllerExampleHelpers
end
79 80 81 |
# File 'lib/spec/runner/configuration.rb', line 79 def include(*) include_or_extend(:include, *) end |
#mock_framework ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/spec/runner/configuration.rb', line 42 def mock_framework # :nodoc: @mock_framework ||= mock_framework_path("rspec") end |
#mock_with(mock_framework) ⇒ Object
Chooses what mock framework to use. Example:
Spec::Runner.configure do |config|
config.mock_with :rspec, :mocha, :flexmock, or :rr
end
To use any other mock framework, you’ll have to provide your own adapter. This is simply a module that responds to the following methods:
setup_mocks_for_rspec
verify_mocks_for_rspec
teardown_mocks_for_rspec.
These are your hooks into the lifecycle of a given example. RSpec will call setup_mocks_for_rspec before running anything else in each Example. After executing the #after methods, RSpec will then call verify_mocks_for_rspec and teardown_mocks_for_rspec (this is guaranteed to run even if there are failures in verify_mocks_for_rspec).
Once you’ve defined this module, you can pass that to mock_with:
Spec::Runner.configure do |config|
config.mock_with MyMockFrameworkAdapter
end
33 34 35 36 37 38 39 40 |
# File 'lib/spec/runner/configuration.rb', line 33 def mock_with(mock_framework) @mock_framework = case mock_framework when Symbol mock_framework_path(mock_framework.to_s) else mock_framework end end |
#predicate_matchers ⇒ Object
DEPRECATED - use Spec::Matchers::DSL instead
Defines global predicate matchers. Example:
config.predicate_matchers[:swim] = :can_swim?
This makes it possible to say:
person.should swim # passes if person.can_swim? returns true
137 138 139 |
# File 'lib/spec/runner/configuration.rb', line 137 def predicate_matchers @predicate_matchers ||= Spec::HashWithDeprecationNotice.new("predicate_matchers", "the new Matcher DSL") end |
#prepend_after(scope = :each, options = {}, &proc) ⇒ Object Also known as: after
Prepends a global after
block to all example groups.
See append_before
for scoping semantics.
115 116 117 |
# File 'lib/spec/runner/configuration.rb', line 115 def prepend_after(scope = :each, ={}, &proc) add_callback(:prepend_after, scope, , &proc) end |
#prepend_before(scope = :each, options = {}, &proc) ⇒ Object
Prepends a global before
block to all example groups.
See append_before
for scoping semantics.
108 109 110 |
# File 'lib/spec/runner/configuration.rb', line 108 def prepend_before(scope = :each, ={}, &proc) add_callback(:prepend_before, scope, , &proc) end |
#suppress_deprecation_warnings! ⇒ Object
158 159 160 |
# File 'lib/spec/runner/configuration.rb', line 158 def suppress_deprecation_warnings! @suppress_deprecation_warnings = true end |
#suppress_deprecation_warnings? ⇒ Boolean
162 163 164 |
# File 'lib/spec/runner/configuration.rb', line 162 def suppress_deprecation_warnings? @suppress_deprecation_warnings ||= false end |