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

Lifecycle/space fixups #519

merged 22 commits into from Jan 9, 2014

Lifecycle/space fixups #519

merged 22 commits into from Jan 9, 2014


Copy link

@myronmarston myronmarston commented Jan 4, 2014

This is the start of addressing a bunch of issues.

  • Fixes #165 -- stop resetting mock proxies twice at the end of each example
  • Fixes #352 -- make test doubles self-destruct after they are torn down.
  • Fixes #240 -- adds with_temporary_scope.

Ready for review.

myronmarston added 10 commits Jan 4, 2014
We don't need to reset the mock proxy while verifying it.
That'll happen later during the teardown phase.

It looks like the main reason we were doing this was
to assist with rspec-mocks testing itself; we would
verify the middle of an example to assert a mock expectation
failure, and a `reset` is needed so it doesn't fail again
when rspec-core calls `verify` as well.

The solution is to use spec helper methods that perform
the reset when we verify in the middle of an example.

I don't have any evidence this improves perf, but it
seems reasonable to assume that removing an extra method
call per example can only make it faster (however slight
the improvement may be).

Fixes #165.
The logic that required this test was removed in cd81094.
We're going to change the behavior of test doubles
that have been reset (so that they "expire" and can
no longer be used). This spec was originally added in
847c66d where the
point was to address an error while resetting a test
double (which, in turn caused that method double
to stick around into later examples and continue to
The second part of this spec was added in
9357e4d. We are
changing test doubles so that they self-destruct
after being reset. Currently, `verify` also
resets, so verifying a test double twice
will no longer be allowed.
We're going to change how pure test doubles behave
after teardown, so update this to focus on partial
doubles (which will not be changed).
Test doubles are not designed to be used outside of
the example they were created in.
Also, document some of them as public since
users may want to rescue them, or specify
a block will raise one of these errors
(e.g. in an rspec-mocks extension gem).
There's no need for a separate file and there's
going to be a bit of interaction between multiple
spaces at various layers in a stack so having it
in one file will make it easier to see how it relates.
* This should be faster (but almost certainly not
  noticably so).
* It was odd to expose these methods off of `RSpec::Mocks`
  given that they are not intended for usage outside
* We weren't getting any benefit from these except
  for not having to type `.space`.
Copy link

penelopezone commented Jan 4, 2014

@myronmarston I took a look through this. Looks good :)

myronmarston added 11 commits Jan 5, 2014
When rspec-expectations tries to diff the object in
a failure message, it blows up when the `pp` library
tries to print it.
This unifies global storage of modified things in one place.
- Make it more general (it's not just about stubbing).
- Remove unused lines.
- Improve doc output (`include_examples` does not
  create a nested group).
- It was duplicated in Proxy.
- Makes more sense to initialize it in Space init.
rspec-mocks lacks the necessary sandboxing to safely
define and run examples from within examples.
rspec-core has and uses this but it's not exposed
for use here.

Instead, we can just trigger the teardown/setup
that happens between examples.

This fixes some rspec-mocks space leakage
that was happening.
Not sure how we wound up with two separate files, anyway.
Since we now use a new space instance per example,
we don't need to clear its collections when resetting.
Before this was necessary because we kept a space instance
that we would keep using for the lifetime of the process.

Constant mutators weren't being reset idempotently, so I
had to tweak them a bit.
@@ -37,7 +25,8 @@ def self.verify
# each example, even if an error was raised during the example.
def self.teardown
space.reset_all = ERROR_SPACE
Copy link

@JonRowe JonRowe Jan 7, 2014

Choose a reason for hiding this comment

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

You could combine these two lines to @space = @space_stack.pop || @root_space no?

Copy link
Member Author

@myronmarston myronmarston Jan 7, 2014

Choose a reason for hiding this comment

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

Nope. @space should be set to @space_stack.last after popping.

Copy link

@JonRowe JonRowe Jan 7, 2014

Choose a reason for hiding this comment

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


Copy link

JonRowe commented Jan 7, 2014

Looking good so far but I left a few notes :)

This is our preferred convention.
myronmarston added a commit that referenced this issue Jan 9, 2014
@myronmarston myronmarston merged commit 8615dc2 into master Jan 9, 2014
1 check passed
@myronmarston myronmarston deleted the lifecycle-space-fixups branch Jan 9, 2014
@myronmarston myronmarston mentioned this pull request Feb 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
3 participants