| Class | Spec::Example::Configuration |
| In: |
lib/spec/example/configuration.rb
|
| Parent: | Object |
Appends a global after block to all example groups. See append_before for filtering semantics.
# File lib/spec/example/configuration.rb, line 120
120: def append_after(*args, &proc)
121: scope, options = scope_and_options(*args)
122: example_group = ExampleGroupFactory.get(
123: get_type_from_options(options)
124: )
125: example_group.append_after(scope, &proc)
126: end
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)
# File lib/spec/example/configuration.rb, line 99
99: def append_before(*args, &proc)
100: scope, options = scope_and_options(*args)
101: example_group = ExampleGroupFactory.get(
102: get_type_from_options(options)
103: )
104: example_group.append_before(scope, &proc)
105: end
Declares modules to be included in all example groups (describe blocks).
config.include(My::Bottle, My::Cup)
If you want to restrict the inclusion to a subset of all the example groups then specify this in a Hash as the last argument:
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
# File lib/spec/example/configuration.rb, line 57
57: def include(*args)
58: args << {} unless Hash === args.last
59: modules, options = args_and_options(*args)
60: required_example_group = get_type_from_options(options)
61: required_example_group = required_example_group.to_sym if required_example_group
62: modules.each do |mod|
63: ExampleGroupFactory.get(required_example_group).send(:include, mod)
64: end
65: end
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 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/example/configuration.rb, line 25
25: def mock_with(mock_framework)
26: @mock_framework = case mock_framework
27: when Symbol
28: mock_framework_path(mock_framework.to_s)
29: else
30: mock_framework
31: end
32: 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/example/configuration.rb, line 75
75: def predicate_matchers
76: @predicate_matchers ||= {}
77: end
Prepends a global after block to all example groups. See append_before for filtering semantics.
# File lib/spec/example/configuration.rb, line 110
110: def prepend_after(*args, &proc)
111: scope, options = scope_and_options(*args)
112: example_group = ExampleGroupFactory.get(
113: get_type_from_options(options)
114: )
115: example_group.prepend_after(scope, &proc)
116: end
Prepends a global before block to all example groups. See append_before for filtering semantics.
# File lib/spec/example/configuration.rb, line 81
81: def prepend_before(*args, &proc)
82: scope, options = scope_and_options(*args)
83: example_group = ExampleGroupFactory.get(
84: get_type_from_options(options)
85: )
86: example_group.prepend_before(scope, &proc)
87: end