[rspec-devel] names for setup and teardown methods

David Chelimsky dchelimsky at gmail.com
Wed May 2 14:49:18 EDT 2007


On 5/2/07, Matt Aimonetti <mattaimonetti at gmail.com> wrote:
> Thanks for the clarification. For some reason, in my project the DB is not
> cleared and that's why I had to use an after(:each) call. It might be
> because my example calls a module which creates a new user instead of
> creating the user directly. Nevermind, I just tried in a new project and it
> works well. I don't know what's wrong.
>
> Anyway, is it normal that the following code passes:

Yes. It tries to recreate the test user after each example, but that
all gets wiped out before the next one, so both examples should pass.

David

>
> def create_test_user
>   User.new(:first_name => 'John', :last_name => 'Doe', :email =>
> 'john at doe.fr ').save
> end
>
> describe "A user" do
>
>   after :each do
>     create_test_user
>   end
>
>   it "should be created if valid" do
>     create_test_user.should be(true)
>     create_test_user.should be(false)
>   end
>
>   it "should not have the same email than another user" do
>    create_test_user.should be(true)
>   end
> end
>
>
> (Obviously if I replace after by before, then the example fail)
>
> -Matt
>
>
>
>
> On 5/1/07, Michael Klishin <michael.s.klishin at gmail.com> wrote:
> > Matt,
> >
> > Second spec is not supposed to pass. You have to put the code creating
> > model in setup (before all in rspec 0.9 terms) cause DB is cleared
> > and refilled before each spec run. So this is expected behavior.
> >
> > On 02/05/07, Matt Aimonetti <mattaimonetti at gmail.com> wrote:
> >
> > > The second example fails. I'm a bit surprised that the user created by
> the
> > > first example doesn't exist anymore when the 2nd example tries creating
> a
> > > new user.
> >
> > --
> > This was freedom. Losing all hope was freedom.
> >
> > Chasing the beauty in programming:
> > www.ruby-lang.org | www.rubyonrails.org
> > _______________________________________________
> > rspec-devel mailing list
> > rspec-devel at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-devel
> >
>
>
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>


More information about the rspec-devel mailing list