Class: Spec::Example::Configuration
- Defined in:
- lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb
Instance Method Summary collapse
-
#append_after(*args, &proc) ⇒ Object
Appends a global
after
block to all example groups. -
#append_before(*args, &proc) ⇒ Object
(also: #before)
Appends a global
before
block to all example groups. - #extend(*args) ⇒ Object
-
#include(*args) ⇒ Object
:call-seq: include(Some::Helpers) include(Some::Helpers, More::Helpers) include(My::Helpers, :type => :key).
- #include_or_extend(*args) ⇒ Object
-
#mock_framework ⇒ Object
:nodoc:.
-
#mock_with(mock_framework) ⇒ Object
Chooses what mock framework to use.
-
#predicate_matchers ⇒ Object
Defines global predicate matchers.
-
#prepend_after(*args, &proc) ⇒ Object
(also: #after)
Prepends a global
after
block to all example groups. -
#prepend_before(*args, &proc) ⇒ Object
Prepends a global
before
block to all example groups.
Instance Method Details
#append_after(*args, &proc) ⇒ Object
Appends a global after
block to all example groups. See #append_before for filtering semantics.
143 144 145 146 147 148 149 |
# File 'lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb', line 143 def append_after(*args, &proc) scope, = (*args) example_group = ExampleGroupFactory.get( () ) example_group.append_after(scope, &proc) end |
#append_before(*args, &proc) ⇒ Object Also known as: before
Appends a global before
block to all example groups.
If you want to restrict the block to a subset of all the example groups then specify this in a Hash as the last argument:
config.prepend_before(:all, :type => :farm)
or
config.prepend_before(:type => :farm)
121 122 123 124 125 126 127 |
# File 'lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb', line 121 def append_before(*args, &proc) scope, = (*args) example_group = ExampleGroupFactory.get( () ) example_group.append_before(scope, &proc) end |
#extend(*args) ⇒ Object
73 74 75 |
# File 'lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb', line 73 def extend(*args) include_or_extend(:extend, *args) end |
#include(*args) ⇒ 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
config.include(My::Pony, My::Horse, :type => :farm)
Only example groups that have that type will get the modules included:
describe "Downtown", :type => :city do
# Will *not* get My::Pony and My::Horse included
end
describe "Old Mac Donald", :type => :farm do
# *Will* get My::Pony and My::Horse included
end
69 70 71 |
# File 'lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb', line 69 def include(*args) include_or_extend(:include, *args) end |
#include_or_extend(*args) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb', line 77 def include_or_extend(*args) action = args.shift args << {} unless Hash === args.last modules, = (*args) required_example_group = () required_example_group = required_example_group.to_sym if required_example_group modules.each do |mod| ExampleGroupFactory.get(required_example_group).send(action, mod) end end |
#mock_framework ⇒ Object
:nodoc:
40 41 42 |
# File 'lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb', line 40 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
31 32 33 34 35 36 37 38 |
# File 'lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb', line 31 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
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
96 97 98 |
# File 'lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb', line 96 def predicate_matchers @predicate_matchers ||= {} end |
#prepend_after(*args, &proc) ⇒ Object Also known as: after
Prepends a global after
block to all example groups. See #append_before for filtering semantics.
132 133 134 135 136 137 138 |
# File 'lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb', line 132 def prepend_after(*args, &proc) scope, = (*args) example_group = ExampleGroupFactory.get( () ) example_group.prepend_after(scope, &proc) end |
#prepend_before(*args, &proc) ⇒ Object
Prepends a global before
block to all example groups. See #append_before for filtering semantics.
102 103 104 105 106 107 108 |
# File 'lib/gems/rspec-1.1.11/lib/spec/example/configuration.rb', line 102 def prepend_before(*args, &proc) scope, = (*args) example_group = ExampleGroupFactory.get( () ) example_group.prepend_before(scope, &proc) end |