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 @@ -5,6 +5,7 @@ Enhancements:
5
5
6
6
* Improve pluralisation of words ending with ` s ` (like process). (Joshua Pinter, #2779 )
7
7
* Add ordering by file modification time (most recent first). (Matheus Richard, #2778 )
8
+ * Extend reserved memoized helper name checking for #let and #subject. (Nick Flückiger, #2886 )
8
9
9
10
Bug fixes:
10
11
Original file line number Diff line number Diff line change @@ -307,9 +307,13 @@ def let(name, &block)
307
307
# We have to pass the block directly to `define_method` to
308
308
# allow it to use method constructs like `super` and `return`.
309
309
raise "#let or #subject called without a block" if block . nil?
310
- raise (
311
- "#let or #subject called with a reserved name #initialize"
312
- ) if :initialize == name
310
+
311
+ # A list of reserved words that can't be used as a name for a memoized helper
312
+ # Matches for both symbols and passed strings
313
+ if [ :initialize , :to_s ] . include? ( name . to_sym )
314
+ raise ArgumentError , "#let or #subject called with reserved name `#{ name } `"
315
+ end
316
+
313
317
our_module = MemoizedHelpers . module_for ( self )
314
318
315
319
# 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