aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-11-16 16:03:06 +0100
committerRobert2017-11-16 16:03:06 +0100
commit3b855c870e39f4a607ff3b473abfa169e231648d (patch)
tree6aa8eb32d86edfb8109866df9bf8cc40af9f3d22
parent30c362f0371c081e0ddb9bc13c5873b1aecda1eb (diff)
downloadchouette-core-robert-bup.tar.bz2
Refs: #4461@1h; CodeReviewrobert-bup
- using webmock instead of mocking Net::HTTP therefore removing the connascence between the spec and the HTTP lib used in the implementation, thank you Teddy
-rw-r--r--spec/models/import/netex_import_spec.rb24
-rw-r--r--spec/support/webmock/helpers.rb5
2 files changed, 18 insertions, 11 deletions
diff --git a/spec/models/import/netex_import_spec.rb b/spec/models/import/netex_import_spec.rb
index b23abf776..4548bd7cc 100644
--- a/spec/models/import/netex_import_spec.rb
+++ b/spec/models/import/netex_import_spec.rb
@@ -1,18 +1,19 @@
RSpec.describe NetexImport, type: :model do
- let( :invoked_calls ){ [] }
+ let( :boiv_iev_uri ){ URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{subject.id}")}
- let( :http_service ){ double 'Net::HTTP' }
before do
- stub_const 'Net::HTTP', http_service
- allow(http_service).to receive( :get ){ invoked_calls << :called }
+ allow(Thread).to receive(:new).and_yield
end
context 'with referential' do
- subject { build :netex_import }
+ subject{ build( :netex_import, id: random_int ) }
+
it 'will trigger the Java API' do
- subject.save
- expect( invoked_calls ).to eq([:called])
+ with_stubbed_request(:get, boiv_iev_uri) do |request|
+ subject.save!
+ expect(request).to have_been_requested
+ end
end
end
@@ -20,11 +21,12 @@ RSpec.describe NetexImport, type: :model do
subject { build :netex_import, referential_id: nil }
it 'its status is forced to aborted and the Java API is not callled' do
- subject.save!
- expect( subject.reload.status ).to eq('aborted')
- expect( invoked_calls ).to be_empty
+ with_stubbed_request(:get, boiv_iev_uri) do |request|
+ subject.save!
+ expect(subject.reload.status).to eq('aborted')
+ expect(request).not_to have_been_requested
+ end
end
-
end
end
diff --git a/spec/support/webmock/helpers.rb b/spec/support/webmock/helpers.rb
index fc6c77850..a6506c035 100644
--- a/spec/support/webmock/helpers.rb
+++ b/spec/support/webmock/helpers.rb
@@ -8,6 +8,11 @@ module Support
def make_headers(headers={}, authorization_token:)
headers.merge('Authorization' => "Token token=#{authorization_token.inspect}")
end
+
+ def with_stubbed_request( method, uri, &blk )
+ stub_request(method, uri).tap(&blk)
+ end
+
end
end
end