transition_through 1.0.0.pre.beta.1 → 1.0.0.pre.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 245765e994574db116dd542c12e40bd84fe6487f130f647761fc542a19745b45
4
- data.tar.gz: fd51b8b84f3c552abb310b6e8912c657449474b80e481f05d4f08b5eb8bca266
3
+ metadata.gz: 450fffb697c0dde12e5cb3bd846514b9596665442ef8e3dd49561949cf8362dc
4
+ data.tar.gz: dac34fae2af7fc17a55f5ff76c0547e1d74fff70215273584ba9d06ed6aa8157
5
5
  SHA512:
6
- metadata.gz: 9b671d76bcece48f74db7248870a0182b841dc52484007802128d727a5ea2d5d075f66b202953450c19207527d99a88d70d0ebf481d0e999c99d049e0d8f3007
7
- data.tar.gz: ca866a6ef2d58f7ca14c9b4a46218e445dd205c3df0f42f7170044127fb8de43cf4818edf1bb1bd68b1fb57dbcd4f72699c7ce4c52a7eb1fb0ca242114ffda77
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
- expect { counter.increment(3) }.to transition { counter.count }.through 0..3
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TransitionThrough
4
- VERSION = '1.0.0-beta.1'
4
+ VERSION = '1.0.0-rc.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transition_through
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta.1
4
+ version: 1.0.0.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeke Gabrielse