[rspec-users] Evaluating shared example customisation block before shared block
Ashley Moran
ashley.moran at patchspace.co.uk
Sun Aug 1 18:12:40 EDT 2010
On 1 Aug 2010, at 3:43 PM, David Chelimsky wrote:
> shared_examples_for "blah" do |a,b|
> ...
> end
>
> it_should_behave_like "blah", 1, 2
>
> That wouldn't have worked with the old implementation, but it would work perfectly well now. This would also "just work" with hash-as-keyword-args:
>
> shared_examples_for "blah" do |options|
> it "blah #{options[:a]}" do
> ..
> end
> end
>
> it_should_behave_like "blah", :a => 1
>
> Now you can do this:
>
> [1,2,3].each do |n|
> it_should_behave_like "blah", :a => n
> end
>
> And we can still use the customization block to define methods, hooks (before/after) and let(). Now it just feels like the rest of RSpec.
>
> Thoughts?
One thought: me.facepalm :)
The only thing it lacks is a DSL to define the requirements. Would it still be desirable to be able to write:
shared_examples_for "blah" do |options|
require_argument options[:a]
it "blah #{options[:a]}" do
..
end
end
Or some such?
Also, after staring at this for a while, I'm puzzled by something. In this code:
it_should_behave_like "blah", :a => 1
how does :a => 1 get passed to the "options" block, as `shared_block` in the code is never called with arguments? Would this need another code change? (Apologies if I'm being thick, it's late and I should probably go to bed, but I wanted to review this first...)
Cheers
Ash
--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
More information about the rspec-users
mailing list