[rspec-users] Interesting shared behaviour side-effect
David Chelimsky
dchelimsky at gmail.com
Sun Oct 21 06:47:21 EDT 2007
On 10/21/07, Wincent Colaiuta <win at wincent.com> wrote:
> Given the following ApplicationController specs:
>
> describe ApplicationController, "one facet", :shared => true do
> it 'foo' ...
> it 'bar' ...
> end
>
> describe ApplicationController, "some other facet", :shared =>
> true do
> it 'abc' ...
> it 'xyz' ...
> end
>
> describe ApplicationController, :shared => true do
> it_should_behave_like 'ApplicationController one facet'
> it_should_behave_like 'ApplicationController some other facet'
> end
>
> And corresponding ApplicationController subclass specs:
>
> describe OtherController do
> it_should_behave_like 'ApplicationController'
> end
>
> Both of the shared behaviour blocks get executed twice when running
> the subclass specs; the specdoc output looks like:
>
> OtherController
> - foo
> - bar
> - abc
> - xyz
> - abc
> - xyz
> - foo
> - bar
>
> And note that it's running the shared behaviours in this order:
>
> - 'one facet'
> - 'some other facet'
> - 'some other facet'
> - 'one facet'
>
> Not actually a big deal; seeing as the specs don't have any side-
> effects and running them twice is harmless, and in any case getting
> rid of the nesting (putting all the specs in a single shared
> behaviour block) gets rid of the duplicate. But I'm wondering, is
> this a bug? Feature? Am I abusing shared behaviours?
Yes. No. Yes (but you're entitled to).
Please report this to the tracker!
Thanks,
David
More information about the rspec-users
mailing list