Skip to content

Insert rspec setup code into generated binstub #20

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

Closed
wants to merge 1 commit into from

Conversation

merhard
Copy link

@merhard merhard commented Jul 14, 2014

This code relies on code in this pull request and should NOT be merged until the other pull request is merged. At that time, the gemspec may also be updated to depend on the newer version of the spring gem.

@@ -12,6 +12,10 @@ def exec_name
def gem_name
"rspec-core"
end

def binstub_code
"RSpec.configuration.start_time = Time.now"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused an error for me unless preceded with require rspec/core. Please see #18 (comment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ac03cce per chat on #18

@merhard
Copy link
Author

merhard commented Aug 16, 2014

The spring pull request was merged. This pull request can now be merged. The gemspec does not need to depend on the next version of spring, since this change doesn't break any functionality.

@willbryant
Copy link

Wouldn't that only work if using binstubs? I've been trying out the following, which seems to work in the non-binstub case too:

    Spring.after_fork { ::RSpec.configuration.start_time = Time.now }

@merhard
Copy link
Author

merhard commented Aug 18, 2014

@willbryant Yes, this issue fix will only work if the rspec binstub this gem provides is generated. If the binstub is generated, it will work whether spring rspec or bin/rspec is used to run the specs, since spring defaults to using the binstub if it exists.
Any idea how to have this gem handle that code block automatically? It seems out of the scope of this gem to have a generator append to or create either ~/.spring.rb or config/spring.rb to add that line.
Maybe merge this pull request to automatically help people using binstubs and add that line to the README for people not using binstubs?

@merhard
Copy link
Author

merhard commented Aug 18, 2014

@willbryant Also, does #18 (comment) fix the issue for you? I found it did for me without adding any extra code to my project's binstubs or spring configs.

@jonleighton
Copy link
Owner

Would it work to define the following instead?

class Spring::Commands::RSpec
  def call
    RSpec.configuration.start_time = Time.now
    load Gem.bin_path("rspec-core", "rspec")
  end
end

Working around the issue in the binstub feels wrong to me.

@merhard
Copy link
Author

merhard commented Aug 20, 2014

@jonleighton My testing shows that would work. I can close this pull request and open a new one if you want.
I am not sure that the issue this is meant to solve is even an issue. Per #18 (comment), I no longer have this issue in my app after changing guard-rspec in my Gemfile to match that gem's README. I believe @nilbus and @zorab47 are also using guard-rspec per their comments here: guard/guard-rspec#268, but I am not sure if the Gemfile change fixes this for anyone other than me.

@jonleighton
Copy link
Owner

My guess is that this issue affects anyone who ends up requiring rspec at application boot time, rather than in their spec helper. I'd be happy to merge a PR which takes the above approach. Thanks.

@merhard
Copy link
Author

merhard commented Aug 20, 2014

I have added a new pull request here: #22.

I am closing this one since the issue this was designed to fix will be fixed by that pull request instead.

@merhard merhard closed this Aug 20, 2014
jonleighton referenced this pull request in rails/spring Nov 15, 2014
Allow arbitrary setup code to be inserted into binstub
jonleighton added a commit to rails/spring that referenced this pull request Nov 22, 2014
This reverts commit 2480a8e, reversing
changes made to 9cd21d2.

Revert "Changelog: binstub_prelude support for commands. #329."

This reverts commit 8a3546d.

Conflicts:
	CHANGELOG.md

Reasoning:

* #329 (comment)
* jonleighton/spring-commands-rspec#20 (comment)
* 2480a8e

Since the thing that this feature was aiming to allow is already
possible via the commands API, I prefer not to add an extra feature to
Spring.
JulianSage added a commit to JulianSage/spring that referenced this pull request Oct 23, 2024
This reverts commit 2480a8eb4e88ad720e3d5a30bc23b53201673d58, reversing
changes made to 9cd21d2249fdc33477dfc99f0e99c5d307108447.

Revert "Changelog: binstub_prelude support for commands. #329."

This reverts commit 8a3546d15892f28f19787d88e4a834e68b91c438.

Conflicts:
	CHANGELOG.md

Reasoning:

* rails/spring#329 (comment)
* jonleighton/spring-commands-rspec#20 (comment)
* rails/spring@2480a8e

Since the thing that this feature was aiming to allow is already
possible via the commands API, I prefer not to add an extra feature to
Spring.
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

Successfully merging this pull request may close these issues.

4 participants