transition_through 1.0.0.pre.beta.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 245765e994574db116dd542c12e40bd84fe6487f130f647761fc542a19745b45
4
- data.tar.gz: fd51b8b84f3c552abb310b6e8912c657449474b80e481f05d4f08b5eb8bca266
3
+ metadata.gz: 0d41241876048696d75e8385c63202cb72388eff35471a01a4e5501254f97b3d
4
+ data.tar.gz: 9c5dcb7d15d133d6f128d037bf2769ecf66d0fea596832fc72f5813cccc0157c
5
5
  SHA512:
6
- metadata.gz: 9b671d76bcece48f74db7248870a0182b841dc52484007802128d727a5ea2d5d075f66b202953450c19207527d99a88d70d0ebf481d0e999c99d049e0d8f3007
7
- data.tar.gz: ca866a6ef2d58f7ca14c9b4a46218e445dd205c3df0f42f7170044127fb8de43cf4818edf1bb1bd68b1fb57dbcd4f72699c7ce4c52a7eb1fb0ca242114ffda77
6
+ metadata.gz: 5bf54daf3b5d0e04e7f9653cfd3d7dbf3ef3e582ffed4e6a6f01bc982214090ddccf953a4da9187a1683d7fac404ad848a1c3f1b347b27062587c0d08970e5cc
7
+ data.tar.gz: de27354247781e9728b735cf5864c42e775c7496bcccf392b0c65daca1710a6f84fe4b78e3307697a73d6d59eea70c74cc3114233d95406fe5f17dd57408b10b
data/README.md CHANGED
@@ -40,10 +40,34 @@ $ 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]
53
+ end
54
+
55
+ it 'should transition nowhere' do
56
+ counter = Counter.new
57
+ count = -> {}
58
+
59
+ expect { count.call }.to transition { counter.count }.nowhere
44
60
  end
45
61
  ```
46
62
 
63
+ ## Note on instance variables
64
+
65
+ Currently, mutating state through an instance variable is not supported. This
66
+ due to the fact that instance variables cannot be observed for changes like an
67
+ accessor can. For more information, see [the tests](https://github.com/keygen-sh/transition_through/blob/d2c6b685e4959d08e70bb5012af98fa01fcdebef/spec/transition_through_spec.rb#L8-L21).
68
+
69
+ If you know of a way to support ivars, please open an issue or PR.
70
+
47
71
  ## Supported Rubies
48
72
 
49
73
  **`transition_through` supports Ruby 3.1 and above.** We encourage you to upgrade
@@ -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'
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
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeke Gabrielse
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Assert state changes through multiple values for an object, enabling
84
- you to test complex state transitions in sequence.
84
+ you to test complex state transitions in sequence with RSpec.
85
85
  email:
86
86
  - oss@keygen.sh
87
87
  executables: []
@@ -113,9 +113,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  version: '3.1'
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ">"
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
- version: 1.3.1
118
+ version: '0'
119
119
  requirements: []
120
120
  rubygems_version: 3.4.13
121
121
  signing_key: