Skip to content

Add macro with_state_machine #1

@modocache

Description

@modocache

The current API isn't very nice because it requires you to write when: :some_state for each assertion, which becomes tedious quickly.

describe Vehicle
  #3. macros raise exception if specified state_machine is not defined on class
  with_state_machine do # 2. uses default state_machine if no arg is passed
    it { should have_state :parked }
  end

  with_state_machine :alarm_state do # 1. macro sets subject for nested `it` blocks
    it { should have_states :active, :off }
  end
end
  • with_state_machine sets the subject to the state_machine defined on a particular attribute. "subject" could either mean the actual subject is shifted to the state_machine instance (or some sort of facade), or perhaps the other matchers such as have_states are aware of the "subject" in some way.
  • with_state_machine uses the default state_machine if no argument is passed
  • with_state_machine raises an exception if the specified state_machine doesn't exist, or no state_machine exists on the class in the first place

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions