|
105 | 105 | end |
106 | 106 | end |
107 | 107 | end |
| 108 | + |
| 109 | + context 'when called with a key and :for' do |
| 110 | + subject(:result) { patcher.do_once(key, for: for_key) { integration.patch } } |
| 111 | + |
| 112 | + let(:key) { double('key') } |
| 113 | + let(:for_key) { double('for key') } |
| 114 | + |
| 115 | + it do |
| 116 | + expect(integration).to receive(:patch).once.and_return(patch_result) |
| 117 | + expect(result).to be(patch_result) |
| 118 | + end |
| 119 | + |
| 120 | + context 'then called a second time' do |
| 121 | + context 'with a matching key and :for' do |
| 122 | + context 'that is the same' do |
| 123 | + subject(:result) do |
| 124 | + patcher.do_once(key, for: for_key) { integration.patch } |
| 125 | + patcher.do_once(key, for: for_key) { integration.patch } |
| 126 | + end |
| 127 | + |
| 128 | + it do |
| 129 | + expect(integration).to receive(:patch).once.and_return(patch_result) |
| 130 | + expect(result).to be true # Because second block doesn't run |
| 131 | + end |
| 132 | + end |
| 133 | + |
| 134 | + context 'that is different' do |
| 135 | + subject(:result) do |
| 136 | + patcher.do_once(key, for: for_key) { integration.patch } |
| 137 | + patcher.do_once(key, for: for_key_two) { integration.patch } |
| 138 | + end |
| 139 | + |
| 140 | + let(:for_key_two) { double('for key two') } |
| 141 | + |
| 142 | + it do |
| 143 | + expect(integration).to receive(:patch).twice.and_return(patch_result) |
| 144 | + expect(result).to be(patch_result) |
| 145 | + end |
| 146 | + end |
| 147 | + end |
| 148 | + end |
| 149 | + end |
108 | 150 | end |
109 | 151 |
|
110 | 152 | describe '#done?' do |
111 | 153 | context 'when called before do_once' do |
112 | | - subject(:done) { patcher.done?(key) } |
113 | 154 | let(:key) { double('key') } |
114 | | - it { is_expected.to be false } |
| 155 | + |
| 156 | + context 'with a key' do |
| 157 | + subject(:done) { patcher.done?(key) } |
| 158 | + it { is_expected.to be false } |
| 159 | + end |
| 160 | + |
| 161 | + context 'with a key and :for' do |
| 162 | + subject(:done) { patcher.done?(key, for: for_key) } |
| 163 | + let(:for_key) { double('for key') } |
| 164 | + it { is_expected.to be false } |
| 165 | + end |
115 | 166 | end |
116 | 167 |
|
117 | 168 | context 'when called after do_once' do |
118 | | - subject(:done) { patcher.done?(key) } |
119 | 169 | let(:key) { double('key') } |
120 | | - before(:each) { patcher.do_once(key) { 'Perform patch' } } |
121 | | - it { is_expected.to be true } |
| 170 | + |
| 171 | + context 'with a key' do |
| 172 | + subject(:done) { patcher.done?(key) } |
| 173 | + before(:each) { patcher.do_once(key) { 'Perform patch' } } |
| 174 | + it { is_expected.to be true } |
| 175 | + end |
| 176 | + |
| 177 | + context 'with a key and :for' do |
| 178 | + subject(:done) { patcher.done?(key, for: for_key) } |
| 179 | + let(:for_key) { double('key') } |
| 180 | + before(:each) { patcher.do_once(key, for: for_key) { 'Perform patch' } } |
| 181 | + it { is_expected.to be true } |
| 182 | + end |
122 | 183 | end |
123 | 184 | end |
124 | 185 | end |
|
0 commit comments