| |   |
| 7 | 7 | # config.mock_with :rspec, :mocha, :flexmock, or :rr |
| 8 | 8 | # end |
| 9 | 9 | # |
| 10 | | # To use any other mock framework, you'll have to provide |
| 11 | | # your own adapter. This is simply a module that responds to |
| 12 | | # setup_mocks_for_rspec, verify_mocks_for_rspec and teardown_mocks_for_rspec. |
| 10 | # To use any other mock framework, you'll have to provide your own |
| 11 | # adapter. This is simply a module that responds to the following |
| 12 | # methods: |
| 13 | # |
| 14 | # setup_mocks_for_rspec |
| 15 | # verify_mocks_for_rspec |
| 16 | # teardown_mocks_for_rspec. |
| 17 | # |
| 13 | 18 | # These are your hooks into the lifecycle of a given example. RSpec will |
| 14 | | # call setup_mocks_for_rspec before running anything else in each Example. |
| 15 | | # After executing the #after methods, RSpec will then call verify_mocks_for_rspec |
| 16 | | # and teardown_mocks_for_rspec (this is guaranteed to run even if there are |
| 17 | | # failures in verify_mocks_for_rspec). |
| 19 | # call setup_mocks_for_rspec before running anything else in each |
| 20 | # Example. After executing the #after methods, RSpec will then call |
| 21 | # verify_mocks_for_rspec and teardown_mocks_for_rspec (this is |
| 22 | # guaranteed to run even if there are failures in |
| 23 | # verify_mocks_for_rspec). |
| 18 | 24 | # |
| 19 | 25 | # Once you've defined this module, you can pass that to mock_with: |
| 20 | 26 | # |
| … | … | |
| 41 | 41 | @mock_framework ||= mock_framework_path("rspec") |
| 42 | 42 | end |
| 43 | 43 | |
| 44 | | # Declares modules to be included in all example groups (<tt>describe</tt> blocks). |
| 45 | | # |
| 46 | | # config.include(My::Bottle, My::Cup) |
| 47 | | # |
| 48 | | # If you want to restrict the inclusion to a subset of all the example groups then |
| 49 | | # specify this in a Hash as the last argument: |
| 44 | # :call-seq: |
| 45 | # include(Some::Helpers) |
| 46 | # include(Some::Helpers, More::Helpers) |
| 47 | # include(My::Helpers, :type => :key) |
| 48 | # |
| 49 | # Declares modules to be included in multiple example groups |
| 50 | # (<tt>describe</tt> blocks). With no :type, the modules listed will be |
| 51 | # included in all example groups. Use :type to restrict the inclusion to |
| 52 | # a subset of example groups. The value assigned to :type should be a |
| 53 | # key that maps to a class that is either a subclass of |
| 54 | # Spec::Example::ExampleGroup or extends Spec::Example::ExampleGroupMethods |
| 55 | # and includes Spec::Example::ExampleMethods |
| 50 | 56 | # |
| 51 | 57 | # config.include(My::Pony, My::Horse, :type => :farm) |
| 52 | 58 | # |
| … | … | |
| 82 | 82 | # |
| 83 | 83 | # This makes it possible to say: |
| 84 | 84 | # |
| 85 | | # person.should swim # passes if person.should_swim? returns true |
| 85 | # person.should swim # passes if person.can_swim? returns true |
| 86 | 86 | # |
| 87 | 87 | def predicate_matchers |
| 88 | 88 | @predicate_matchers ||= {} |
| … | … | |
| 97 | 97 | ) |
| 98 | 98 | example_group.prepend_before(scope, &proc) |
| 99 | 99 | end |
| 100 | |
| 100 | 101 | # Appends a global <tt>before</tt> block to all example groups. |
| 101 | 102 | # |
| 102 | | # If you want to restrict the block to a subset of all the example groups then |
| 103 | | # specify this in a Hash as the last argument: |
| 103 | # If you want to restrict the block to a subset of all the example |
| 104 | # groups then specify this in a Hash as the last argument: |
| 104 | 105 | # |
| 105 | 106 | # config.prepend_before(:all, :type => :farm) |
| 106 | 107 | # |
| … | … | |
| 128 | 128 | example_group.prepend_after(scope, &proc) |
| 129 | 129 | end |
| 130 | 130 | alias_method :after, :prepend_after |
| 131 | |
| 131 | 132 | # Appends a global <tt>after</tt> block to all example groups. |
| 132 | 133 | # See #append_before for filtering semantics. |
| 133 | 134 | def append_after(*args, &proc) |
| toggle raw diff |
--- a/rspec/lib/spec/example/configuration.rb
+++ b/rspec/lib/spec/example/configuration.rb
@@ -7,14 +7,20 @@ module Spec
# 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.
+ # 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).
+ # 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:
#
@@ -35,12 +41,18 @@ module Spec
@mock_framework ||= mock_framework_path("rspec")
end
- # Declares modules to be included in all example groups (<tt>describe</tt> 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:
+ # :call-seq:
+ # include(Some::Helpers)
+ # include(Some::Helpers, More::Helpers)
+ # include(My::Helpers, :type => :key)
+ #
+ # Declares modules to be included in multiple example groups
+ # (<tt>describe</tt> 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)
#
@@ -70,7 +82,7 @@ module Spec
#
# This makes it possible to say:
#
- # person.should swim # passes if person.should_swim? returns true
+ # person.should swim # passes if person.can_swim? returns true
#
def predicate_matchers
@predicate_matchers ||= {}
@@ -85,10 +97,11 @@ module Spec
)
example_group.prepend_before(scope, &proc)
end
+
# Appends a global <tt>before</tt> 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:
+ # 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)
#
@@ -115,6 +128,7 @@ module Spec
example_group.prepend_after(scope, &proc)
end
alias_method :after, :prepend_after
+
# Appends a global <tt>after</tt> block to all example groups.
# See #append_before for filtering semantics.
def append_after(*args, &proc) |
| |   |
| 7 | 7 | default(ExampleGroup) |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | | # Registers an example group class +klass+ with the symbol |
| 11 | | # +type+. For example: |
| 10 | # Registers an example group class +klass+ with the symbol +type+. For |
| 11 | # example: |
| 12 | 12 | # |
| 13 | | # Spec::Example::ExampleGroupFactory.register(:farm, Spec::Farm::Example::FarmExampleGroup) |
| 13 | # Spec::Example::ExampleGroupFactory.register(:farm, FarmExampleGroup) |
| 14 | 14 | # |
| 15 | | # This will cause Main#describe from a file living in |
| 16 | | # <tt>spec/farm</tt> to create example group instances of type |
| 17 | | # Spec::Farm::Example::FarmExampleGroup. |
| 18 | | def register(id, example_group_class) |
| 19 | | @example_group_types[id] = example_group_class |
| 15 | # With that you can append a hash with :type => :farm to the describe |
| 16 | # method and it will load an instance of FarmExampleGroup. |
| 17 | # |
| 18 | # describe Pig, :type => :farm do |
| 19 | # ... |
| 20 | # |
| 21 | # If you don't use the hash explicitly, <tt>describe</tt> will |
| 22 | # implicitly use an instance of FarmExampleGroup for any file loaded |
| 23 | # from the <tt>./spec/farm</tt> directory. |
| 24 | def register(key, example_group_class) |
| 25 | @example_group_types[key] = example_group_class |
| 20 | 26 | end |
| 21 | 27 | |
| 22 | 28 | # Sets the default ExampleGroup class |
| … | … | |
| 32 | 32 | @example_group_types.merge!(old) if old |
| 33 | 33 | end |
| 34 | 34 | |
| 35 | | def get(id=nil) |
| 36 | | if @example_group_types.values.include?(id) |
| 37 | | id |
| 35 | def get(key=nil) |
| 36 | if @example_group_types.values.include?(key) |
| 37 | key |
| 38 | 38 | else |
| 39 | | @example_group_types[id] |
| 39 | @example_group_types[key] |
| 40 | 40 | end |
| 41 | 41 | end |
| 42 | 42 | |
| … | … | |
| 49 | 49 | protected |
| 50 | 50 | |
| 51 | 51 | def determine_superclass(opts) |
| 52 | | id = if opts[:type] |
| 52 | key = if opts[:type] |
| 53 | 53 | opts[:type] |
| 54 | 54 | elsif opts[:spec_path] =~ /spec(\\|\/)(#{@example_group_types.keys.join('|')})/ |
| 55 | 55 | $2 == '' ? nil : $2.to_sym |
| 56 | 56 | end |
| 57 | | get(id) |
| 57 | get(key) |
| 58 | 58 | end |
| 59 | 59 | |
| 60 | 60 | end |
| toggle raw diff |
--- a/rspec/lib/spec/example/example_group_factory.rb
+++ b/rspec/lib/spec/example/example_group_factory.rb
@@ -7,16 +7,22 @@ module Spec
default(ExampleGroup)
end
- # Registers an example group class +klass+ with the symbol
- # +type+. For example:
+ # Registers an example group class +klass+ with the symbol +type+. For
+ # example:
#
- # Spec::Example::ExampleGroupFactory.register(:farm, Spec::Farm::Example::FarmExampleGroup)
+ # Spec::Example::ExampleGroupFactory.register(:farm, FarmExampleGroup)
#
- # This will cause Main#describe from a file living in
- # <tt>spec/farm</tt> to create example group instances of type
- # Spec::Farm::Example::FarmExampleGroup.
- def register(id, example_group_class)
- @example_group_types[id] = example_group_class
+ # With that you can append a hash with :type => :farm to the describe
+ # method and it will load an instance of FarmExampleGroup.
+ #
+ # describe Pig, :type => :farm do
+ # ...
+ #
+ # If you don't use the hash explicitly, <tt>describe</tt> will
+ # implicitly use an instance of FarmExampleGroup for any file loaded
+ # from the <tt>./spec/farm</tt> directory.
+ def register(key, example_group_class)
+ @example_group_types[key] = example_group_class
end
# Sets the default ExampleGroup class
@@ -26,11 +32,11 @@ module Spec
@example_group_types.merge!(old) if old
end
- def get(id=nil)
- if @example_group_types.values.include?(id)
- id
+ def get(key=nil)
+ if @example_group_types.values.include?(key)
+ key
else
- @example_group_types[id]
+ @example_group_types[key]
end
end
@@ -43,12 +49,12 @@ module Spec
protected
def determine_superclass(opts)
- id = if opts[:type]
+ key = if opts[:type]
opts[:type]
elsif opts[:spec_path] =~ /spec(\\|\/)(#{@example_group_types.keys.join('|')})/
$2 == '' ? nil : $2.to_sym
end
- get(id)
+ get(key)
end
end |