Sha256: 0a9ca6e54272b81df03efb47e6a9768ff45bbb81f23477f2590c540920f39ad2
Contents?: true
Size: 1.74 KB
Versions: 68
Compression:
Stored size: 1.74 KB
Contents
require 'spec_helper' require 'flydata-core/wrapper_forwardable' module FlydataCore describe WrapperSingleForwardable do class Target def self.foo(a, b) target_foo_result end end class Test extend WrapperSingleForwardable def_wrapper_single_delegator Target, :foo def initialize(item) @item = item end def ==(other) @item == other.item end attr_reader :item end let(:subject_object) { Test } let(:args) { [ 'arg1', 'arg2' ] } describe '.def_wrapper_single_delegator' do it 'defines a class method of the given name to the subject class' do expect(subject_object.respond_to?(:foo)).to eq true end describe 'the method defined by it' do subject { subject_object.foo(*args) } before do expect(Target).to receive(:foo).with(*args). and_return(target_foo_result) end context 'when the target method returns an object' do let(:target_foo_result) { double('single_object') } it 'returns an object of the subject class containing the target result' do is_expected.to eq subject_object.new(target_foo_result) end end context 'when the target method returns nil' do let(:target_foo_result) { nil } it 'returns nil' do is_expected.to eq nil end end context 'when the target method returns an array' do let(:target_foo_result) { [ double('object1'), double('object2') ] } it 'returns an array of instances of the subject class. Each instance contains an object returned from the target' do is_expected.to eq target_foo_result.collect{|item| subject_object.new(item) } end end end end end end
Version data entries
68 entries across 68 versions & 1 rubygems