Skip to content

Assert state changes in sequence. Like change{}, but for asserting multiple changes in RSpec.

License

Notifications You must be signed in to change notification settings

keygen-sh/transition_through

Repository files navigation

transition_through

CI Gem Version

Assert state changes in sequence. Like change { ... }, but for asserting multiple changes in RSpec.

Sponsored by:

Keygen

A fair source software licensing and distribution API.

Installation

Add this line to your application's Gemfile:

gem 'transition_through'

And then execute:

$ bundle

Or install it yourself as:

$ gem install transition_through

Usage

it 'should transition through' do
  counter = Counter.new
  count   = -> {
    counter.count = 0
    counter.increment
    counter.count  = counter.count + 3
    counter.count -= 2
    counter.decrement(by: 2)
  }

  expect { count.call }.to transition { counter.count }.through [0, 1, 4, 2, 0]
end

it 'should transition nowhere' do
  counter = Counter.new
  count   = -> {}

  expect { count.call }.to transition { counter.count }.nowhere
end

Note on instance variables

Currently, mutating state through an instance variable is not supported. This is due to the fact that instance variables cannot be observed for changes like an accessor can. For more information, see the tests.

If you know of a way to support ivars, please open an issue or PR.

Supported Rubies

transition_through supports Ruby 3.1 and above. We encourage you to upgrade if you're on an older version. Ruby 3 provides a lot of great features, like better pattern matching and a new shorthand hash syntax.

Is it any good?

Yes.

Contributing

If you have an idea, or have discovered a bug, please open an issue or create a pull request.

License

The gem is available as open source under the terms of the MIT License.

About

Assert state changes in sequence. Like change{}, but for asserting multiple changes in RSpec.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published