Bug in subject memoization #766

Closed
exviva opened this Issue Jan 3, 2013 · 6 comments

Comments

Projects
None yet
2 participants
Contributor

exviva commented Jan 3, 2013

Today I wanted to play around with the new superpowers of let and subject, but ran into some issues, exposed in exviva/rspec-core@3041a3b.

I'd expect subject to be memoized and return the same object in before, let and it blocks, but for some reason all the examples from the commit fail, in all 3 contexts.

I thought this would have to do with the recent changes in the way subject was implemented, but weirdly enough, in v2.12.2, one shared example fails, in all 3 contexts:

its(:object_id) { should eq(subject_id_in_let) }

I tried to find a solution, but no luck, maybe you could help out? I'll gladly submit a proper PR when we find out what's going on.

Contributor

exviva commented Jan 3, 2013

Let me just add that I've started this commit without shared_examples_for, with same results, so that's not the problem.

Owner

myronmarston commented Jan 3, 2013

Thanks for testing things out and finding this bug! Your failing spec is really helpful, too.

I think there are two problems here:

  • The implicit subject is no longer memoized as of 19dd6b2. We apparently lack a spec to protect against regressions here, and I didn't realize it at the time.
  • There's something funky going on with its. It looks like it may have depended upon the old subject implementation. Plus the current implementation is a bit weird.

Want to take a stab at fixing either of these?

Contributor

exviva commented Jan 4, 2013

@myronmarston thanks for your input. I'm going to dig into it.

Contributor

exviva commented Jan 4, 2013

I'm not sure why its does not play well with memoization - I think it has to do with the fact, that multiple instances of subject try to put something in the same memo hash via let, so when chaining super()s, they're not properly retrieved from the memo. There's so much metaprogramming going on, however, that I'm not sure anymore :).

Contributor

exviva commented Jan 4, 2013

Here's a stab at refactoring its - still failing though: exviva/rspec-core@c968d02.

Any ideas? :)

Contributor

exviva commented Jan 8, 2013

Closed by #768

@exviva exviva closed this Jan 8, 2013

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