Confusion over SharedExampleGroups

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Confusion over SharedExampleGroups

Brian Takita-2
A colleague of mine ran into issues with the usage of SharedExampleGroups.

He was expecting it to create its own ExampleGroup (describe block)
when it is invoked using it_should_behave_like, and was surprised when
test pollution occurred due to a before block in the
SharedExampleGroup.

What is your experience with this?

Should there be another type of SharedExampleGroup that does
encapsulate before blocks?

For example,

shared_describe "My shared specs" do
  before do
    @defined_in_shared_example_group = true
  end

  it "should not interfere with other specs" do
  end
end

describe Foobar do
  it_should_behave_like "My shared specs"

  it "should not see defined_in_shared_example_group" do
    @defined_in_shared_example_group.should be_nil
  end
end
_______________________________________________
rspec-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/rspec-devel
Reply | Threaded
Open this post in threaded view
|

Re: Confusion over SharedExampleGroups

David Chelimsky-2
On Wed, Apr 29, 2009 at 11:42 AM, Brian Takita <[hidden email]> wrote:

> A colleague of mine ran into issues with the usage of SharedExampleGroups.
>
> He was expecting it to create its own ExampleGroup (describe block)
> when it is invoked using it_should_behave_like, and was surprised when
> test pollution occurred due to a before block in the
> SharedExampleGroup.
>
> What is your experience with this?
>
> Should there be another type of SharedExampleGroup that does
> encapsulate before blocks?
>
> For example,
>
> shared_describe "My shared specs" do
>  before do
>    @defined_in_shared_example_group = true
>  end
>
>  it "should not interfere with other specs" do
>  end
> end
>
> describe Foobar do
>  it_should_behave_like "My shared specs"
>
>  it "should not see defined_in_shared_example_group" do
>    @defined_in_shared_example_group.should be_nil
>  end
> end

What's the point of doing this? i.e. why would you want a shared group
that does not share state? They are not parameterized, so they are not
configurable except through shared state. Unless you're thinking that
the shared state is access to Foobar through described class, which
begs the question if we're sharing some state, why not share all
state?
_______________________________________________
rspec-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/rspec-devel
Reply | Threaded
Open this post in threaded view
|

Re: Confusion over SharedExampleGroups

David Chelimsky-2
On Apr 29, 2009, at 11:51 AM, David Chelimsky <[hidden email]>  
wrote:

> On Wed, Apr 29, 2009 at 11:42 AM, Brian Takita  
> <[hidden email]> wrote:
>> A colleague of mine ran into issues with the usage of  
>> SharedExampleGroups.
>>
>> He was expecting it to create its own ExampleGroup (describe block)
>> when it is invoked using it_should_behave_like, and was surprised  
>> when
>> test pollution occurred due to a before block in the
>> SharedExampleGroup.
>>
>> What is your experience with this?
>>
>> Should there be another type of SharedExampleGroup that does
>> encapsulate before blocks?
>>
>> For example,
>>
>> shared_describe "My shared specs" do
>>  before do
>>    @defined_in_shared_example_group = true
>>  end
>>
>>  it "should not interfere with other specs" do
>>  end
>> end
>>
>> describe Foobar do
>>  it_should_behave_like "My shared specs"
>>
>>  it "should not see defined_in_shared_example_group" do
>>    @defined_in_shared_example_group.should be_nil
>>  end
>> end
>
> What's the point of doing this? i.e. why would you want a shared group
> that does not share state? They are not parameterized, so they are not
> configurable except through shared state. Unless you're thinking that
> the shared state is access to Foobar through described class, which
> begs the question if we're sharing some state, why not share all
> state?

Actually, if the shared group ends up being a subclass, then befores  
in the current group would be available to the shared group, but not  
the other way round. Then the subgroup could be named "behaving like  
My shared specs" or some such.

Thoughts?
_______________________________________________
rspec-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/rspec-devel