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

Allow rspec-core to be used without -expectations or -mocks. #1615

Merged
merged 3 commits into from Jul 20, 2014

Conversation

@penelopezone
Copy link
Member

@penelopezone penelopezone commented Jun 23, 2014

We've always had the philosophy that the various RSpec components should obviously standalone. As it is at the moment, when one specifies only gem 'rspec-core' in one's Gemfile it will only pull rspec-core and rspec-support.

This does mean, however, that when a user tries to run tests with a freshly initialised project with this setup they will get a backtrace saying that neither of rspec-expectations or rspec-mocks could be loaded. This way around, if they simply want to raise to cause tests to fail, they can.

I was chatting with @tomstuart at a conference recently. He said that whilst he was teaching RSpec he likes to show each piece working on its own, before showing them together. He lamented that he has to sweep modifying the spec_helper configuration under the table and that it'd be nice if this just worked out of the box.

At the same conference @hone02 stated that he likes to use RSpec's runner, but the sorts of things he's running merely require raises after conditional checks and so he doesn't really want to load either -mocks or -expectations.

I guess basically, the question is: is this a feature that we want to have as part of RSpec Core, or is the current setup where you have to modify your spec_helper acceptable?

@tomstuart
Copy link
Contributor

@tomstuart tomstuart commented Jun 23, 2014

Thanks for this, @samphippen. You’ve accurately summarised my position.

Tangentially: I’ve said before that it’d be nice if #expect_with supported :nothing rather than needing the obtuse Module.new, but with this change I suppose that doesn’t matter much, because I can’t think of any use case for expect_with :nothing if it’s essentially the default whenever rspec-expectations isn’t loadable.

::RSpec::Matchers
rescue LoadError
Module.new
end

This comment has been minimized.

@tomstuart

tomstuart Jun 23, 2014
Contributor

I’m concerned that this implementation allows an explicit RSpec.configuration.expect_with :rspec to fail silently when rspec-expectations isn’t loadable.

Might it be better to do the begin/rescue inside #expectation_frameworks, since that’s where the defaulting happens? That would more closely mirror the mock_with behaviour, and you’d still get an exception if you said expect_with :rspec without being able to load rspec-expectations.

This comment has been minimized.

@penelopezone

penelopezone Jun 23, 2014
Author Member

I agree, that's a really good note. I'll move it.

@myronmarston
Copy link
Member

@myronmarston myronmarston commented Jun 23, 2014

I like this idea. Would be nice to have a cuke for this case....I think you can simulate it by having a Given only rspec-core is installed step that adds --disable-gems to RUBYOPT and also mutates $LOAD_PATH and rejects rspec-expectations and rspec-mocks from that list (such as via a file loaded by a --require option). It could then demonstrate that attempting to use rspec-mocks and rspec-expectations APIs fail, but that you can use simple raise statements to trigger failures.

@JonRowe
Copy link
Member

@JonRowe JonRowe commented Jun 23, 2014

I also like this idea, I'm surprised we hadn't had this crop up before :)

@penelopezone
Copy link
Member Author

@penelopezone penelopezone commented Jun 24, 2014

@myronmarston I had a look around the features directory and I couldn't see anywhere obvious to place the feature. Do you have any thoughts?

@myronmarston
Copy link
Member

@myronmarston myronmarston commented Jun 26, 2014

@myronmarston I had a look around the features directory and I couldn't see anywhere obvious to place the feature. Do you have any thoughts?

You could a top-level use-only-rspec-core cuke.

@myronmarston
Copy link
Member

@myronmarston myronmarston commented Jul 15, 2014

@samphippen -- do you plan to get back to this soon?

@penelopezone
Copy link
Member Author

@penelopezone penelopezone commented Jul 15, 2014

Yeah, I'm hoping to loop around on it this weekend. Work has gotten insane again.

@penelopezone
Copy link
Member Author

@penelopezone penelopezone commented Jul 19, 2014

@myronmarston I gave this a go, the problem is aruba appears to use RSpec's matchers api, so the execution step fails. I'm not really sure what to do because they've been stripped out of the load path. Thoughts?

@myronmarston
Copy link
Member

@myronmarston myronmarston commented Jul 19, 2014

Push what you have and I'll take a look.

Sent from my iPhone

On Jul 19, 2014, at 7:20 AM, Sam Phippen notifications@github.com wrote:

@myronmarston I gave this a go, the problem is aruba appears to use RSpec's matchers api, so the execution step fails. I'm not really sure what to do because they've been stripped out of the load path. Thoughts?


Reply to this email directly or view it on GitHub.

@penelopezone
Copy link
Member Author

@penelopezone penelopezone commented Jul 19, 2014

Already did.

@penelopezone
Copy link
Member Author

@penelopezone penelopezone commented Jul 19, 2014

@myronmarston fwiw I tried doing it in the step instead of an around hook and that failed even earlier, so the step is still there but empty.

@myronmarston
Copy link
Member

@myronmarston myronmarston commented Jul 19, 2014

@samphippen -- I pushed a fix. The main problem is that you were manipulating $LOAD_PATH in the aruba process (which caused rspec-expectations autoloads to fail from within that process) rather than manipulating it in the RSpec process. I also cleaned things up a bunch. Let me know what you think.

@penelopezone
Copy link
Member Author

@penelopezone penelopezone commented Jul 19, 2014

@myronmarston LGTM, thanks for the fix.

@myronmarston
Copy link
Member

@myronmarston myronmarston commented Jul 19, 2014

Cool, I'll take care of squashing and merging this later.

myronmarston added a commit that referenced this pull request Jul 19, 2014
@myronmarston
Copy link
Member

@myronmarston myronmarston commented Jul 19, 2014

OK, I rebased, squashed, added a changelog, and made a few more edits. I plan to merge when green.

@penelopezone
Copy link
Member Author

@penelopezone penelopezone commented Jul 19, 2014

👍 /cc @tomstuart :))))))))

Sam Phippen and others added 3 commits Jun 23, 2014
At the moment if one wants to use RSpec's runner in standalone mode one
must first disable the default mocking/expectation adapters.

This patch silently sets up no mocking or expecting framework if the
default configuration is used but only 'rspec-core' is present in the
Gemfile.
Change require_expect_syntax_in_aruba_specs.rb to use the newer
`disable_monkey_patching!` option rather than configuring expectations
and mocks. Configuring those libs directly would fail when they
have been removed from the load path, and `disable_monkey_patching!`
provides the overall effect we want: monkey patching is removed
from all pieces of RSpec we use.
myronmarston added a commit that referenced this pull request Jul 20, 2014
Allow rspec-core to be used without -expectations or -mocks.
@myronmarston myronmarston merged commit 72bd83a into master Jul 20, 2014
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
@myronmarston myronmarston deleted the core-standalone branch Jul 20, 2014
@tomstuart
Copy link
Contributor

@tomstuart tomstuart commented Jul 20, 2014

Thank you!

MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
Allow rspec-core to be used without -expectations or -mocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.