Zeus sometimes runs RSpec twice #180

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

Comments

Projects
None yet
@darthdeus
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@davebrace

davebrace 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.

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

This comment has been minimized.

Show comment
Hide comment
@burke

burke Dec 8, 2012

Owner

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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@davebrace

davebrace Dec 8, 2012

I'm using rspec 2.12.1.

I'm using rspec 2.12.1.

@burke

This comment has been minimized.

Show comment
Hide comment
@burke

burke Dec 8, 2012

Owner

Thanks. I'll play with it on monday.

Owner

burke commented Dec 8, 2012

Thanks. I'll play with it on monday.

@darthdeus

This comment has been minimized.

Show comment
Hide comment
@darthdeus

darthdeus Dec 8, 2012

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@davebrace

davebrace 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.

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

This comment has been minimized.

Show comment
Hide comment
@antage

antage 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

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

This comment has been minimized.

Show comment
Hide comment
@Soliah

Soliah 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 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

This comment has been minimized.

Show comment
Hide comment
@Soliah

Soliah 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

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

This comment has been minimized.

Show comment
Hide comment
@darthdeus

darthdeus Dec 16, 2012

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@turadg

turadg Dec 17, 2012

Collaborator

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?

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@davebrace

davebrace 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.

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

This comment has been minimized.

Show comment
Hide comment
@codepodu

codepodu 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.

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

@brandonhilkert

This comment has been minimized.

Show comment
Hide comment
@brandonhilkert

brandonhilkert 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.

+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

This comment has been minimized.

Show comment
Hide comment
@darthdeus

darthdeus Jan 1, 2013

Contributor

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

Contributor

darthdeus commented Jan 1, 2013

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

@julioprotzek

This comment has been minimized.

Show comment
Hide comment
@julioprotzek

julioprotzek Jan 9, 2013

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

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

@skyeagle

This comment has been minimized.

Show comment
Hide comment
@skyeagle

skyeagle Jan 14, 2013

Confirm that removing rspec/autorun solves the issue.

Confirm that removing rspec/autorun solves the issue.

@kurko

This comment has been minimized.

Show comment
Hide comment
@kurko

kurko Jan 19, 2013

+1 about removing rspec/autorun.

kurko commented Jan 19, 2013

+1 about removing rspec/autorun.

@davebrace

This comment has been minimized.

Show comment
Hide comment
@davebrace

davebrace Jan 19, 2013

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

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

@darthdeus

This comment has been minimized.

Show comment
Hide comment
@darthdeus

darthdeus Jan 21, 2013

Contributor

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

Contributor

darthdeus commented Jan 21, 2013

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

@turadg

This comment has been minimized.

Show comment
Hide comment
@turadg

turadg Jan 21, 2013

Collaborator

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)

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@turadg

turadg Jan 21, 2013

Collaborator

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

Collaborator

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

Merge pull request #243 from turadg/patch-1
document the Spork wiki page to close #180
@mattheworiordan

This comment has been minimized.

Show comment
Hide comment
@mattheworiordan

mattheworiordan Jan 27, 2013

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

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

@rwjblue rwjblue referenced this issue in rails/spring Feb 26, 2013

Closed

Issues with testing gems #83

noahpatterson pushed a commit to noahpatterson/DCOpen211DCConnect that referenced this issue Mar 17, 2014

Allow contributors to use Zeus for fast Rails commands & tests
[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