Forum: RSpec Testing code that integrates with Rspec

Posted by Mike Grafton (Guest)
on 2010-02-24 06:52
(Received via mailing list)
Hey all,

I've been using Rspec for a while now, but this is the first time I've 
run
up against the following problem: how do you use Rspec to test code that
uses Rspec?

Basically my code takes as input a representation of example groups, and 
it
should dynamically create those example groups and then run them. I 
borrowed
this code from a open-source project that doesn't appear to have tests 
for
it; the code works, but I'd like to get it under test so I can improve 
it.

Going through the Rspec code (v 1.3.0), it appears that this should be
possible.  There's Spec::Runner::Options, which looks to be a decent 
entry
point for kicking off an Rspec run (with #run_examples). It has 
something
attached to it called a Reporter, which looks like an observer that, if 
I
could mock it, I could sense exactly what my run of Rspec did.

Unfortunately, when I wrote a spec to invoke this code, both the code 
under
test and the spec itself seemed to talk to the same Reporter (the one 
that
got created first, for the the spec). So my spec and my code are 
entangled.

Any suggestions?

Here's a gist with a stripped down version of my code and a description 
of
what output it produced. I can work on this gist to make it actually
runnable if anybody is interested.

Thanks a bunch,
Mike
Posted by Mike Grafton (Guest)
on 2010-02-24 08:11
(Received via mailing list)
Oops, forgot the gist:

http://gist.github.com/312383

Thanks,
Mike
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.