transition_through 1.0.0.pre.beta.1 → 1.0.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/transition_through/matcher.rb +10 -4
- data/lib/transition_through/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 450fffb697c0dde12e5cb3bd846514b9596665442ef8e3dd49561949cf8362dc
|
4
|
+
data.tar.gz: dac34fae2af7fc17a55f5ff76c0547e1d74fff70215273584ba9d06ed6aa8157
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bb05c7e740418950526aa9bc825a9d45da390175df7788a3f2ec6ed0a6a43f5268251151eca92098a610941fbdccbb9509fdf25346aa7006e5e07c472d3328c
|
7
|
+
data.tar.gz: f13f636bb6988f1bffb3fb2174d686b3cbbcd692720eeded7b8749618166d28a35dc4d637637a0e2281d79da42a9f5e6f4de4ea8f889e24eda41216e95d2b80a
|
data/README.md
CHANGED
@@ -40,7 +40,16 @@ $ gem install transition_through
|
|
40
40
|
|
41
41
|
```ruby
|
42
42
|
it 'should transition through' do
|
43
|
-
|
43
|
+
counter = Counter.new
|
44
|
+
count = -> {
|
45
|
+
counter.count = 0
|
46
|
+
counter.increment
|
47
|
+
counter.count = counter.count + 3
|
48
|
+
counter.count -= 2
|
49
|
+
counter.decrement(by: 2)
|
50
|
+
}
|
51
|
+
|
52
|
+
expect { count.call }.to transition { counter.count }.through [0, 1, 4, 2, 0]
|
44
53
|
end
|
45
54
|
```
|
46
55
|
|
@@ -19,6 +19,8 @@ module TransitionThrough
|
|
19
19
|
|
20
20
|
def supports_block_expectations? = true
|
21
21
|
def matches?(expect_block)
|
22
|
+
raise InvalidExpressionError, 'transition block is required' if state_block.nil?
|
23
|
+
|
22
24
|
path, start_line = state_block.source_location
|
23
25
|
|
24
26
|
# walk the ast until we find our transition expression
|
@@ -27,14 +29,14 @@ module TransitionThrough
|
|
27
29
|
|
28
30
|
ast.value.accept(exp)
|
29
31
|
|
30
|
-
# raise if the expression is empty
|
31
|
-
raise InvalidExpressionError if
|
32
|
+
# raise if the expression is too complex or empty
|
33
|
+
raise InvalidExpressionError, 'complex or empty transition expressions are not supported' if
|
32
34
|
exp.result.nil? || exp.result.receiver.nil? || exp.result.method_name.nil?
|
33
35
|
|
34
36
|
# get the actual transitioning object from the state block's binding
|
35
37
|
receiver = state_block.binding.eval(exp.result.receiver.name.to_s)
|
36
38
|
|
37
|
-
raise InvalidExpressionError unless
|
39
|
+
raise InvalidExpressionError, "expected accessor #{receiver.class}##{exp.result.method_name} but it's missing" unless
|
38
40
|
receiver.respond_to?(:"#{exp.result.method_name}=") &&
|
39
41
|
receiver.respond_to?(exp.result.method_name)
|
40
42
|
|
@@ -59,12 +61,16 @@ module TransitionThrough
|
|
59
61
|
@actual_states == @expected_states
|
60
62
|
end
|
61
63
|
|
64
|
+
# assert state changes across array or range of values
|
62
65
|
def through(*values)
|
63
66
|
@expected_states = values.flatten(1)
|
64
67
|
|
65
|
-
self
|
68
|
+
self # allow chaining
|
66
69
|
end
|
67
70
|
|
71
|
+
# noop because no change is default assertion
|
72
|
+
def nowhere = self
|
73
|
+
|
68
74
|
def failure_message
|
69
75
|
"expected block to transition through #{@expected_states.inspect} but it transitioned through #{@actual_states.inspect}"
|
70
76
|
end
|