Skip to content
This repository

Bug in subject memoization #766

Closed
exviva opened this Issue January 03, 2013 · 6 comments

2 participants

Olek Janiszewski Myron Marston
Olek Janiszewski

Today I wanted to play around with the new superpowers of let and subject, but ran into some issues, exposed in exviva@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.

Olek Janiszewski

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

Myron Marston
Owner

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?

Olek Janiszewski

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

Olek Janiszewski

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 :).

Olek Janiszewski

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

Any ideas? :)

Olek Janiszewski

Closed by #768

Olek Janiszewski exviva closed this January 07, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.