Specs attempt to be run twice using RSpec TM bundle + Spork

158 views
Skip to first unread message

Elliot Winkler

unread,
Nov 23, 2009, 2:20:56 PM11/23/09
to spor...@googlegroups.com
I posted this problem on the RSpec mailing list and they said to try
here, so that what I'm doing ;)

I'm having the hardest time trying to figure out something weird I've
suddenly run into. I'm running my specs using the RSpec Textmate bundle
+ Spork. So of course I've got TM_RSPEC_OPTS in Textmate set to --drb
and I'm running `spork` from the command line to fire up the Spork
server before I run the specs. However, if I run a spec file in
Textmate, it seems that my spec_helper is getting loaded one too many
times. This isn't a problem on small apps because it doesn't take that
long to re-load the spec_helper. However, on big apps this can add 4 or
5 seconds to the time, and when running just one spec file this is kind
of annoying.

I did a quick test by having spec_helper print out something at the
bottom of the file (outside of any prefork or each_run blocks) and then
wrote up a quick one-example spec file. When I ran it, the debug line in
spec_helper was printed to the window, then the examples were printed,
then the line in spec_helper was printed again. (I didn't get a second
set of examples because I think RSpec's smart about not re-running
examples, or maybe it's Spork that's smart about not re-running
each_run's). So it definitely looks like spec_helper is getting loaded
again, after all the specs are run.

Actually, what it looks like is that two commands are being executed:
one to run just the spec file I have open, another to run all the specs.
I put a debug line in Spec::OptionParser#order! just to see what
arguments it got called with, and here's what I got:

------------
Spec::OptionParser#order!: @argv is
["/Users/elliot/code/nonwork/proj/web/rails_apps/sample/spec/foo_spec.rb",
"--format", "textmate", "--drb"]
Spec::OptionParser#order!: @argv is
["/Users/elliot/code/nonwork/proj/web/rails_apps/sample/spec/foo_spec.rb",
"--format", "textmate"]
** Spec::Runner::DrbCommandLine.run: DRb run called with argv:
["/Users/elliot/code/nonwork/proj/web/rails_apps/sample/spec/foo_spec.rb",
"--format", "textmate"]
** Spork: spec_helper was loaded
** Spork: each_run block executed

(examples run)

Spec::OptionParser#order!: @argv is ["--colour", "--format", "progress",
"--loadby", "mtime", "--reverse", "--drb"]
Spec::OptionParser#order!: @argv is ["--colour", "--format", "progress",
"--loadby", "mtime", "--reverse"]
** Spec::Runner::DrbCommandLine.run: DRb run called with argv:
["--colour", "--format", "progress", "--loadby", "mtime", "--reverse"]
** Spork: spec_helper was loaded
** Spork: each_run block executed
Spec::OptionParser#order!: @argv is ["--colour", "--format", "progress",
"--loadby", "mtime", "--reverse"]
------------

So what seems to be run is the equivalent of `spec foo_spec.rb --format
textmate --drb` followed by just `spec --opts spec.opts`.. or something.
I'm not sure ;)

Things I've tried that haven't worked:

* running specs from the app I'm working on
* running specs from a fresh app
* reinstalling rspec, rspec-rails, the RSpec Textmate bundle, and spork
* updating Textmate to the latest version (1.5.8)
* downgrading to Textmate 1.5.7
* commenting out the line that requires spec_helper in my spec file
* disabling the --drb option in TM_RSPEC_OPTS

Just to emphasize, what I've described only happens when Spork is
running. If I leave TM_RSPEC_OPTS at --drb but fail to leave the Spork
server open, spec_helper only gets run once as it should.

Also, this is only for Textmate -- I've got --drb in my spec.opts and
`rake spec` works just fine when Spork is running.

Sorry for the long email. Tim, could you offer any ideas as to what
might be causing this problem?

-- Elliot

Elliot Winkler

unread,
Nov 23, 2009, 4:15:09 PM11/23/09
to spor...@googlegroups.com
Okay, tried running my spec file with various versions of rspec and
spork. Basically, I figured out that something changed between RSpec
1.2.8 and 1.2.9 to cause the issue I'm seeing. This makes sense as I
swear I hadn't encountered this issue until just a little while ago. It
must have been when I upgraded RSpec on my computer when I started to
see it.

I'm going to try and figure out what changed between 1.2.8 and 1.2.9 and
see if I can write a patch for Spork next.

-- Elliot

Tim Harper

unread,
Nov 23, 2009, 4:41:31 PM11/23/09
to spor...@googlegroups.com
I've run into this problem before. To get around it, I had to call
exit! instead of exit in the Spork subprocess (see commit
352676304a1efee931298bd385f01e0393c68e64), because otherwise when
the subprocess got killed of the at_exit hooks (registered by RSpec)
would cause all loaded specs to run.

It seems it would be nice if RSpec tracked which examples were run
already as to avoid running them twice.

Tim

David Chelimsky

unread,
Nov 23, 2009, 6:38:21 PM11/23/09
to spor...@googlegroups.com
How are the specs getting run in the first place? And why is this unique to Textmate? Elliot, you don't see the same behavior on the command line, do you?
 
It seems it would be nice if RSpec tracked which examples were run
already as to avoid running them twice.

I'm more than happy to find a way to solve this problem and get RSpec to play nice w/ others in general. I think, however, that asking RSpec to be smarter than it already is about whether or not to run is the wrong way to go. In the RSpec/Spork relationship, Spork is the puppeteer and RSpec the puppet, so I think that we should look for an extension point in RSpec that lets Spork (or any other process manager) tell RSpec what to do when, and that Spork should use that. 

WDYT?

Cheers,
David
 
Tim

--

You received this message because you are subscribed to the Google Groups "sporkgem" group.
To post to this group, send email to spor...@googlegroups.com.
To unsubscribe from this group, send email to sporkgem+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sporkgem?hl=.



Tim Harper

unread,
Nov 23, 2009, 11:00:52 PM11/23/09
to spor...@googlegroups.com
David,

I think that's a swell idea. If there were simply a way to turn off
the at_exit hook in rspec, that would be swell.

Tim

David Chelimsky

unread,
Nov 23, 2009, 11:06:37 PM11/23/09
to spor...@googlegroups.com
David,

I think that's a swell idea.  If there were simply a way to turn off
the at_exit hook in rspec, that would be swell.

Cool. I'll look into that.

One question I have though - how are the examples running now if not through the at_exit hook?
 

Tim

--

You received this message because you are subscribed to the Google Groups "sporkgem" group.
To post to this group, send email to spor...@googlegroups.com.
To unsubscribe from this group, send email to sporkgem+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sporkgem?hl=en.



Tim Harper

unread,
Nov 23, 2009, 11:08:18 PM11/23/09
to spor...@googlegroups.com
Like this:

::Spec::Runner::CommandLine.run(
::Spec::Runner::OptionParser.parse(
argv,
stderr,
stdout
)
)

Tim

Elliot Winkler

unread,
Nov 23, 2009, 11:10:38 PM11/23/09
to spor...@googlegroups.com
I don't think it's the at_exit. I narrowed the problem down to commit a2a3b0f (in RSpec) [1], which automatically loaded spec.opts. Something about that is causing stuff to get loaded twice.

Not seeing this problem on the command line that I know of, still looking into it.

-- Elliot

[1] http://github.com/dchelimsky/rspec/commit/a2a3b0f120bc8da9dcb054c121ffc62304134a50

For more options, visit this group at http://groups.google.com/group/sporkgem?hl=en.



Reply all
Reply to author
Forward
0 new messages