Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSpec runs specs twice when run from within ruby and file is reloaded between subsequent runs #826

Closed
mostr opened this issue Mar 10, 2013 · 7 comments

Comments

@mostr
Copy link

mostr commented Mar 10, 2013

I'd like to run specs from withing ruby runtime every time my spec or lib file changes. Unfortunately it looks like RSpec runs the same specs twice when file is load-ed between subsequent runs. I'm using JRuby and to eliminate JVM startup time I'd like to fire my ruby runtime once, load all my stuff on start and then reload only files changed.

I've created tiny project showing this issue live https://github.com/mostr/rspec_double_run_issue.

Is there a way to cleanup RSpec "context" between subsequent runs when run with RSpec::Core::Runner.run?

@mostr
Copy link
Author

mostr commented Mar 10, 2013

I'm attaching part of output from run of this sample script mentioned above:

ruby run_spec_in_loop.rb 
Running spec from within ruby runtime
.
Finished in 0.00047 seconds
1 example, 0 failures

loading spec file via 'load' as if it was changed and we wanted changes to be picked up
Running spec from within ruby runtime
..
Finished in 0.001 seconds
2 examples, 0 failures

@JonRowe
Copy link
Member

JonRowe commented Mar 18, 2013

Hey, the whole purpose of the runner is to allow you to customise what specs are run from your own tools, there are various projects that do this sort of thing on MRI Ruby, e.g. guard-rspec and in particular there are things for JVM / JRuby like 'nailgun' that you might like to look at.

@mostr
Copy link
Author

mostr commented Mar 18, 2013

You're right but the thing is guard-rspec executes on fresh runner every time (what causes delays on JRuby) .What I want to do is to have runner instance configured and just run spec I want using this instance. But when I try to do that after reloading specs file it executes those specs twice.

@JonRowe
Copy link
Member

JonRowe commented Mar 18, 2013

The RSpec runner is already calling load internally, your second load is what's causing the double run issue.

I quickly knocked up a script based off your example which reruns a single spec file, changes the specs to something else, then reruns them, work's correctly without the second load

See: https://gist.github.com/JonRowe/5192007

@JonRowe
Copy link
Member

JonRowe commented Apr 11, 2013

Hey @mostr, I'm going to close this now, I hope my last tip helped you out, but this doesn't seem like an issue within RSpec itself.

@JonRowe JonRowe closed this as completed Apr 11, 2013
@mostr
Copy link
Author

mostr commented Apr 11, 2013

Yeah, thanks a lot, your tip was very helpful.

@JonRowe
Copy link
Member

JonRowe commented Apr 11, 2013

No worries. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants