[rspec-users] shared behav

David Chelimsky dchelimsky at gmail.com
Tue Dec 18 16:36:40 EST 2007


On Dec 18, 2007 11:39 AM, Jonathan Linowes <JONATHAN at linowes.com> wrote:
>
> hi, i want to make a behavior shared between models, the examples need to
> create new instances etc. Is there a way to pass the model class to the
> shared behavior?

We're calling these shared example groups now.

The way to affect the state within a shared example group is to use
before(:each) to set an instance variable:

shared_examples_for "models that do stuff" do
  before(:each) do
    @instance = @class.new
  end
  it "should do something" do
   @instance.should do_something
  end
end

describe Foo do
  before(:each) do
    @class = Foo
  end
  it_should_behave_like "models that do stuff"
end

Cheers,
David

>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list