Skip to content

Commit

Permalink
add nowhere matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Aug 14, 2024
1 parent c4ad30b commit c5f6e8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/transition_through/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@ def matches?(expect_block)
@actual_states == @expected_states
end

# assert state changes across array or range of values
def through(*values)
@expected_states = values.flatten(1)

self
self # allow chaining
end

# noop because no change is default assertion
def nowhere = self

def failure_message
"expected block to transition through #{@expected_states.inspect} but it transitioned through #{@actual_states.inspect}"
end
Expand Down
8 changes: 8 additions & 0 deletions spec/transition_through_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ def decrement(n = 1, by: 1) = n.times { self.count += by }
expect { counter.increment(3) }.to transition { counter.count }.through 0..3
end

it 'should support nothing' do
expect { }.to transition { counter.count }
end

it 'should support nowhere' do
expect { }.to transition { counter.count }.nowhere
end

it 'should track transitions' do
expect {
counter.count = 0
Expand Down

0 comments on commit c5f6e8e

Please sign in to comment.