Ok, I created a new project and tried to reproduce my issue and I discovered something else. I can't really reproduce the previously reported problem.<br> <br>I have a new rails project with one User model with validates_uniqueness_of :email
<br><br>Here is my spec file for the model<br><br>require File.dirname(__FILE__) + '/../spec_helper'<br>def create_test_user<br> User.new(:first_name => 'John', :last_name => 'Doe', :email => '
<a href="mailto:john@doe.fr">john@doe.fr</a>').save<br>end<br><br>describe "A user" do<br> <br> it "should be created if valid" do<br> create_test_user.should be(true)<br> create_test_user.should be(false)
<br> end<br> <br> it "should not have the same email than another user" do<br> create_test_user.should be(false)<br> end<br>end<br><br>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.
<br><br>rspec_on_rails plugin and rspec gem from trunk. (updated today)<br><br>-Matt<br><br><br><div><span class="gmail_quote">On 5/1/07, <b class="gmail_sendername">aslak hellesoy</b> <<a href="mailto:aslak.hellesoy@gmail.com">
aslak.hellesoy@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On 5/1/07, aslak hellesoy <<a href="mailto:aslak.hellesoy@gmail.com">
aslak.hellesoy@gmail.com</a>> wrote:<br>> On 5/1/07, Matt Aimonetti <<a href="mailto:mattaimonetti@gmail.com">mattaimonetti@gmail.com</a>> wrote:<br>> > after(:each) doesn't work either.<br>> >
<br>><br>> Really? A sample spec showing how after(:each) doesn't work would be helpful.<br>><br><br>I mean some code I can run to reproduce what you see.<br><br>> Aslak<br>><br>> > -Matt<br>> >
<br>> ><br>> > On 5/1/07, aslak hellesoy <<a href="mailto:aslak.hellesoy@gmail.com">aslak.hellesoy@gmail.com</a>> wrote:<br>> > ><br>> > > It's after(:each) and not teardown(:each)<br>
> > ><br>> > > On 5/1/07, Matt Aimonetti < <a href="mailto:mattaimonetti@gmail.com">mattaimonetti@gmail.com</a>> wrote:<br>> > > > describe "a legacy user" do<br>> > > > include LegacyUserHelper
<br>> > > ><br>> > > > before :all do<br>> > > > LEGACY.connect<br>> > > > migration_for_legacy_users<br>> > > > end<br>> > > ><br>> > > > before do
<br>> > > > @l_user = LegacyUser.new<br>> > > > end<br>> > > ><br>> > > > teardown :each do<br>> > > ><br>> > delete_user_with_email(valid_legacy_user_attributes[:email])
<br>> > > > end<br>> > > ><br>> > > > Here is a snippet of my code.<br>> > > ><br>> > > > Before running my examples, I need to connect to my legacy database and
<br>> > > > migrating the schema. After each example I need to delete the legacy<br>> > user<br>> > > > just created. To get the above code to work, I had to move my<br>> > > ><br>
> > delete_user_with_email(valid_legacy_user_attributes[:email])<br>> > function to be<br>> > > > run before each example instead of after.<br>> > > ><br>> > > > -Matt<br>> > > >
<br>> > > > On 4/30/07, David Chelimsky < <a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>> wrote:<br>> > > > ><br>> > > > > On 4/30/07, Matt Aimonetti <<a href="mailto:mattaimonetti@gmail.com">
mattaimonetti@gmail.com</a>> wrote:<br>> > > > > > teardown :each and after :each don't seem to work for me.<br>> > > > > ><br>> > > > > > I had to move my function from "teardown :each" to "before" since
<br>> > the<br>> > > > > > function was deleting the object created by the previous spec and<br>> > the<br>> > > > > > function didn't seem to be called. Maybe I didn't understand
<br>> > properly<br>> > > > > how<br>> > > > > > teardown and after work.<br>> > > > ><br>> > > > > Each example (i.e. #it or #specify) gets run in its own object. It has
<br>> > > > > no access to any state in the other examples. before(:each) is run<br>> > > > > before each example, in the same object as the example. after(:each)<br>> > > > > is run after each example, in the same object as the example.
<br>> > > > ><br>> > > > > I'm a bit confused by your description of the problem. Can you post<br>> > > > > some code so we can talk about a specific example?<br>> > > > >
<br>> > > > ><br>> > > > > ><br>> > > > > > -Matt<br>> > > > > ><br>> > > > > ><br>> > > > > > On 4/18/07, Matthew Heidemann <
<a href="mailto:matthew.heidemann@gmail.com">matthew.heidemann@gmail.com</a>> wrote:<br>> > > > > > > I personally like before :each_example. The first time I read it I<br>> > > > > said,
<br>> > > > > > "before :each what?".<br>> > > > > > ><br>> > > > > > > I think once people run the spec and see 1 example 0 failures,<br>> > they
<br>> > > > > know<br>> > > > > > that the 'it do' is an example<br>> > > > > > ><br>> > > > > > ><br>> > > > > > ><br>
> > > > > > > On 4/11/07, Matt Aimonetti < <a href="mailto:matt@aimonetti.net">matt@aimonetti.net</a>> wrote:<br>> > > > > > > > I fully agree with Dean and prefer the "before :each", "after
<br>> > :all"<br>> > > > > > option, it reads better and is easier to understand for newbies.<br>> > > > > > > ><br>> > > > > > > > -Matt<br>> > > > > > > >
<br>> > > > > > > ><br>> > > > > > > ><br>> > > > > > > > On 4/11/07, Dean Wampler <<a href="mailto:deanwampler@gmail.com">deanwampler@gmail.com</a>
> wrote:<br>> > > > > > > > > Setup and teardown are more approachable to converts from<br>> > > > > Test::Unit,<br>> > > > > > > > > but "before :all" and "after :each" read better, IMHO.
<br>> > > > > > > > ><br>> > > > > > > > > "all_examples" might cause people to ask "what examples?" I'm<br>> > not<br>> > > > > sure
<br>> > > > > > > > > most people will think of the "it blocks" as examples. Still,<br>> > you<br>> > > > > > > > > could just accept any symbol that begins with "each" and
<br>> > "all", so<br>> > > > > > > > > people can invent their own name ;)<br>> > > > > > > > ><br>> > > > > > > > > dean<br>
> > > > > > > > ><br>> > > > > > > > ><br>> > > > > > > > > On 4/11/07, David Chelimsky < <a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com
</a>> wrote:<br>> > > > > > > > > > We're going to rename context_setup and context_teardown<br>> > because<br>> > > > > > they<br>> > > > > > > > > > no longer read well when using "describe/id". There are two
<br>> > > > > ideas<br>> > > > > > > > > > floating around about this. The first:<br>> > > > > > > > > ><br>> > > > > > > > > > setup :each #default - works like setup does now
<br>> > > > > > > > > > setup :all #replaces context_setup<br>> > > > > > > > > > teardown :each #default - works like teardown does now<br>> > > > > > > > > > teardown :all #replaces context teardown
<br>> > > > > > > > > ><br>> > > > > > > > > > The second uses "before" and "after" in the same way:<br>> > > > > > > > > >
<br>> > > > > > > > > > before :each #default - works like setup does now<br>> > > > > > > > > > before :all #replaces context_setup<br>> > > > > > > > > > after :each #default - works like teardown does now
<br>> > > > > > > > > > after :all #replaces context teardown<br>> > > > > > > > > ><br>> > > > > > > > > > In both cases, the default is :each, so you can just say
<br>> > "setup<br>> > > > > do"<br>> > > > > > or<br>> > > > > > > > > > "before do" instead of "setup :each do" or "before :each
<br>> > do".<br>> > > > > > > > > ><br>> > > > > > > > > > == Examples<br>> > > > > > > > > ><br>> > > > > > > > > > describe Thing do
<br>> > > > > > > > > > setup :all { ... }<br>> > > > > > > > > > setup :each { ... }<br>> > > > > > > > > > it "should do something" { ... }
<br>> > > > > > > > > > it "should do something else" { ... }<br>> > > > > > > > > > teardown :each { ... }<br>> > > > > > > > > > teardown :all { ... }
<br>> > > > > > > > > > end<br>> > > > > > > > > ><br>> > > > > > > > > > describe Thing do<br>> > > > > > > > > > before :all { ... }
<br>> > > > > > > > > > before :each { ... }<br>> > > > > > > > > > it "should do something" { ... }<br>> > > > > > > > > > it "should do something else" { ... }
<br>> > > > > > > > > > after :each { ... }<br>> > > > > > > > > > after :all { ... }<br>> > > > > > > > > > end<br>> > > > > > > > > >
<br>> > > > > > > > > > describe Thing do<br>> > > > > > > > > > before { ... } # works like before :each<br>> > > > > > > > > > it "should do something" { ... }
<br>> > > > > > > > > > it "should do something else" { ... }<br>> > > > > > > > > > after { ... } # works like after :each<br>> > > > > > > > > > end
<br>> > > > > > > > > ><br>> > > > > > > > > > One other thing that occurs to me is that "before :each"<br>> > really<br>> > > > > > means
<br>> > > > > > > > > > "before each example" - so perhaps it should be "before<br>> > > > > > :each_example"<br>> > > > > > > > > > and "before :all_examples" (or :each and :each_example could
<br>> > > > > both be<br>> > > > > > > > > > supported, etc).<br>> > > > > > > > > ><br>> > > > > > > > > > WDYT?<br>
> > > > > > > > > ><br>> > _______________________________________________<br>> > > > > > > > > > rspec-devel mailing list<br>> > > > > > > > > >
<a href="mailto:rspec-devel@rubyforge.org">rspec-devel@rubyforge.org</a><br>> > > > > > > > > ><br>> > <a href="http://rubyforge.org/mailman/listinfo/rspec-devel">http://rubyforge.org/mailman/listinfo/rspec-devel
</a><br>> > > > > > > > > ><br>> > > > > > > > ><br>> > > > > > > > ><br>> > > > > > > > > --<br>> > > > > > > > > Dean Wampler
<br>> > > > > > > > > <a href="http://www.objectmentor.com">http://www.objectmentor.com</a><br>> > > > > > > > > <a href="http://www.aspectprogramming.com">http://www.aspectprogramming.com
</a><br>> > > > > > > > > <a href="http://www.contract4j.org">http://www.contract4j.org</a><br>> > > > > > > > ><br>> > _______________________________________________
<br>> > > > > > > > > rspec-devel mailing list<br>> > > > > > > > > <a href="mailto:rspec-devel@rubyforge.org">rspec-devel@rubyforge.org</a><br>> > > > > > > > >
<br>> > <a href="http://rubyforge.org/mailman/listinfo/rspec-devel">http://rubyforge.org/mailman/listinfo/rspec-devel</a><br>> > > > > > > > ><br>> > > > > > > ><br>
> > > > > > > ><br>> > > > > > > > _______________________________________________<br>> > > > > > > > rspec-devel mailing list<br>> > > > > > > >
<a href="mailto:rspec-devel@rubyforge.org">rspec-devel@rubyforge.org</a><br>> > > > > > > ><br>> > <a href="http://rubyforge.org/mailman/listinfo/rspec-devel">http://rubyforge.org/mailman/listinfo/rspec-devel
</a><br>> > > > > > > ><br>> > > > > > ><br>> > > > > > ><br>> > > > > > > _______________________________________________<br>> > > > > > > rspec-devel mailing list
<br>> > > > > > > <a href="mailto:rspec-devel@rubyforge.org">rspec-devel@rubyforge.org</a><br>> > > > > > > <a href="http://rubyforge.org/mailman/listinfo/rspec-devel">http://rubyforge.org/mailman/listinfo/rspec-devel
</a><br>> > > > > > ><br>> > > > > ><br>> > > > > ><br>> > > > > > _______________________________________________<br>> > > > > > rspec-devel mailing list
<br>> > > > > > <a href="mailto:rspec-devel@rubyforge.org">rspec-devel@rubyforge.org</a><br>> > > > > > <a href="http://rubyforge.org/mailman/listinfo/rspec-devel">http://rubyforge.org/mailman/listinfo/rspec-devel
</a><br>> > > > > ><br>> > > > > _______________________________________________<br>> > > > > rspec-devel mailing list<br>> > > > > <a href="mailto:rspec-devel@rubyforge.org">
rspec-devel@rubyforge.org</a><br>> > > > > <a href="http://rubyforge.org/mailman/listinfo/rspec-devel">http://rubyforge.org/mailman/listinfo/rspec-devel</a><br>> > > > ><br>> > > >
<br>> > > _______________________________________________<br>> > > rspec-devel mailing list<br>> > > <a href="mailto:rspec-devel@rubyforge.org">rspec-devel@rubyforge.org</a><br>> > > <a href="http://rubyforge.org/mailman/listinfo/rspec-devel">
http://rubyforge.org/mailman/listinfo/rspec-devel</a><br>> > ><br>> ><br>> ><br>> > _______________________________________________<br>> > rspec-devel mailing list<br>> > <a href="mailto:rspec-devel@rubyforge.org">
rspec-devel@rubyforge.org</a><br>> > <a href="http://rubyforge.org/mailman/listinfo/rspec-devel">http://rubyforge.org/mailman/listinfo/rspec-devel</a><br>> ><br>><br>_______________________________________________
<br>rspec-devel mailing list<br><a href="mailto:rspec-devel@rubyforge.org">rspec-devel@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-devel">http://rubyforge.org/mailman/listinfo/rspec-devel</a>
<br></blockquote></div><br>