| Class | Spec::DSL::Configuration |
| In: |
lib/spec/dsl/configuration.rb
|
| Parent: | Object |
Appends a global after block to all behaviours. See append_before for filtering semantics.
# File lib/spec/dsl/configuration.rb, line 107
107: def append_after(*args, &proc)
108: Behaviour.append_after(*args, &proc)
109: end
Appends a global before block to all behaviours.
If you want to restrict the block to a subset of all the behaviours then specify this in a Hash as the last argument:
config.prepend_before(:all, :behaviour_type => :farm)
or
config.prepend_before(:behaviour_type => :farm)
# File lib/spec/dsl/configuration.rb, line 94
94: def append_before(*args, &proc)
95: Behaviour.append_before(*args, &proc)
96: end
Declares modules to be included in all behaviours (describe blocks).
config.include(My::Bottle, My::Cup)
If you want to restrict the inclusion to a subset of all the behaviours then specify this in a Hash as the last argument:
config.include(My::Pony, My::Horse, :behaviour_type => :farm)
Only behaviours that have that type will get the modules included:
describe "Downtown", :behaviour_type => :city do
# Will *not* get My::Pony and My::Horse included
end
describe "Old Mac Donald", :behaviour_type => :farm do
# *Will* get My::Pony and My::Horse included
end
# File lib/spec/dsl/configuration.rb, line 58
58: def include(*args)
59: included_modules.push(*args)
60: end
Chooses what mock framework to use. Example:
Spec::Runner.configure do |config|
config.mock_with :rspec # or :mocha, or :flexmock
end
To use any other mock framework, you‘ll have to provide your own adapter. This is simply a module that responds to setup_mocks_for_rspec, verify_mocks_for_rspec and 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
# File lib/spec/dsl/configuration.rb, line 26
26: def mock_with(mock_framework)
27: @mock_framework = case mock_framework
28: when Symbol
29: mock_framework_path(mock_framework.to_s)
30: else
31: mock_framework
32: end
33: end
Defines global predicate matchers. Example:
config.predicate_matchers[:swim] = :can_swim?
This makes it possible to say:
person.should swim # passes if person.should_swim? returns true
# File lib/spec/dsl/configuration.rb, line 74
74: def predicate_matchers
75: @predicate_matchers ||= {}
76: end
Prepends a global after block to all behaviours. See append_before for filtering semantics.
# File lib/spec/dsl/configuration.rb, line 101
101: def prepend_after(*args, &proc)
102: Behaviour.prepend_after(*args, &proc)
103: end
Prepends a global before block to all behaviours. See append_before for filtering semantics.
# File lib/spec/dsl/configuration.rb, line 80
80: def prepend_before(*args, &proc)
81: Behaviour.prepend_before(*args, &proc)
82: end