diff --git a/README.md b/README.md index d9005af..08611ae 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,15 @@ $ gem install transition_through ```ruby it 'should transition through' do - expect { + counter = Counter.new + count = -> { counter.count = 0 counter.count += 1 counter.count = counter.count + 3 counter.count -= 2 - }.to transition { counter.count }.through [0, 1, 4, 2] + } + + expect { count.call }.to transition { counter.count }.through [0, 1, 4, 2] end ``` diff --git a/spec/transition_through_spec.rb b/spec/transition_through_spec.rb index ea5d126..0102f48 100644 --- a/spec/transition_through_spec.rb +++ b/spec/transition_through_spec.rb @@ -5,6 +5,20 @@ RSpec.describe TransitionThrough do let(:counter) { Counter.new } + context 'using ivars' do + temporary_model :counter, table_name: nil, base_class: nil do + attr_accessor :count + + def initialize = @count = 0 + def increment(n = 1) = n.times { @count += 1 } + end + + # TODO(ezekg) not sure this is possible since you can't redefine an ivar setter + it 'should not track transitions' do + expect { counter.increment(3) }.to transition { counter.count }.through [0] + end + end + context 'using methods' do temporary_model :counter, table_name: nil, base_class: nil do attr_accessor :count @@ -67,19 +81,19 @@ def increment(n = 1) = n.times { self.count += 1 } counter.count -= 2 }.to transition { counter.count }.through [0, 1, 4, 2] end - end - context 'using ivars' do - temporary_model :counter, table_name: nil, base_class: nil do - attr_accessor :count - - def initialize = @count = 0 - def increment(n = 1) = n.times { @count += 1 } - end - - # TODO(ezekg) not sure this is possible since you can't redefine an ivar setter - it 'should not track transitions' do - expect { counter.increment(3) }.to transition { counter.count }.through [0] + describe 'README' do + it 'should transition through' do + counter = Counter.new + count = -> { + counter.count = 0 + counter.count += 1 + counter.count = counter.count + 3 + counter.count -= 2 + } + + expect { count.call }.to transition { counter.count }.through [0, 1, 4, 2] + end end end end