[rspec-users] alias method spec?

Bob Cotton bob.cotton at rallydev.com
Wed Mar 21 12:44:38 EDT 2007


"David Chelimsky" <dchelimsky at gmail.com> writes:
> On 3/21/07, Bob Cotton <bob.cotton at rallydev.com> wrote:
>>
>>   [ I'm still thinking in context/specify. ]
>>
>> David, your suggestion does answer Bryan's scenario,
>>
>>   "you instead had two types of things (Foo and Bar) with one method
>>   that should behave the same for each"
>>
>> It is an interesting approach to testing a common behavior between two
>> classes. But what about factoring the specify into a module:
>>
>> module Common
>>   specify "..."
>> end
>>
>> then include that into the context?
>
> The problem there is that we'd have to add #specify to Module, which
> I'm hesitant to do. How about this (using "it" and Examples instead of
> "specify"):
>
> module EditionExamples < SharedExampleGroup
>   it "should " do
>     ..
>   end
> end
>
> describe LargeEdition do
>   include EditionExamples
>   setup do
>     ...
>   end
> end
>
> describe SmallEdition do
>   include EditionExamples
>   setup do
>     ...
>   end
> end
>
> That make sense?

Sure does, except, can you have modules subclass?

> module EditionExamples < SharedExampleGroup

Instead of factoring out the setup bits and having a common behavior,
factor out the common behavior and have the #describe be
the thing we are defining, which makes more sense. That fells right.

I'd be all for adding specify/it to Module.

*or* 

rspec, through #describe, is creating classes on the fly. Could you
have something that defines common behavior that writes Modules on the
fly?

describe_common AllEditions do
  it "should" do
  end
end          

describe "LargeEdition" do
  include AllEditions
  setup ...
end

describe "SmallEdition" do
  include AllEditions
  setup ...
end

- Bob


More information about the rspec-users mailing list