This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -288,7 +288,26 @@ def let(name, &block)
288
288
raise (
289
289
"#let or #subject called with a reserved name #initialize"
290
290
) if :initialize == name
291
- MemoizedHelpers . module_for ( self ) . __send__ ( :define_method , name , &block )
291
+ our_module = MemoizedHelpers . module_for ( self )
292
+
293
+ # If we have a module clash in our helper module
294
+ # then we need to remove it to prevent a warning.
295
+ #
296
+ # Note we do not check ancestor modules (see: `instance_methods(false)`)
297
+ # as we can override them.
298
+ if our_module . instance_methods ( false ) . include? ( name )
299
+ our_module . __send__ ( :remove_method , name )
300
+ end
301
+ our_module . __send__ ( :define_method , name , &block )
302
+
303
+ # If we have a module clash in the example module
304
+ # then we need to remove it to prevent a warning.
305
+ #
306
+ # Note we do not check ancestor modules (see: `instance_methods(false)`)
307
+ # as we can override them.
308
+ if instance_methods ( false ) . include? ( name )
309
+ remove_method ( name )
310
+ end
292
311
293
312
# Apply the memoization. The method has been defined in an ancestor
294
313
# module so we can use `super` here to get the value.
Original file line number Diff line number Diff line change 66
66
expect ( group . new . foo ) . to eq ( 'foo' )
67
67
end
68
68
69
+ it 'supports overriding let without warnings' do
70
+ shared = Module . new do
71
+ extend RSpec ::SharedContext
72
+ let ( :foo ) { 'foo' }
73
+ end
74
+ group = RSpec . describe do
75
+ include shared
76
+ let ( :foo ) { 'bar' }
77
+ end
78
+
79
+ expect ( group . new . foo ) . to eq ( 'bar' )
80
+ end
81
+
69
82
it "supports let when applied to an individual example via metadata" do
70
83
shared = Module . new do
71
84
extend RSpec ::SharedContext
You can’t perform that action at this time.
0 commit comments