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

Zeus sometimes runs RSpec twice #180

Closed
darthdeus opened this issue Dec 5, 2012 · 23 comments
Closed

Zeus sometimes runs RSpec twice #180

darthdeus opened this issue Dec 5, 2012 · 23 comments
Labels

Comments

@darthdeus
Copy link
Contributor

@darthdeus darthdeus commented Dec 5, 2012

I'm not sure if this is a duplicate of #175, but I'm experiencing the same behavior in some of my apps that use RSpec.

However it doesn't happen in all of them, so I'm not sure how to give exact steps to reproduce this.

@davebrace
Copy link

@davebrace davebrace commented Dec 8, 2012

I'm having the same issue... Specs run twice when trying to run an individual spec file, but only run once when passing in a directory to the test command. This is with with the 13.1 gem.

@burke
Copy link
Owner

@burke burke commented Dec 8, 2012

Test frameworks do some really asinine hacks to autorun loaded test files. What version of rspec are you guys using? I'll try to figure this one out early next week.

@davebrace
Copy link

@davebrace davebrace commented Dec 8, 2012

I'm using rspec 2.12.1.

@burke
Copy link
Owner

@burke burke commented Dec 8, 2012

Thanks. I'll play with it on monday.

@darthdeus
Copy link
Contributor Author

@darthdeus darthdeus commented Dec 8, 2012

I'm using both 2.11 and having the issue exactly the same, twice when running a single spec, but only once when running all the specs.

@davebrace
Copy link

@davebrace davebrace commented Dec 8, 2012

Interestingly... I tested this on two projects, both using rspec 2.12.1 and both using zeus 0.13.1. In one project the specs run twice, and all fail the second time (it's like rspec's rails helpers aren't loaded during the second run). In the second project, everything works fine. I'm at a loss for what could be causing the issue.

@antage
Copy link

@antage antage commented Dec 12, 2012

In one project the specs run twice, and all fail the second time (it's like rspec's rails helpers aren't loaded during the second run)

I have same problem too.

zeus 0.13.1, rspec 2.12.0

@Soliah
Copy link

@Soliah Soliah commented Dec 15, 2012

It's running once for me when running against a directory, but twice when run against a single spec file.

On zeus 0.13.1, rspec 2.12.2.

@Soliah
Copy link

@Soliah Soliah commented Dec 16, 2012

Removing require 'rails/autorun' from my spec_helper.rb stops these errors from happening to me.

Including my spec_helper.rb for brevity. Note that this is basically from a fresh application, but I just did the same to an older app running rspec 2.8.0 and it seems to have worked.

require 'simplecov'

SimpleCov.start 'rails' do
  add_filter '/test/'
  add_filter '/config/'
  add_filter '/vendor/'
  add_filter '/spec/'

  add_group 'Controllers', 'app/controllers'
  add_group 'Models', 'app/models'
  add_group 'Helpers', 'app/helpers'
  add_group 'Decorators', 'app/decorators'
  add_group 'Libraries', 'lib'

  use_merging true
end

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# require 'rspec/autorun'

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = true
  config.infer_base_class_for_anonymous_controllers = false
  config.order = "random"
end
@darthdeus
Copy link
Contributor Author

@darthdeus darthdeus commented Dec 16, 2012

I have to confirm this, but it only helps running the whole spec file.

If I try to run a specific line, I will get an error No tests found on line 69. Valid tests to run:, whereas with the autorun enabled I am able to run a single spec, but not the whole file.

@turadg
Copy link
Collaborator

@turadg turadg commented Dec 17, 2012

In summary:
With rspec/autorun
directories run once
files run twice
running lines in tests works

Without rspec/autorun
directories never run (0 tests)
files run once (correctly)
running lines in tests doesn't work (not found, perhaps because 0 tests on the directory?)

(zeus master, rspec 2.12.0)

fwiw, when rspec runs twice, the second time my specs are failing due to database leftovers.

@burke any ideas on how to fix all this?

@davebrace
Copy link

@davebrace davebrace commented Dec 17, 2012

Interestingly, in the one project I have where Zeus (0.13.1) works perfectly with rspec (runs directories / single file, single file with line number), I am including "rspec/autorun" in my spec_helper.

In the project where I am experiencing problems with specs running twice, removing 'rspec/autorun' allows me to correctly run individual files and individual files with line numbers, but directories run no tests.

@codepodu
Copy link

@codepodu codepodu commented Dec 25, 2012

@Soliah 's fix works for me. I removed require 'rspec/autorun' from spec_helper. It was a remnant from the Spork days.

@brandonhilkert
Copy link

@brandonhilkert brandonhilkert commented Dec 31, 2012

+1 for @Soliah

Mine worked as expected for both directories and files. Removing rspec/autorun from spec_helper.rb causes everything to run just once as expected.

@darthdeus
Copy link
Contributor Author

@darthdeus darthdeus commented Jan 1, 2013

While removing the rspec/autorun helps, it is still just treating the symptoms, not the root cause.

@julioprotzek
Copy link

@julioprotzek julioprotzek commented Jan 9, 2013

Removing rspec/autorun from spec_helper.rb worked for me.

@skyeagle
Copy link

@skyeagle skyeagle commented Jan 14, 2013

Confirm that removing rspec/autorun solves the issue.

@kurko
Copy link

@kurko kurko commented Jan 19, 2013

+1 about removing rspec/autorun.

@davebrace
Copy link

@davebrace davebrace commented Jan 19, 2013

As of 0.13.2, removing rspec/autorun solved this problem in all my projects!

@darthdeus
Copy link
Contributor Author

@darthdeus darthdeus commented Jan 21, 2013

Is there any hope for getting this fixed? :( I'd love to help, but not really sure how.

@turadg
Copy link
Collaborator

@turadg turadg commented Jan 21, 2013

I believe it is fixed in 0.13.2. Updating my comment earlier:

Without rspec/autorun
directories run correctly (e.g. zeus rspec spec)
files run correctly (e.g. zeus rspec spec/models/user_spec.rb)
locations in tests run correctly (e.g. zeus rspec spec/models/user_spec.rb:23)

(zeus 0.13.2, rspec 2.12.1)

@turadg
Copy link
Collaborator

@turadg turadg commented Jan 21, 2013

Btw, master is behind 0.13.2 at the moment: #236

@turadg turadg closed this in d3c096d Jan 22, 2013
turadg added a commit that referenced this issue Jan 22, 2013
document the Spork wiki page to close #180
@mattheworiordan
Copy link

@mattheworiordan mattheworiordan commented Jan 27, 2013

Removing rspec/autorun fixed the problem and still ensured tests run fine without Zeus

noahpatterson pushed a commit to noahpatterson/DCOpen211DCConnect that referenced this issue Mar 17, 2014
[Zeus](https://github.com/burke/zeus) is a great gem that preloads
your Rails app so you can run commands and tests quickly. However,
it doesn't play well with the default "spec_helper.rb" that gets
generated when you install Rspec. The solution is to remove
"require 'rspec/autorun'" from "spec_helper.rb", which is what this
commit does.

This change does not affect those who do not have Zeus installed.
Running "rspec" from the command line will continue to work.

Reference and more info:
burke/zeus#180
http://railscasts.com/episodes/412-fast-rails-commands
http://robots.thoughtbot.com/post/40193452558/improving-rails-boot-time-with-zeus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.