Fix sandboxing of rspec-core's own specs. #852

Merged
merged 1 commit into from Mar 31, 2013

Projects

None yet

2 participants

@myronmarston
Member

Because rspec-core dog-foods itself, rspec-core's spec suite has
examples that define example groups and examples and run them. The
usual lifetime of an RSpec::Mocks::Proxy is for one example
(the proxy cache gets cleared between each example), but since the
specs in rspec-core's suite sometimes create test doubles and pass
them to examples a spec defines and runs, the test double's proxy
must live beyond the inner example: it must live for the scope
of wherever it got defined. Here we implement the necessary semantics
for rspec-core's specs:

  • #verify_all and #reset_all affect only mocks that were created
    within the current scope.
  • Mock proxies live for the duration of the scope in which they are
    created.

Thus, mock proxies created in an inner example live for only that
example, but mock proxies created in an outer example can be used
in an inner example but will only be reset/verified when the outer
example completes.

These changes were needed due to the recent refactoring in rspec-mocks
which changed what held a reference to the mock proxy (a proxy cache
rather than an instance variable on the mocked object) and the
lifecycle of those proxies (cleared between each example rather
than persisted for the rest of the process).

@myronmarston myronmarston Fix sandboxing of rspec-core's own specs.
Because rspec-core dog-foods itself, rspec-core's spec suite has
examples that define example groups and examples and run them. The
usual lifetime of an RSpec::Mocks::Proxy is for one example
(the proxy cache gets cleared between each example), but since the
specs in rspec-core's suite sometimes create test doubles and pass
them to examples a spec defines and runs, the test double's proxy
must live beyond the inner example: it must live for the scope
of wherever it got defined. Here we implement the necessary semantics
for rspec-core's specs:

- #verify_all and #reset_all affect only mocks that were created
 within the current scope.
- Mock proxies live for the duration of the scope in which they are
 created.

Thus, mock proxies created in an inner example live for only that
example, but mock proxies created in an outer example can be used
in an inner example but will only be reset/verified when the outer
example completes.

These changes were needed due to the recent refactoring in rspec-mocks
which changed what held a reference to the mock proxy (a proxy cache
rather than an instance variable on the mocked object) and the
lifecycle of those proxies (cleared between each example rather
than persisted for the rest of the process).
e40d30d
@myronmarston myronmarston merged commit f4cca6f into master Mar 31, 2013

1 check passed

default The Travis build passed
Details
@myronmarston myronmarston deleted the fix_sandboxing branch Mar 31, 2013
@dchelimsky
Member

Well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment