File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1414
1515RSpec ::Matchers . define :match_type do |attribute , type |
1616 match do |actual |
17- actual . is_a? ( type )
17+ if type . is_a? ( Array )
18+ type . any? { |t | actual . is_a? ( t ) }
19+ else
20+ actual . is_a? ( type )
21+ end
1822 end
1923
2024 failure_message do |actual |
Original file line number Diff line number Diff line change 6464 end
6565 end
6666
67+ context 'when a condition that matches multiple types' do
68+ it 'passes assertion if one of the types passes' do
69+ json [ 'data' ] [ 'attributes' ] [ 'is_foo' ] = false
70+ allow ( post_record ) . to receive ( :is_foo ) { false }
71+ expect {
72+ assert_payload ( :post , post_record , json_item ) do
73+ key ( :is_foo , [ TrueClass , FalseClass ] )
74+ end
75+ } . to_not raise_error
76+
77+ json [ 'data' ] [ 'attributes' ] [ 'is_foo' ] = true
78+ allow ( post_record ) . to receive ( :is_foo ) { true }
79+ expect {
80+ assert_payload ( :post , post_record , json_item ) do
81+ key ( :is_foo , [ TrueClass , FalseClass ] )
82+ end
83+ } . to_not raise_error
84+
85+ json [ 'data' ] [ 'attributes' ] [ 'is_foo' ] = 'true'
86+ allow ( post_record ) . to receive ( :is_foo ) { 'true' }
87+ expect {
88+ assert_payload ( :post , post_record , json_item ) do
89+ key ( :is_foo , [ TrueClass , FalseClass ] )
90+ end
91+ } . to raise_error ( RSpec ::Expectations ::ExpectationNotMetError )
92+ end
93+ end
94+
6795 context 'when json value does not match payload value' do
6896 before do
6997 allow ( post_record ) . to receive ( :title ) { 'foo' }
You can’t perform that action at this time.
0 commit comments