Skip to content
This repository
Browse code

use `define_method` instead of `let` for named subject

`subject` already memoizes the value
  • Loading branch information...
commit f87dfbfabf7b816c9d68d6417c8ba946ecb999cb 1 parent 0592aca
David Chelimsky dchelimsky authored

Showing 2 changed files with 1 addition and 2 deletions. Show diff stats Hide diff stats

  1. +0 1  lib/rspec/core/let.rb
  2. +1 1  lib/rspec/core/subject.rb
1  lib/rspec/core/let.rb
@@ -105,7 +105,6 @@ def self.included(mod)
105 105 mod.extend ExampleGroupMethods
106 106 mod.__send__ :include, ExampleMethods
107 107 end
108   -
109 108 end
110 109 end
111 110 end
2  lib/rspec/core/subject.rb
@@ -193,7 +193,7 @@ def its(attribute, &block)
193 193 # @see ExampleMethods#subject
194 194 # @see ExampleMethods#should
195 195 def subject(name=nil, &block)
196   - let(name) { subject } if name
  196 + define_method(name) { subject } if name
197 197 block ? @explicit_subject_block = block : explicit_subject || implicit_subject
198 198 end
199 199

0 comments on commit f87dfbf

Please sign in to comment.
Something went wrong with that request. Please try again.