Module StateMachine::Assertions
In: lib/state_machine/assertions.rb

Provides a set of helper methods for making assertions about the content of various objects

Methods

Public Instance methods

Validates that the given hash only includes at most one of a set of exclusive keys. If more than one key is found, an ArgumentError will be raised.

Examples

  options = {:only => :on, :except => :off}
  assert_exclusive_keys(options, :only)                   # => nil
  assert_exclusive_keys(options, :except)                 # => nil
  assert_exclusive_keys(options, :only, :except)          # => ArgumentError: Conflicting keys: only, except
  assert_exclusive_keys(options, :only, :except, :with)   # => ArgumentError: Conflicting keys: only, except

Validates that the given hash only includes the specified valid keys. If any invalid keys are found, an ArgumentError will be raised.

Examples

  options = {:name => 'John Smith', :age => 30}

  assert_valid_keys(options, :name)           # => ArgumentError: Invalid key(s): age
  assert_valid_keys(options, 'name', 'age')   # => ArgumentError: Invalid key(s): age, name
  assert_valid_keys(options, :name, :age)     # => nil

[Validate]