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

Ashley Moran ashley.moran at patchspace.co.uk
Wed Aug 4 04:22:47 EDT 2010

On 4 Aug 2010, at 1:05 AM, David Chelimsky wrote:

> I actually like contract a lot. Maybe we'll need alias_shared_examples_for_to :)

Haha, actually that gets +1 from me!  Should I file a ticket? :)

In general I like contract, I just wasn't sure it was the right word for this usage of shared examples.

Maybe I just need to reword the shared examples, to write something like this:

  it_satisfies_contract "container of", :children, :child, Child.name

(Obviously, if I had an inflection library in place, you could drop the last 2 args)

> This is just Ruby. It bugged me for a while too, but mostly because I kept forgetting. Now I'm completely accustomed to it and def and define_method seem quite the same to me.

Maybe.  Perhaps then Ruby needs a neater closure-based method syntax eg:

  foo = 1

  defc my_method(bar)
    foo + bar

or some such...

> This was a mis-alignment between names in the group and its examples (example_group.describes == example.described_class), but is now fixed (you can refer to described_class in both cases):http://github.com/rspec/rspec-core/commit/b236a8d8927da108097fed7982d1450e4701939d

Works for me! Ta :)

> shared_examples_for "foo" do
>  raise "gotta define entity_class" unless public_instance_methods.map{|m|m.to_s).include?("entity_class")
> end

Aye, I guess I'm just in love with DSLs...

If I feel the need I might write a simple DSL and see if it's worth it.

>> And also, if it's defined as a `let` in the host, you can't use it in the descriptions in the shared example group (which you couldn't before, of course).
> Right - the only thing available to descriptions is going to be the params you pass in.

I have a feeling this will cause a misalignment, but maybe not.  I'll work through some more practical examples and see how it plays out.

BTW any idea when the next beta will go out, so that this is in a released gem?  I've got it working, but I had no luck using Bundler's :path option so I ended up having to build and install the gems into my project gemset.  That's probably just a RubyGems/Bundler issue though.



More information about the rspec-users mailing list