[rspec-users] Evaluating shared example customisation block before shared block

Ashley Moran ashley.moran at patchspace.co.uk
Fri Jul 30 11:57:52 EDT 2010

On Jul 30, 2010, at 3:10 pm, David Chelimsky wrote:

> Maybe that, or a DSL that wraps that, is the better way, so we can get the best of both worlds?
> shared_examples_for Enumerable do
>  require_instance_method :foo, "gotta have foo instance method"
>  require_class_method :foo, "gotta have foo class method"
>  require_instance_variable "@foo", "gotta have an instance variable named @foo"
>  it "..." { .. }
> end
> Thoughts?

Actually, I *much* prefer this, as it makes it explicit what the host spec must provide in order to have the shared behaviour.  (Wincent's email has just popped up so consider this a response to his message too.)  I lean towards making things fail as early and explicitly as possible, as it reduces the total worldwide developer head-scratching time.  InvalidSharedExampleUsageError("Must provide instance method :foo") or some such wins for me over NoMethodError("undefined method foo on <#Class ...>").  There should be no _requirement_ to use this DSL though, so the key would be to make sure it doesn't muddy the RSpec code.

This is probably something that could be solved in code quicker than debate.  It's a yak I'm happy to shave before getting back to my own project as it impacts what I'm working on ... want me to have a look at it this evening, David?  I can fork rspec-core and play around with the idea.



More information about the rspec-users mailing list