spec/unit/adamantium/module_methods/memoize_spec.rb in adamantium-0.0.2 vs spec/unit/adamantium/module_methods/memoize_spec.rb in adamantium-0.0.3
- old
+ new
@@ -8,23 +8,33 @@
subject
instance = object.new
instance.send(method).should equal(instance.send(method))
end
- it 'creates a method that returns a frozen value' do
+ it 'creates a method that returns a same value' do
subject
- object.new.send(method).should be_frozen
+ instance = object.new
+ first = instance.send(method)
+ second = instance.send(method)
+ first.should be(second)
end
specification = proc do
subject
- file, line = object.new.send(method).first.split(':')[0, 2]
- File.expand_path(file).should eql(File.expand_path('../../../../../lib/adamantium.rb', __FILE__))
- line.to_i.should eql(211)
+ 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(80)
+ 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
@@ -47,23 +57,64 @@
end
end
end
describe Adamantium::ModuleMethods, '#memoize' do
- subject { object.memoize(method) }
+ subject { object.memoize(method, options) }
+ let(:options) { {} }
- let(:object) { Class.new(AdamantiumSpecs::Object) }
+ let(:object) do
+ Class.new(AdamantiumSpecs::Object) do
+ def some_state
+ Object.new
+ end
+ end
+ end
+ context 'with :noop freezer option' do
+ let(:method) { :some_state }
+ let(:options) { { :freezer => :noop } }
+
+ it_should_behave_like 'a command method'
+ it_should_behave_like 'memoizes method'
+
+ it 'is still a public method' do
+ should be_public_method_defined(method)
+ end
+
+ it 'creates a method that returns a non frozen value' do
+ subject
+ object.new.send(method).should_not be_frozen
+ end
+ end
+
+ context 'memoized method that returns generated values' do
+ let(:method) { :some_state }
+
+ it_should_behave_like 'a command method'
+ it_should_behave_like 'memoizes method'
+
+ it 'creates a method that returns a frozen value' do
+ subject
+ object.new.send(method).should be_frozen
+ end
+ end
+
context 'public method' do
let(:method) { :public_method }
it_should_behave_like 'a command method'
it_should_behave_like 'memoizes method'
it 'is still a public method' do
should be_public_method_defined(method)
end
+
+ it 'creates a method that returns a frozen value' do
+ subject
+ object.new.send(method).should be_frozen
+ end
end
context 'protected method' do
let(:method) { :protected_method }
@@ -71,18 +122,28 @@
it_should_behave_like 'memoizes method'
it 'is still a protected method' do
should be_protected_method_defined(method)
end
+
+ it 'creates a method that returns a frozen value' do
+ subject
+ object.new.send(method).should be_frozen
+ end
end
context 'private method' do
let(:method) { :private_method }
it_should_behave_like 'a command method'
it_should_behave_like 'memoizes method'
it 'is still a private method' do
should be_private_method_defined(method)
+ end
+
+ it 'creates a method that returns a frozen value' do
+ subject
+ object.new.send(method).should be_frozen
end
end
end