state_machine_rspec 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/lib/matchers/events/handle_event.rb +6 -0
- data/lib/matchers/events/matcher.rb +17 -1
- data/lib/matchers/events/reject_event.rb +6 -0
- data/lib/matchers/states/have_state.rb +7 -1
- data/lib/matchers/states/matcher.rb +16 -2
- data/lib/matchers/states/reject_state.rb +6 -0
- data/lib/state_machine_rspec/state_machine_introspector.rb +2 -2
- data/lib/state_machine_rspec/version.rb +1 -1
- data/spec/matchers/events/handle_event_spec.rb +26 -0
- data/spec/matchers/events/reject_event_spec.rb +26 -0
- data/spec/matchers/states/have_state_spec.rb +26 -0
- data/spec/matchers/states/reject_state_spec.rb +18 -0
- data/state_machine_rspec.gemspec +1 -1
- metadata +5 -5
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## [0.1.3](https://github.com/modocache/state_machine_rspec/compare/v0.1.2...v0.1.3)
|
2
|
+
|
3
|
+
- Add `#description` to matchers.
|
4
|
+
- Update rspec dependency.
|
5
|
+
|
1
6
|
## [0.1.2](https://github.com/modocache/state_machine_rspec/compare/v0.1.1...v0.1.2)
|
2
7
|
|
3
8
|
- state_machine dependency updated from "~> 1.1.0" to ">= 1.1.0".
|
@@ -26,10 +26,22 @@ module StateMachineRspec
|
|
26
26
|
"subclasses of #{self.class} must override matches_events?"
|
27
27
|
end
|
28
28
|
|
29
|
+
def description
|
30
|
+
message = @events.map{ |event| event.inspect }.join(', ')
|
31
|
+
message << " when #{state_name.inspect}" if state_name
|
32
|
+
message
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def state_machine_scope
|
38
|
+
@options.fetch(:on, nil)
|
39
|
+
end
|
40
|
+
|
29
41
|
private
|
30
42
|
|
31
43
|
def enter_when_state
|
32
|
-
if state_name
|
44
|
+
if state_name
|
33
45
|
unless when_state = @introspector.state(state_name)
|
34
46
|
raise StateMachineIntrospectorError,
|
35
47
|
"#{@subject.class} does not define state: #{state_name}"
|
@@ -40,6 +52,10 @@ module StateMachineRspec
|
|
40
52
|
end
|
41
53
|
end
|
42
54
|
|
55
|
+
def state_name
|
56
|
+
@options.fetch(:when, nil)
|
57
|
+
end
|
58
|
+
|
43
59
|
def undefined_events?
|
44
60
|
undefined_events = @introspector.undefined_events(@events)
|
45
61
|
unless undefined_events.empty?
|
@@ -14,6 +14,13 @@ module StateMachineRspec
|
|
14
14
|
@failure_message.nil?
|
15
15
|
end
|
16
16
|
|
17
|
+
def description
|
18
|
+
message = super
|
19
|
+
message << " == #{state_value.inspect}" if state_value
|
20
|
+
message << " on #{state_machine_scope.inspect}" if state_machine_scope
|
21
|
+
"have #{message}"
|
22
|
+
end
|
23
|
+
|
17
24
|
private
|
18
25
|
|
19
26
|
def undefined_states?
|
@@ -27,7 +34,6 @@ module StateMachineRspec
|
|
27
34
|
end
|
28
35
|
|
29
36
|
def incorrect_value?
|
30
|
-
state_value = @options.fetch(:value, nil)
|
31
37
|
if state_value && @introspector.state(@states.first).value != state_value
|
32
38
|
@failure_message = "Expected #{@states.first} to have value #{state_value}"
|
33
39
|
true
|
@@ -11,12 +11,16 @@ module StateMachineRspec
|
|
11
11
|
@states = states
|
12
12
|
end
|
13
13
|
|
14
|
+
def description
|
15
|
+
@states.map{ |event| event.inspect }.join(', ')
|
16
|
+
end
|
17
|
+
|
14
18
|
def matches?(subject)
|
15
19
|
raise_if_multiple_values
|
16
20
|
|
17
21
|
@subject = subject
|
18
22
|
@introspector = StateMachineIntrospector.new(@subject,
|
19
|
-
|
23
|
+
state_machine_scope)
|
20
24
|
|
21
25
|
return false unless matches_states?(@states)
|
22
26
|
@failure_message.nil?
|
@@ -27,10 +31,20 @@ module StateMachineRspec
|
|
27
31
|
"subclasses of #{self.class} must override matches_states?"
|
28
32
|
end
|
29
33
|
|
34
|
+
protected
|
35
|
+
|
36
|
+
def state_machine_scope
|
37
|
+
@options.fetch(:on, nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
def state_value
|
41
|
+
@options.fetch(:value, nil)
|
42
|
+
end
|
43
|
+
|
30
44
|
private
|
31
45
|
|
32
46
|
def raise_if_multiple_values
|
33
|
-
if @states.count > 1 &&
|
47
|
+
if @states.count > 1 && state_value
|
34
48
|
raise ArgumentError, 'cannot make value assertions on ' +
|
35
49
|
'multiple states at once'
|
36
50
|
end
|
@@ -21,7 +21,7 @@ class StateMachineIntrospector
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def defined_states(states)
|
24
|
-
states.
|
24
|
+
states.select { |s| state_defined? s }
|
25
25
|
end
|
26
26
|
|
27
27
|
def undefined_events(events)
|
@@ -29,7 +29,7 @@ class StateMachineIntrospector
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def valid_events(events)
|
32
|
-
events.
|
32
|
+
events.select { |e| valid_event? e }
|
33
33
|
end
|
34
34
|
|
35
35
|
def invalid_events(events)
|
@@ -106,4 +106,30 @@ describe StateMachineRspec::Matchers::HandleEventMatcher do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
|
+
|
110
|
+
describe '#description' do
|
111
|
+
context 'with no options' do
|
112
|
+
let(:matcher) { described_class.new([:placate, :mollify]) }
|
113
|
+
|
114
|
+
it 'returns a string description' do
|
115
|
+
matcher.description.should == 'handle :placate, :mollify'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when :when state is specified' do
|
120
|
+
let(:matcher) { described_class.new([:destroy_food, when: :hangry]) }
|
121
|
+
|
122
|
+
it 'mentions the requisite state' do
|
123
|
+
matcher.description.should == 'handle :destroy_food when :hangry'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when :on is specified' do
|
128
|
+
let(:matcher) { described_class.new([:ensmarmify, on: :tired_investors]) }
|
129
|
+
|
130
|
+
it 'mentions the state machine variable' do
|
131
|
+
matcher.description.should == 'handle :ensmarmify on :tired_investors'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
109
135
|
end
|
@@ -106,4 +106,30 @@ describe StateMachineRspec::Matchers::RejectEventMatcher do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
|
+
|
110
|
+
describe '#description' do
|
111
|
+
context 'with no options' do
|
112
|
+
let(:matcher) { described_class.new([:makeadealify, :hustlinate]) }
|
113
|
+
|
114
|
+
it 'returns a string description' do
|
115
|
+
matcher.description.should == 'reject :makeadealify, :hustlinate'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when :when state is specified' do
|
120
|
+
let(:matcher) { described_class.new([:begargle, when: :sleep_encrusted]) }
|
121
|
+
|
122
|
+
it 'mentions the requisite state' do
|
123
|
+
matcher.description.should == 'reject :begargle when :sleep_encrusted'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when :on is specified' do
|
128
|
+
let(:matcher) { described_class.new([:harrangue, on: :suspicious_crowd]) }
|
129
|
+
|
130
|
+
it 'mentions the state machine variable' do
|
131
|
+
matcher.description.should == 'reject :harrangue on :suspicious_crowd'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
109
135
|
end
|
@@ -107,4 +107,30 @@ describe StateMachineRspec::Matchers::HaveStateMatcher do
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
110
|
+
|
111
|
+
describe '#description' do
|
112
|
+
context 'with no options' do
|
113
|
+
let(:matcher) { described_class.new([:fancy_shirt, :cracked_toenail]) }
|
114
|
+
|
115
|
+
it 'returns a string description' do
|
116
|
+
matcher.description.should == 'have :fancy_shirt, :cracked_toenail'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when :value is specified' do
|
121
|
+
let(:matcher) { described_class.new([:mustache, value: :really_shady]) }
|
122
|
+
|
123
|
+
it 'mentions the requisite state' do
|
124
|
+
matcher.description.should == 'have :mustache == :really_shady'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when :on state machine is specified' do
|
129
|
+
let(:matcher) { described_class.new([:lunch, on: :tuesday]) }
|
130
|
+
|
131
|
+
it 'mentions the state machine variable' do
|
132
|
+
matcher.description.should == 'have :lunch on :tuesday'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
110
136
|
end
|
@@ -78,4 +78,22 @@ describe StateMachineRspec::Matchers::RejectStateMatcher do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
|
+
|
82
|
+
describe '#description' do
|
83
|
+
context 'with no options' do
|
84
|
+
let(:matcher) { described_class.new([:mustard, :tomatoes]) }
|
85
|
+
|
86
|
+
it 'returns a string description' do
|
87
|
+
matcher.description.should == 'not have :mustard, :tomatoes'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'when :on state machine is specified' do
|
92
|
+
let(:matcher) { described_class.new([:peanut_butter, on: :toast]) }
|
93
|
+
|
94
|
+
it 'mentions the state machine variable' do
|
95
|
+
matcher.description.should == 'not have :peanut_butter on :toast'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
81
99
|
end
|
data/state_machine_rspec.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'rb-fsevent'
|
26
26
|
spec.add_development_dependency 'terminal-notifier-guard'
|
27
27
|
|
28
|
-
spec.add_dependency 'rspec', '~> 2.
|
28
|
+
spec.add_dependency 'rspec', '~> 2.14'
|
29
29
|
spec.add_dependency 'state_machine', '>= 1.1.0'
|
30
30
|
spec.add_dependency 'activesupport'
|
31
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: state_machine_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -114,7 +114,7 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '2.
|
117
|
+
version: '2.14'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
requirements:
|
123
123
|
- - ~>
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '2.
|
125
|
+
version: '2.14'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: state_machine
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
209
|
version: '0'
|
210
210
|
requirements: []
|
211
211
|
rubyforge_project:
|
212
|
-
rubygems_version: 1.8.
|
212
|
+
rubygems_version: 1.8.25
|
213
213
|
signing_key:
|
214
214
|
specification_version: 3
|
215
215
|
summary: RSpec matchers for state_machine.
|