Sha256: eaaecd9248cfcff0c42c89148e2fa2aa642728e6232b327d93d113a35c3396be
Contents?: true
Size: 1.28 KB
Versions: 6
Compression:
Stored size: 1.28 KB
Contents
require 'matchers/states/matcher' module StateMachinesRspec module Matchers def have_states(state, *states) HaveStateMatcher.new(states.unshift(state)) end alias_method :have_state, :have_states class HaveStateMatcher < StateMachinesRspec::Matchers::States::Matcher def matches_states?(states) return false if undefined_states? return false if incorrect_value? @failure_message.nil? end def description message = super message << " == #{state_value.inspect}" if state_value message << " on #{state_machine_scope.inspect}" if state_machine_scope "have #{message}" end private def undefined_states? undefined_states = @introspector.undefined_states(@states) unless undefined_states.empty? @failure_message = "Expected #{@introspector.state_machine_attribute} " + "to allow states: #{undefined_states.join(', ')}" end !undefined_states.empty? end def incorrect_value? if state_value && @introspector.state(@states.first).value != state_value @failure_message = "Expected #{@states.first} to have value #{state_value}" true end false end end end end
Version data entries
6 entries across 6 versions & 2 rubygems