This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -288,7 +288,20 @@ 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 this module, (e.g. the `include_super = false`)
294
+ # then we need to remove it to prevent a warning
295
+ if our_module . instance_methods ( false ) . include? ( name )
296
+ our_module . __send__ ( :remove_method , name )
297
+ end
298
+ our_module . __send__ ( :define_method , name , &block )
299
+
300
+ # If we have a module clash in the example module, (e.g. the `include_super = false`)
301
+ # then we need to remove it to prevent a warning
302
+ if instance_methods ( false ) . include? ( name )
303
+ remove_method ( name )
304
+ end
292
305
293
306
# Apply the memoization. The method has been defined in an ancestor
294
307
# 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