Sha256: 543a7b5d0abd3df32d87fbc9432b33ef4841cfaa4b0805b89632357ab07613fc
Contents?: true
Size: 982 Bytes
Versions: 1
Compression:
Stored size: 982 Bytes
Contents
require 'spec_helper' RSpec.describe Yaks::StatefulBuilder do class Buildable include Yaks::Attributes.new(:foo, :bar) def self.create(foo, bar) new(foo: foo, bar: bar) end def finalize update(foo: 7, bar: 8) end def wrong_type(x, y) "foo #{x} #{y}" end end subject { Yaks::StatefulBuilder.new(Buildable, [:foo, :bar, :update, :finalize, :wrong_type]) } it 'should keep state' do expect( subject.create(3, 4) do foo 7 update bar: 6 end.to_h ).to eql(foo: 7, bar: 6) end it 'should unwrap again' do expect( subject.create(3, 4) { finalize } ).to eql Buildable.new(foo: 7, bar: 8) end describe 'kind_of?' do it 'should test if the returned thing is of the right type' do expect { subject.create(3, 4) { wrong_type(1,'2') }}.to raise_exception Yaks::IllegalState, 'Buildable#wrong_type(1, "2") returned "foo 1 2". Expected instance of Buildable' end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yaks-0.6.0 | spec/unit/yaks/stateful_builder_spec.rb |