[rspec-users] rspec_on_rails magical incantations

David Richards drichards at showcase60.com
Thu Jul 26 12:50:37 EDT 2007


I ran into something really puzzling today.  I don't know exactly why  
it's happening, but I thought I'd share my experiences.

I started a dummy app just to test an idea outside of the context of  
my real work today.  So, I quickly get things started:

* rails junk
* cd junk
* ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/ 
CURRENT/rspec
* ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/ 
CURRENT/rspec_on_rails
* script/generate rspec
* script/generate rspec_scaffold Junk name:string
* script/generate rspec
* cp ../mrm/config/database.yml config/ (just a good database script  
that tells me where I keep my SQLite databases)
* rake db:migrate
* autotest

That gives me an error on @junk = Junk.new in the setup of my  
scaffolded Junk model.  I wrestled with it for a while, and couldn't  
get around it.  I could get the test to pass with rake spec, which  
uses the other runner, but not with autotest or script/spec, which I  
believe use the same runner.

So I scraped the whole app and started from scratch, this time  
generating rspec before I generated the scaffold.  Turns out this was  
the trick.  Now, why the funny problem, I don't know.  I guess the  
generator needs to see something different while it generates, but I  
can't imagine what it is.  The spec_helper.rb and the spec.opts are  
the same, I believe.  (I checked that between my working app and non- 
working app and didn't see a difference.)  There are the previous- 
failures.txt, which I can't imagine would affect anything.  Then  
there's script/spec and script/spec_server.  I'm sure it has  
something to do with the scaffold generator talking to them somehow,  
but since the generated spec is identical, I don't know.

Anyway, I'm stumped.  If anyone understands this, great.  It's one  
less mystery at the end of the day.  If not, I'll just remember to do  
my incantations in the correct order and post this in case someone  
else runs into the same problem.

Cheers,

David


More information about the rspec-users mailing list