Permalink
Browse files

`include_examples` and `include_context` now accept a customization b…

…lock.

- Closes #615.
  • Loading branch information...
1 parent f87dfbf commit 092a9c663a0bcdaf0c02ce8babb52549a83c7976 @dchelimsky dchelimsky committed Jun 4, 2012
Showing with 21 additions and 17 deletions.
  1. +8 −13 lib/rspec/core/example_group.rb
  2. +13 −4 spec/rspec/core/example_group_spec.rb
@@ -138,26 +138,21 @@ def alias_it_behaves_like_to name, *args, &block
end
# Includes shared content mapped to `name` directly in the group in which
- # it is declared. Unlike `it_behaves_like`, this does not create a nested
- # example group, nor does it accept a block.
+ # it is declared, as opposed to `it_behaves_like`, which creates a nested
+ # group. If given a block, that block is also eval'd in the current context.
#
# @see SharedExampleGroup
- def self.include_context(name, *args)
- block_given? ? block_not_supported("context") : find_and_eval_shared("context", name, *args)
+ def self.include_context(name, *args, &block)
+ find_and_eval_shared("context", name, *args, &block)
end
# Includes shared content mapped to `name` directly in the group in which
- # it is declared. Unlike `it_behaves_like`, this does not create a nested
- # example group, nor does it accept a block.
+ # it is declared, as opposed to `it_behaves_like`, which creates a nested
+ # group. If given a block, that block is also eval'd in the current context.
#
# @see SharedExampleGroup
- def self.include_examples(name, *args)
- block_given? ? block_not_supported("examples") : find_and_eval_shared("examples", name, *args)
- end
-
- # @private
- def self.block_not_supported(label)
- warn("Customization blocks not supported for include_#{label}. Use it_behaves_like instead.")
+ def self.include_examples(name, *args, &block)
+ find_and_eval_shared("examples", name, *args, &block)
end
# @private
@@ -970,10 +970,19 @@ def foo; end
eval_count.should eq(1)
end
- it "warns the user that blocks are not supported when given a block" do
- group = ExampleGroup.describe
- group.should_receive(:warn).with(/blocks not supported for #{name}/)
- group.send(name, "named this with block") {}
+ it "evals the block when given" do
+ key = "#{__FILE__}:#{__LINE__}"
+ shared_examples(key) do
+ it("does something") do
+ foo.should eq("bar")
+ end
+ end
+ group = ExampleGroup.describe do
+ send name, key do
+ def foo; "bar"; end
+ end
+ end
+ group.run.should be_true
end
end
end

0 comments on commit 092a9c6

Please sign in to comment.