This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ Enhancements:
38
38
39
39
* Improve pluralisation of words ending with ` s ` (like process). (Joshua Pinter, #2779 )
40
40
* Add ordering by file modification time (most recent first). (Matheus Richard, #2778 )
41
+ * Extend reserved memoized helper name checking for #let and #subject. (Nick Flückiger, #2886 )
41
42
42
43
Bug fixes:
43
44
Original file line number Diff line number Diff line change @@ -236,9 +236,13 @@ def let(name, &block)
236
236
# We have to pass the block directly to `define_method` to
237
237
# allow it to use method constructs like `super` and `return`.
238
238
raise "#let or #subject called without a block" if block . nil?
239
- raise (
240
- "#let or #subject called with a reserved name #initialize"
241
- ) if :initialize == name
239
+
240
+ # A list of reserved words that can't be used as a name for a memoized helper
241
+ # Matches for both symbols and passed strings
242
+ if [ :initialize , :to_s ] . include? ( name . to_sym )
243
+ raise ArgumentError , "#let or #subject called with reserved name `#{ name } `"
244
+ end
245
+
242
246
our_module = MemoizedHelpers . module_for ( self )
243
247
244
248
# If we have a module clash in our helper module
Original file line number Diff line number Diff line change @@ -520,10 +520,28 @@ def count
520
520
end . to raise_error ( /#let or #subject called without a block/ )
521
521
end
522
522
523
- it 'raises an error when attempting to define a reserved method name' do
523
+ it 'raises an error when attempting to define a reserved name #initialize ' do
524
524
expect do
525
- RSpec . describe { let ( :initialize ) { true } }
526
- end . to raise_error ( /#let or #subject called with a reserved name #initialize/ )
525
+ RSpec . describe { let ( :initialize ) { true } }
526
+ end . to raise_error ( /#let or #subject called with reserved name `initialize`/ )
527
+ end
528
+
529
+ it 'raises an error when attempting to define a reserved name #initialize as a string' do
530
+ expect do
531
+ RSpec . describe { let ( 'initialize' ) { true } }
532
+ end . to raise_error ( /#let or #subject called with reserved name `initialize`/ )
533
+ end
534
+
535
+ it 'raises an error when attempting to define a reserved name #to_s' do
536
+ expect do
537
+ RSpec . describe { let ( :to_s ) { true } }
538
+ end . to raise_error ( /#let or #subject called with reserved name `to_s`/ )
539
+ end
540
+
541
+ it 'raises an error when attempting to define a reserved name #to_s as a string' do
542
+ expect do
543
+ RSpec . describe { let ( 'to_s' ) { true } }
544
+ end . to raise_error ( /#let or #subject called with reserved name `to_s`/ )
527
545
end
528
546
529
547
let ( :a_value ) { "a string" }
You can’t perform that action at this time.
0 commit comments