-
Notifications
You must be signed in to change notification settings - Fork 37
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
Load time incorrect with Spring #18
Comments
Yep, I think we could/should handle this in |
I just added #!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require 'bundler/setup'
RSpec.configuration.start_time = Time.now
load Gem.bin_path('rspec-core', 'rspec') and output after running the specs looks like:
At least as a temporary fix until the gem addresses it. |
👍 |
@merhard thanks, that's a helpful and easy temporary fix. |
Thanks, this fixed my issue. Anyone want to offer a pull request to replace the binstub on install? |
A permanent fix is not straightforward. Spring generates the binstub by filling in the blanks with values provided by this gem. In other words, there's no direct way to modify the binstub in the way suggested. I see a few options.
Any other options I'm missing? What do you think is the best way to move forward? |
merhard@f05e17f Thoughts on this code as a solution? |
That should do the trick |
This fix had been working for me but is now causing an error. I'm not sure what has changed.
Based on wspurgin/rspec-sidekiq#51, adding #!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require 'bundler/setup'
require 'rspec/core'
RSpec.configuration.start_time = Time.now
load Gem.bin_path('rspec-core', 'rspec') |
Which versions of spring and rspec are you using? |
gem 'spring', '1.1.3' Dan Kohn mailto:dan@dankohn.com On Fri, Aug 1, 2014 at 8:42 AM, merhard notifications@github.com wrote:
|
@dankohn Per https://github.com/rails/spring#use-without-adding-to-bundle, shouldn't you be using Does: RSpec.configuration.start_time = Time.now if defined? RSpec.configuration work instead of: require 'rspec/core'
RSpec.configuration.start_time = Time.now ? My benchmark tests in Ruby 1.9.3 show the former to be much faster than the latter. module RSpec; end
require 'benchmark'
Benchmark.bm do |bm|
bm.report('defined false:') do
1000.times do
RSpec.configuration.start_time = Time.now if defined? RSpec.configuration
end
end
bm.report('require: ') do
1000.times do
require 'rspec/core'
RSpec.configuration.start_time = Time.now
end
end
bm.report('defined true: ') do
1000.times do
RSpec.configuration.start_time = Time.now if defined? RSpec.configuration
end
end
end
# >> user system total real
# >> defined false: 0.000000 0.000000 0.000000 ( 0.000201)
# >> require: 0.390000 0.040000 0.430000 ( 0.423843)
# >> defined true: 0.000000 0.000000 0.000000 ( 0.000687) |
Yes, your code works just as well. Thanks! Dan Kohn mailto:dan@dankohn.com On Fri, Aug 1, 2014 at 11:18 AM, merhard notifications@github.com wrote:
|
Yes, I can confirm that I'm unclear how to write a test for this, but I'm happy to test a fork. |
I noticed I put guard-rspec in my Gemfile incorrectly per its README. Replacing gem 'guard-rspec', group: :development, require: false fixed this RSpec load time issue for me. Note that I was having this issue when running my specs with and without guard. Both Is anyone's RSpec load time output still incorrect after making this change and not using the |
I believe this was fixed by #22 |
Standard practice now with Rails 4 seems to be to use Spring with
spring-commands-rspec
to generatebin/rspec
. In rspec-core, because@load_time
gets set inReporter#start
before Spring forks the rails process, the load time only gets set once, when the Spring server first starts. Every time I run my specs withbin/rspec
, I get output like this:It was really just 85 minutes ago that Spring started.
When running rspec directly (not using the binstub provided by this gem), I do not have this issue.
I originally brought up the issue rspec/rspec-core#1574 with the rspec-core team, and we agreed that this would be better addressed by the launcher. @myronmarston pointed out that rspec exposes an attribute that alternate runners can set to the current time when they begin the setup for the next run.
I think this gem probably would be the most appropriate place to address this issue, but it also seems that the API provided by
Spring::Commands
is somewhat limited and may possibly not support what we need to do. You certainly would know better than me though. What are your thoughts?The text was updated successfully, but these errors were encountered: