Skip to content

Instantly share code, notes, and snippets.

@ClayShentrup
Last active June 23, 2016 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClayShentrup/f4d4a48193dc36c4f8b1ff3f82a7b787 to your computer and use it in GitHub Desktop.
Save ClayShentrup/f4d4a48193dc36c4f8b1ff3f82a7b787 to your computer and use it in GitHub Desktop.
names_for_let_objects 2
module NamesForLetObject
def names_for_let_objects(objects)
objects.map { |object| name_for_let_object(object) }
end
def name_for_let_object(object)
__memoized.instance_variable_get(:@memoized).key(object)
end
end
expected collection contained: [:user_1]
actual collection contained: [:user_1, :user_2]
the extra elements were: [:user_2]
describe(User) do
describe('.old_enough_to_drink') do
let!(:bob) { create(:user, age: 21) }
let!(:alice) { create(:user, age: 20) }
def result
names_for_let_objects(User.all)
end
specify do
expect(result.to eq([:bob])
end
end
end
@ryanswood
Copy link

I believe that users_spec.rb line 7 should be described_class.old_enough_to_drink to be at parity with the 'before' example.

Looks good. I am going to be linking to it in my own list of engineering principles and techniques.

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