spec/lib/sinclair/class_methods_spec.rb in sinclair-2.0.0 vs spec/lib/sinclair/class_methods_spec.rb in sinclair-2.0.1

- old
+ new

@@ -8,28 +8,28 @@ let(:options) { {} } let(:instance) { dummy_class.new } let(:dummy_class) { Class.new } let(:builder_class) { Sinclair } - describe '#build' do + describe '.build' do let(:block) do method_name = :some_method value = 1 proc do add_method(method_name) { value } end end it 'executes the block and builds' do - expect { builder_class.build(dummy_class, options, &block) } + expect { builder_class.build(dummy_class, **options, &block) } .to add_method(:some_method).to(dummy_class) end context 'when the method is built and called' do before do - builder_class.build(dummy_class, options, &block) + builder_class.build(dummy_class, **options, &block) end it 'returns the value' do expect(instance.some_method).to eq(1) end @@ -44,11 +44,31 @@ end end end it 'executes the block and builds' do - expect { builder_class.build(dummy_class, options) } + expect { builder_class.build(dummy_class, **options) } .to add_method(:some_method).to(dummy_class) + end + end + + context 'when a block is given and initialization contains more arguments' do + let(:builder_class) { ComplexBuilder } + let(:value) { Random.rand(10..30) } + let(:power) { Random.rand(3..5) } + let(:result) { value**power } + + it 'executes the block and builds' do + expect { builder_class.build(dummy_class, value, power, &:add_default) } + .to add_method(:result).to(dummy_class) + end + + context 'when the method is called' do + before { builder_class.build(dummy_class, value, power, &:add_default) } + + it 'returns the evaluated value' do + expect(instance.result).to eq(result) + end end end end end