Permalink
Browse files

extract Let and supporting methods to separate module

  • Loading branch information...
1 parent d0b3159 commit a17d693ee06eef1a68a7d49f4cb57e5dcfc1c13f @dchelimsky dchelimsky committed Mar 3, 2010
Showing with 30 additions and 10 deletions.
  1. +1 −0 lib/rspec/core.rb
  2. +1 −10 lib/rspec/core/example_group.rb
  3. +28 −0 lib/rspec/core/let.rb
View
@@ -1,4 +1,5 @@
require 'rspec/core/load_path'
+require 'rspec/core/let'
require 'rspec/core/deprecation'
require 'rspec/core/mocking/with_absolutely_nothing'
require 'rspec/core/around_proxy'
@@ -7,6 +7,7 @@ module Core
class ExampleGroup
extend Advice
include ExampleGroupSubject
+ include Let
attr_accessor :running_example
@@ -200,12 +201,6 @@ def self.to_s
self == Rspec::Core::ExampleGroup ? 'Rspec::Core::ExampleGroup' : name
end
- def self.let(name, &block)
- define_method(name) do
- __memoized[name] ||= instance_eval(&block)
- end
- end
-
def self.all_apply?(filters)
metadata.all_apply?(filters)
end
@@ -214,10 +209,6 @@ def described_class
self.class.describes
end
- def __memoized
- @__memoized ||= {}
- end
-
def __reset__
instance_variables.each { |ivar| remove_instance_variable(ivar) }
__memoized.clear
View
@@ -0,0 +1,28 @@
+module Rspec
+ module Core
+
+ module Let
+
+ module ClassMethods
+ def let(name, &block)
+ define_method(name) do
+ __memoized[name] ||= instance_eval(&block)
+ end
+ end
+ end
+
+ module InstanceMethods
+ def __memoized
+ @__memoized ||= {}
+ end
+ end
+
+ def self.included(mod)
+ mod.extend ClassMethods
+ mod.__send__ :include, InstanceMethods
+ end
+
+ end
+
+ end
+end

0 comments on commit a17d693

Please sign in to comment.