Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor specs and remove unnecessary code

* The specification for the file and line number were only necessary
  when using string class_eval. Now that the code uses define_method
  it is no longer necessary since ruby takes care of those details.
  • Loading branch information...
commit bda21abaca8dff82464866297665f70fd2eca42c 1 parent 0967ebd
@dkubb authored
View
2  lib/adamantium.rb
@@ -30,7 +30,6 @@ def self.included(descendant)
super
descendant.send(:include, Adamantium)
descendant.extend(self)
-
self
end
end
@@ -94,7 +93,6 @@ def memoize(name, value)
unless memory.key?(name)
store_memory(name, freeze_object(value))
end
-
self
end
View
15 lib/adamantium/freezer.rb
@@ -100,12 +100,9 @@ class OptionError < RuntimeError; end
# @api private
def self.get(name)
case name
- when :noop
- Noop
- when :deep
- Deep
- when :flat
- Flat
+ when :noop then Noop
+ when :deep then Deep
+ when :flat then Flat
else
raise UnknownFreezerError, "Freezer with name #{name.inspect} is unknown"
end
@@ -126,14 +123,10 @@ def self.get(name)
#
def self.parse(options)
keys = options.keys - [:freezer]
-
unless keys.empty?
raise OptionError, "Unknown option key(s) for memoizer #{keys.inspect}"
end
-
- return unless options.key?(:freezer)
-
- get(options.fetch(:freezer))
+ get(options.fetch(:freezer)) if options.key?(:freezer)
end
end
end
View
27 spec/unit/adamantium/module_methods/memoize_spec.rb
@@ -13,31 +13,7 @@
it 'creates a method that returns a same value' do
subject
instance = object.new
- first = instance.send(method)
- second = instance.send(method)
- first.should be(second)
- end
-
- specification = proc do
- subject
- if method != :some_state
- file, line = object.new.send(method).first.split(':')[0, 2]
- File.expand_path(file).should eql(File.expand_path('../../../../../lib/adamantium/module_methods.rb', __FILE__))
- line.to_i.should eql(84)
- end
- end
-
- it 'sets the file and line number properly' do
- # Exclude example for methot that does not return caller
- if method == :some_method
- return
- end
-
- if RUBY_PLATFORM.include?('java')
- pending('Kernel#caller returns the incorrect line number in JRuby', &specification)
- else
- instance_eval(&specification)
- end
+ instance.send(method).should be(instance.send(method))
end
context 'when the initializer calls the memoized method' do
@@ -60,6 +36,7 @@
describe Adamantium::ModuleMethods, '#memoize' do
subject { object.memoize(method, options) }
+
let(:options) { {} }
let(:object) do
Please sign in to comment.
Something went wrong with that request. Please try again.