diff options
| author | Teddy Wing | 2017-10-30 17:45:08 +0100 |
|---|---|---|
| committer | Teddy Wing | 2017-10-30 17:48:58 +0100 |
| commit | 1299a941e45be30d75709db096a7bc233b64eb95 (patch) | |
| tree | 45d7e0a02a0fd7c6034c9987089d27c2239990f9 | |
| parent | f7d48398f5cb2ad714691bd630619b02c8958ac5 (diff) | |
| download | chouette-core-1299a941e45be30d75709db096a7bc233b64eb95.tar.bz2 | |
ComplianceControlSetCopyWorker spec: Always stub API call
In the first test, we weren't stubbing the Java API call, so it would
get executed for real. Put the HTTP stub in a `before(:each)` call so
that it gets stubbed for every test here.
Additionally, reorganise the tests a bit to clean them up. Move the HTTP
stub to a `let` to allow it to be called in a couple different places.
Since the HTTP stub depends on the `check_set` double, move that to a
`let` too. And have the `ComplianceControlSetCopier` mock always return
`check_set`, now that the app code depends on that return value.
Refs #4782
| -rw-r--r-- | spec/workers/compliance_control_set_copy_worker_spec.rb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/spec/workers/compliance_control_set_copy_worker_spec.rb b/spec/workers/compliance_control_set_copy_worker_spec.rb index 72a030292..0ff721e75 100644 --- a/spec/workers/compliance_control_set_copy_worker_spec.rb +++ b/spec/workers/compliance_control_set_copy_worker_spec.rb @@ -1,28 +1,35 @@ RSpec.describe ComplianceControlSetCopyWorker do let(:control_set_id) { 55 } let(:referential_id) { 99 } + let(:check_set) { double(ComplianceCheckSet, id: 888) } + let(:stub_validation_request) do + stub_request( + :get, + "#{Rails.configuration.iev_url}/boiv_iev/referentials/validator/new?id=#{check_set.id}" + ) + end before(:each) do - allow_any_instance_of(ComplianceControlSetCopier).to receive(:copy) + allow_any_instance_of( + ComplianceControlSetCopier + ).to receive(:copy).and_return(check_set) + + stub_validation_request end it "calls ComplianceControlSetCopier" do expect_any_instance_of( ComplianceControlSetCopier - ).to receive(:copy).with(control_set_id, referential_id) + ).to receive(:copy) + .with(control_set_id, referential_id) + .and_return(check_set) ComplianceControlSetCopyWorker.new.perform(control_set_id, referential_id) end it "calls the Java API to launch validation" do - validation_request = stub_request( - :get, - "#{Rails.configuration.iev_url}/boiv_iev/referentials/validator/new?id=#{control_set_id}" - ) - allow_any_instance_of(ComplianceControlSetCopier).to receive(:copy).and_return(check_set) - ComplianceControlSetCopyWorker.new.perform(control_set_id, referential_id) - expect(validation_request).to have_been_requested + expect(stub_validation_request).to have_been_requested end end |
