File tree 2 files changed +64
-2
lines changed
spec/lib/interactify/rspec
2 files changed +64
-2
lines changed Original file line number Diff line number Diff line change 6
6
7
7
RSpec ::Matchers . define :expect_inputs do |*expected_inputs |
8
8
match do |actual |
9
- actual_inputs = actual . expected_keys
9
+ next false unless actual . respond_to? ( :expected_keys )
10
+
11
+ actual_inputs = Array ( actual . expected_keys )
10
12
@missing_inputs = expected_inputs - actual_inputs
11
13
@extra_inputs = actual_inputs - expected_inputs
12
14
25
27
# e.g. expect(described_class).to promise_outputs(:request_logger)
26
28
RSpec ::Matchers . define :promise_outputs do |*expected_outputs |
27
29
match do |actual |
28
- actual_outputs = actual . promised_keys
30
+ next false unless actual . respond_to? ( :promised_keys )
31
+
32
+ actual_outputs = Array ( actual . promised_keys )
29
33
@missing_outputs = expected_outputs - actual_outputs
30
34
@extra_outputs = actual_outputs - expected_outputs
31
35
Original file line number Diff line number Diff line change
1
+ require 'interactify/rspec/matchers'
2
+
3
+ RSpec . describe 'rspec matchers' do
4
+ describe 'expect_inputs' do
5
+ it 'passes when the inputs are correct' do
6
+ expect ( k ( :A ) ) . to expect_inputs ( :a )
7
+ expect ( k ( :A ) ) . not_to expect_inputs ( :b )
8
+
9
+ expect ( k ( :B ) ) . to expect_inputs ( :b )
10
+ expect ( k ( :B ) ) . not_to expect_inputs ( :a )
11
+
12
+ expect ( k ( :P ) ) . not_to expect_inputs ( :a , :b )
13
+ end
14
+
15
+ it 'works with vanilla interactors without blowing up' do
16
+ expect ( k ( :Vanilla ) ) . not_to expect_inputs ( :a )
17
+ end
18
+ end
19
+
20
+ describe 'promise_outputs' do
21
+ it 'passes when the outputs are correct' do
22
+ expect ( k ( :A ) ) . not_to promise_outputs ( :a )
23
+ expect ( k ( :A ) ) . not_to promise_outputs ( :a )
24
+
25
+ expect ( k ( :P ) ) . to promise_outputs ( :a , :b , :c )
26
+ end
27
+
28
+ it 'works with vanilla interactors without blowing up' do
29
+ expect ( k ( :Vanilla ) ) . not_to promise_outputs ( :a )
30
+ end
31
+ end
32
+
33
+
34
+ module self ::SomeNamespace
35
+ Vanilla = Class . new do
36
+ include Interactor
37
+ end
38
+
39
+ A = Class . new do
40
+ include Interactify
41
+ expect :a
42
+ end
43
+
44
+ B = Class . new do
45
+ include Interactify
46
+ expect :b
47
+ end
48
+
49
+ P = Class . new do
50
+ include Interactify
51
+ promise :a , :b , :c
52
+ end
53
+ end
54
+
55
+ def k ( klass )
56
+ self . class ::SomeNamespace . const_get ( klass )
57
+ end
58
+ end
You can’t perform that action at this time.
0 commit comments