Skip to content

#let fails in an ugly way when accidentally called without a block

gitlab-qa-bot requested to merge github/fork/rubiii/let-without-a-block into master

Created by: rubiii

here's the error rspec raises when this happens:

ArgumentError:
  tried to create Proc object without a block
# ./spec/rspec/core/memoized_helpers_spec.rb:490:in `block (3 levels) in <module:Core>'
# ./spec/rspec/core/memoized_helpers_spec.rb:490:in `block (2 levels) in <module:Core>'

took me a minute to figure out what went wrong. especially because:

  1. it works on my mac but fails on travis. same versions and everything.
  2. i was actually calling #subject without a block which delegates to #let.
  3. i had to tell rake (which runs the specs on travis) to output complete stacktraces to even find that line.

so i'm not really sure how to proceed and would like to hear your thoughts.

i would suggest to add a guard clause and at least change the error message to tell the user what went wrong. not sure if you would change the error type though. and maybe the error could even point to the line of code which calls #let, but i don't know if there's a cheap and reliable way to do this through the caller.

Merge request reports