spec/unit/adamantium/module_methods/memoize_spec.rb in adamantium-0.1.0 vs spec/unit/adamantium/module_methods/memoize_spec.rb in adamantium-0.2.0

- old
+ new

@@ -7,37 +7,30 @@ it 'memoizes the instance method' do subject instance = object.new expect(instance.send(method)).to be(instance.send(method)) end +end - it 'creates a method that returns a same value' do - subject - instance = object.new - expect(instance.send(method)).to be(instance.send(method)) - end - +shared_examples_for 'wraps original method' do it 'creates a method with an arity of 0' do subject expect(object.new.method(method).arity).to be_zero end context 'when the initializer calls the memoized method' do + it_should_behave_like 'memoizes method' + before do method = self.method object.send(:define_method, :initialize) { send(method) } end it 'allows the memoized method to be called within the initializer' do subject expect { object.new }.to_not raise_error end - - it 'memoizes the methdod inside the initializer' do - subject - expect(object.new.memoized(method)).to_not be_nil - end end end describe Adamantium::ModuleMethods, '#memoize' do subject { object.memoize(method, options) } @@ -54,20 +47,20 @@ context 'on method with arguments' do let(:method) { :argumented } it 'should raise error' do - expect { subject }.to raise_error(ArgumentError, 'Cannot memoize method with nonzero arity') + expect { subject }.to raise_error(ArgumentError, "Cannot memoize #{object}#argumented, its arity is 1") 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_should_behave_like 'wraps original method' it 'is still a public method' do should be_public_method_defined(method) end @@ -80,10 +73,11 @@ 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_should_behave_like 'wraps original method' it 'creates a method that returns a frozen value' do subject expect(object.new.send(method)).to be_frozen end @@ -92,9 +86,10 @@ context 'public method' do let(:method) { :public_method } it_should_behave_like 'a command method' it_should_behave_like 'memoizes method' + it_should_behave_like 'wraps original method' it 'is still a public method' do should be_public_method_defined(method) end