defra_ruby_address 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +66 -6
  3. data/Rakefile +2 -2
  4. data/bin/console +2 -6
  5. data/lib/defra_ruby/address/response.rb +1 -2
  6. data/lib/defra_ruby/address/services/os_api_address_lookup_v1_service.rb +100 -0
  7. data/lib/defra_ruby/address/services/os_places_address_lookup_service.rb +11 -14
  8. data/lib/defra_ruby/address/version.rb +1 -1
  9. data/lib/defra_ruby/address.rb +1 -0
  10. metadata +6 -180
  11. data/spec/defra_ruby/address/configuration_spec.rb +0 -18
  12. data/spec/defra_ruby/address/response_spec.rb +0 -70
  13. data/spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb +0 -73
  14. data/spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb +0 -73
  15. data/spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb +0 -72
  16. data/spec/defra_ruby/address_spec.rb +0 -30
  17. data/spec/examples.txt +0 -27
  18. data/spec/fixtures/ea_address_facade_v1_1_blank.json +0 -8
  19. data/spec/fixtures/ea_address_facade_v1_1_not_found.json +0 -14
  20. data/spec/fixtures/ea_address_facade_v1_1_valid.json +0 -83
  21. data/spec/fixtures/ea_address_facade_v1_blank.json +0 -13
  22. data/spec/fixtures/ea_address_facade_v1_not_found.json +0 -8
  23. data/spec/fixtures/ea_address_facade_v1_valid.json +0 -45
  24. data/spec/fixtures/os_places_address_lookup_blank.json +0 -5
  25. data/spec/fixtures/os_places_address_lookup_not_found.json +0 -6
  26. data/spec/fixtures/os_places_address_lookup_valid.json +0 -56
  27. data/spec/spec_helper.rb +0 -83
  28. data/spec/support/defra_ruby_address.rb +0 -4
  29. data/spec/support/dotenv.rb +0 -4
  30. data/spec/support/pry.rb +0 -7
  31. data/spec/support/shared_examples/handle_request_errors.rb +0 -32
  32. data/spec/support/simplecov.rb +0 -17
  33. data/spec/support/webmock.rb +0 -4
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module DefraRuby
6
- module Address
7
- RSpec.describe EaAddressFacadeV11Service do
8
- describe "#run" do
9
- before do
10
- DefraRuby::Address.configure { |c| c.host = "http://localhost:8005/" }
11
- stub_request(:get, url).to_return(status: code, body: body)
12
- end
13
-
14
- let(:client_id) { DefraRuby::Address.configuration.client_id }
15
- let(:key) { DefraRuby::Address.configuration.key }
16
- let(:postcode) { "BS1 5AH" }
17
- let(:url) { "http://localhost:8005/address-service/v1/addresses/postcode?client-id=#{client_id}&key=#{key}&query-string=#{postcode}" }
18
- let(:code) { 200 }
19
- let(:body) { File.read("spec/fixtures/ea_address_facade_v1_1_valid.json") }
20
-
21
- include_examples "handle request errors"
22
-
23
- context "when the postcode is valid" do
24
-
25
- it "returns a successful response" do
26
- response = described_class.run(postcode)
27
-
28
- expect(a_request(:get, url)).to have_been_made.at_most_once
29
-
30
- expect(response).to be_a(Response)
31
- expect(response.successful?).to eq(true)
32
- expect(response.results).not_to be_empty
33
- end
34
- end
35
-
36
- context "when the postcode is invalid" do
37
- context "because it is not found" do
38
- let(:postcode) { "BS1 9XX" }
39
- let(:body) { File.read("spec/fixtures/ea_address_facade_v1_1_not_found.json") }
40
-
41
- it "returns a 'NoMatchError'" do
42
- response = described_class.run(postcode)
43
-
44
- expect(a_request(:get, url)).to have_been_made.at_most_once
45
-
46
- expect(response).to be_a(Response)
47
- expect(response).to_not be_successful
48
- expect(response.results).to be_empty
49
- expect(response.error).to be_an_instance_of(DefraRuby::Address::NoMatchError)
50
- end
51
- end
52
-
53
- context "because it is blank" do
54
- let(:postcode) { "" }
55
- let(:code) { 400 }
56
- let(:body) { File.read("spec/fixtures/ea_address_facade_v1_1_blank.json") }
57
-
58
- it "returns a failed response" do
59
- response = described_class.run(postcode)
60
-
61
- expect(a_request(:get, url)).to have_been_made.at_most_once
62
-
63
- expect(response).to be_a(Response)
64
- expect(response).to_not be_successful
65
- expect(response.results).to be_empty
66
- expect(response.error).to be_an_instance_of(RestClient::BadRequest)
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module DefraRuby
6
- module Address
7
- RSpec.describe EaAddressFacadeV1Service do
8
- describe "#run" do
9
- before do
10
- DefraRuby::Address.configure { |c| c.host = "http://localhost:8005/" }
11
- stub_request(:get, url).to_return(status: code, body: body)
12
- end
13
-
14
- let(:client_id) { DefraRuby::Address.configuration.client_id }
15
- let(:key) { DefraRuby::Address.configuration.key }
16
- let(:postcode) { "BS1 5AH" }
17
- let(:url) { "http://localhost:8005/address-service/v1/addresses/postcode?client-id=#{client_id}&key=#{key}&postcode=#{postcode}" }
18
- let(:code) { 200 }
19
- let(:body) { File.read("spec/fixtures/ea_address_facade_v1_valid.json") }
20
-
21
- include_examples "handle request errors"
22
-
23
- context "when the postcode is valid" do
24
-
25
- it "returns a successful response" do
26
- response = described_class.run(postcode)
27
-
28
- expect(a_request(:get, url)).to have_been_made.at_most_once
29
-
30
- expect(response).to be_a(Response)
31
- expect(response.successful?).to eq(true)
32
- expect(response.results).not_to be_empty
33
- end
34
- end
35
-
36
- context "when the postcode is invalid" do
37
- context "because it is not found" do
38
- let(:postcode) { "BS1 9XX" }
39
- let(:body) { File.read("spec/fixtures/ea_address_facade_v1_not_found.json") }
40
-
41
- it "returns a 'NoMatchError'" do
42
- response = described_class.run(postcode)
43
-
44
- expect(a_request(:get, url)).to have_been_made.at_most_once
45
-
46
- expect(response).to be_a(Response)
47
- expect(response).to_not be_successful
48
- expect(response.results).to be_empty
49
- expect(response.error).to be_an_instance_of(DefraRuby::Address::NoMatchError)
50
- end
51
- end
52
-
53
- context "because it is blank" do
54
- let(:postcode) { "" }
55
- let(:code) { 400 }
56
- let(:body) { File.read("spec/fixtures/ea_address_facade_v1_blank.json") }
57
-
58
- it "returns a failed response" do
59
- response = described_class.run(postcode)
60
-
61
- expect(a_request(:get, url)).to have_been_made.at_most_once
62
-
63
- expect(response).to be_a(Response)
64
- expect(response).to_not be_successful
65
- expect(response.results).to be_empty
66
- expect(response.error).to be_an_instance_of(RestClient::BadRequest)
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module DefraRuby
6
- module Address
7
- RSpec.describe OsPlacesAddressLookupService do
8
- describe "#run" do
9
- before do
10
- DefraRuby::Address.configure { |c| c.host = "http://localhost:8005/" }
11
- stub_request(:get, url).to_return(status: code, body: body)
12
- end
13
-
14
- let(:postcode) { "BS1 5AH" }
15
- let(:url) { "http://localhost:8005/addresses?postcode=#{postcode}" }
16
- let(:code) { 200 }
17
- let(:body) { File.read("spec/fixtures/os_places_address_lookup_valid.json") }
18
-
19
- include_examples "handle request errors"
20
-
21
- context "when the postcode is valid" do
22
-
23
- it "returns a successful response" do
24
- response = described_class.run(postcode)
25
-
26
- expect(a_request(:get, url)).to have_been_made.at_most_once
27
-
28
- expect(response).to be_a(Response)
29
- expect(response.successful?).to eq(true)
30
- expect(response.results).not_to be_empty
31
- end
32
- end
33
-
34
- context "when the postcode is invalid" do
35
- let(:code) { 400 }
36
-
37
- context "because it is not found" do
38
- let(:postcode) { "BS1 9XX" }
39
- let(:body) { File.read("spec/fixtures/os_places_address_lookup_not_found.json") }
40
-
41
- it "returns a 'NoMatchError'" do
42
- response = described_class.run(postcode)
43
-
44
- expect(a_request(:get, url)).to have_been_made.at_most_once
45
-
46
- expect(response).to be_a(Response)
47
- expect(response).to_not be_successful
48
- expect(response.results).to be_empty
49
- expect(response.error).to be_an_instance_of(DefraRuby::Address::NoMatchError)
50
- end
51
- end
52
-
53
- context "because it is blank" do
54
- let(:postcode) { "" }
55
- let(:body) { File.read("spec/fixtures/os_places_address_lookup_blank.json") }
56
-
57
- it "returns a failed response" do
58
- response = described_class.run(postcode)
59
-
60
- expect(a_request(:get, url)).to have_been_made.at_most_once
61
-
62
- expect(response).to be_a(Response)
63
- expect(response).to_not be_successful
64
- expect(response.results).to be_empty
65
- expect(response.error).to be_an_instance_of(RestClient::BadRequest)
66
- end
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe DefraRuby::Address do
6
- describe "VERSION" do
7
- it "is a version string in the correct format" do
8
- expect(DefraRuby::Address::VERSION).to be_a(String)
9
- expect(DefraRuby::Address::VERSION).to match(/\d+\.\d+\.\d+/)
10
- end
11
- end
12
-
13
- describe "#configuration" do
14
- context "when the host app has not provided configuration" do
15
- it "returns a DefraRuby::Address::Configuration instance" do
16
- expect(described_class.configuration).to be_an_instance_of(DefraRuby::Address::Configuration)
17
- end
18
- end
19
-
20
- context "when the host app has provided configuration" do
21
- let(:host) { "http://localhost:9012" }
22
-
23
- it "returns an DefraRuby::Address::Configuration instance with a matching host" do
24
- described_class.configure { |config| config.host = host }
25
-
26
- expect(described_class.configuration.host).to eq(host)
27
- end
28
- end
29
- end
30
- end
data/spec/examples.txt DELETED
@@ -1,27 +0,0 @@
1
- example_id | status | run_time |
2
- -------------------------------------------------------------------------------------- | ------ | --------------- |
3
- ./spec/defra_ruby/address/configuration_spec.rb[1:1] | passed | 0.00888 seconds |
4
- ./spec/defra_ruby/address/response_spec.rb[1:1:1:1] | passed | 0.00013 seconds |
5
- ./spec/defra_ruby/address/response_spec.rb[1:1:2:1] | passed | 0.0003 seconds |
6
- ./spec/defra_ruby/address/response_spec.rb[1:2:1:1] | passed | 0.0001 seconds |
7
- ./spec/defra_ruby/address/response_spec.rb[1:2:2:1] | passed | 0.00014 seconds |
8
- ./spec/defra_ruby/address/response_spec.rb[1:3:1:1] | passed | 0.00011 seconds |
9
- ./spec/defra_ruby/address/response_spec.rb[1:3:2:1] | passed | 0.0001 seconds |
10
- ./spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb[1:1:1:1:1] | passed | 0.00301 seconds |
11
- ./spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb[1:1:1:2:1] | passed | 0.00311 seconds |
12
- ./spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb[1:1:2:1] | passed | 0.01005 seconds |
13
- ./spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb[1:1:3:1:1] | passed | 0.01183 seconds |
14
- ./spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb[1:1:3:2:1] | passed | 0.00571 seconds |
15
- ./spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb[1:1:1:1:1] | passed | 0.00323 seconds |
16
- ./spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb[1:1:1:2:1] | passed | 0.00337 seconds |
17
- ./spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb[1:1:2:1] | passed | 0.02025 seconds |
18
- ./spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb[1:1:3:1:1] | passed | 0.0075 seconds |
19
- ./spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb[1:1:3:2:1] | passed | 0.00576 seconds |
20
- ./spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb[1:1:1:1:1] | passed | 0.0035 seconds |
21
- ./spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb[1:1:1:2:1] | passed | 0.00558 seconds |
22
- ./spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb[1:1:2:1] | passed | 0.0041 seconds |
23
- ./spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb[1:1:3:1:1] | passed | 0.00572 seconds |
24
- ./spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb[1:1:3:2:1] | passed | 0.00559 seconds |
25
- ./spec/defra_ruby/address_spec.rb[1:1:1] | passed | 0.00494 seconds |
26
- ./spec/defra_ruby/address_spec.rb[1:2:1:1] | passed | 0.00262 seconds |
27
- ./spec/defra_ruby/address_spec.rb[1:2:2:1] | passed | 0.00014 seconds |
@@ -1,8 +0,0 @@
1
- {
2
- "facade_status_code": 400,
3
- "facade_error_message": "bad request to facade service, no request made to supplier service. required paramater missing.",
4
- "facade_error_code": "address_service_error_13",
5
- "supplier_was_called": false,
6
- "supplier_status_code": null,
7
- "supplier_response": null
8
- }
@@ -1,14 +0,0 @@
1
- {
2
- "header": {
3
- "totalMatches": 0,
4
- "startMatch": null,
5
- "endMatch": null,
6
- "query": "postcode=BS1 9XX",
7
- "language": "EN",
8
- "dataset": "DPA",
9
- "epoch": "70",
10
- "uriToSupplier": "https://api.ordnancesurvey.co.uk/places/v1/addresses/postcode?lr=EN&postcode=BS1%209XX&fq=logical_status_code%3A1&dataset=DPA",
11
- "uriFromClient": ""
12
- },
13
- "results": []
14
- }
@@ -1,83 +0,0 @@
1
- {
2
- "header": {
3
- "totalMatches": 2,
4
- "startMatch": 1,
5
- "endMatch": 2,
6
- "query": "postcode=BS1 5AH",
7
- "language": "EN",
8
- "dataset": "DPA",
9
- "epoch": "70",
10
- "uriToSupplier": "https://api.ordnancesurvey.co.uk/places/v1/addresses/postcode?lr=EN&postcode=BS1%205AH&fq=logical_status_code%3A1&dataset=DPA",
11
- "uriFromClient": ""
12
- },
13
- "results": [
14
- {
15
- "uprn": 340116,
16
- "address": "ENVIRONMENT AGENCY, HORIZON HOUSE, DEANERY ROAD, BRISTOL, BS1 5AH",
17
- "organisation": "ENVIRONMENT AGENCY",
18
- "premises": "HORIZON HOUSE",
19
- "street_address": "DEANERY ROAD",
20
- "locality": null,
21
- "city": "BRISTOL",
22
- "postcode": "BS1 5AH",
23
- "country": "United Kingdom",
24
- "x": 358205.03,
25
- "y": 172708.06,
26
- "coordinate_system": null,
27
- "blpu_state_date": "12/10/2009",
28
- "blpu_state_code": 2,
29
- "postal_address_code": "D",
30
- "logical_status_code": 1,
31
- "source_data_type": "dpa",
32
- "blpu_state_code_description": "In use",
33
- "classification_code": "CO01",
34
- "classification_code_description": "Office / Work Studio",
35
- "lpi_logical_status_code": null,
36
- "lpi_logical_status_code_description": null,
37
- "match": 1.0,
38
- "match_description": "EXACT",
39
- "topography_layer_toid": "osgb1000002529079737",
40
- "parent_uprn": null,
41
- "last_update_date": "10/02/2016",
42
- "status": "APPROVED",
43
- "entry_date": "12/10/2009",
44
- "postal_address_code_description": "A record which is linked to PAF",
45
- "usrn": null,
46
- "language": "EN"
47
- },
48
- {
49
- "uprn": 340117,
50
- "address": "THRIVE RENEWABLES PLC, DEANERY ROAD, BRISTOL, BS1 5AH",
51
- "organisation": "THRIVE RENEWABLES PLC",
52
- "premises": null,
53
- "street_address": "DEANERY ROAD",
54
- "locality": null,
55
- "city": "BRISTOL",
56
- "postcode": "BS1 5AH",
57
- "country": "United Kingdom",
58
- "x": 358130.1,
59
- "y": 172687.88,
60
- "coordinate_system": null,
61
- "blpu_state_date": "12/10/2009",
62
- "blpu_state_code": 2,
63
- "postal_address_code": "D",
64
- "logical_status_code": 1,
65
- "source_data_type": "dpa",
66
- "blpu_state_code_description": "In use",
67
- "classification_code": "CO01",
68
- "classification_code_description": "Office / Work Studio",
69
- "lpi_logical_status_code": null,
70
- "lpi_logical_status_code_description": null,
71
- "match": 1.0,
72
- "match_description": "EXACT",
73
- "topography_layer_toid": "osgb1000002529079753",
74
- "parent_uprn": null,
75
- "last_update_date": "14/03/2019",
76
- "status": "APPROVED",
77
- "entry_date": "12/10/2009",
78
- "postal_address_code_description": "A record which is linked to PAF",
79
- "usrn": null,
80
- "language": "EN"
81
- }
82
- ]
83
- }
@@ -1,13 +0,0 @@
1
- {
2
- "facade_status_code": 400,
3
- "facade_error_message": "bad request to supplier service",
4
- "facade_error_code": "address_service_error_1",
5
- "supplier_was_called": true,
6
- "supplier_status_code": 400,
7
- "supplier_response": {
8
- "error": {
9
- "statuscode": 400,
10
- "message": "Parameter postcode cannot be empty."
11
- }
12
- }
13
- }
@@ -1,8 +0,0 @@
1
- {
2
- "totalMatches": 0,
3
- "startMatch": null,
4
- "endMatch": null,
5
- "uri_to_supplier": "https://api.ordnancesurvey.co.uk/places/v1/addresses/postcode?lr=EN&postcode=bs19xx&maxresults=100&dataset=DPA",
6
- "uri_from_client": "stub",
7
- "results": []
8
- }
@@ -1,45 +0,0 @@
1
- {
2
- "totalMatches": 2,
3
- "startMatch": 1,
4
- "endMatch": 2,
5
- "uri_to_supplier": "https://api.ordnancesurvey.co.uk/places/v1/addresses/postcode?lr=EN&postcode=bs15ah&maxresults=100&dataset=DPA",
6
- "uri_from_client": "stub",
7
- "results": [
8
- {
9
- "uprn": 340116,
10
- "address": "ENVIRONMENT AGENCY, HORIZON HOUSE, DEANERY ROAD, BRISTOL, BS1 5AH",
11
- "organisation": "ENVIRONMENT AGENCY",
12
- "premises": "HORIZON HOUSE",
13
- "street_address": "DEANERY ROAD",
14
- "locality": null,
15
- "city": "BRISTOL",
16
- "postcode": "BS1 5AH",
17
- "x": "358205.03",
18
- "y": "172708.07",
19
- "coordinate_system": null,
20
- "state_date": "12/10/2009",
21
- "blpu_state_code": null,
22
- "postal_address_code": null,
23
- "logical_status_code": null,
24
- "source_data_type": "dpa"
25
- },
26
- {
27
- "uprn": 340117,
28
- "address": "THRIVE RENEWABLES PLC, DEANERY ROAD, BRISTOL, BS1 5AH",
29
- "organisation": "THRIVE RENEWABLES PLC",
30
- "premises": null,
31
- "street_address": "DEANERY ROAD",
32
- "locality": null,
33
- "city": "BRISTOL",
34
- "postcode": "BS1 5AH",
35
- "x": "358130.1",
36
- "y": "172687.87",
37
- "coordinate_system": null,
38
- "state_date": "12/10/2009",
39
- "blpu_state_code": null,
40
- "postal_address_code": null,
41
- "logical_status_code": null,
42
- "source_data_type": "dpa"
43
- }
44
- ]
45
- }
@@ -1,5 +0,0 @@
1
- {
2
- "errors": [
3
- "query param postcode may not be empty"
4
- ]
5
- }
@@ -1,6 +0,0 @@
1
- {
2
- "error": {
3
- "statuscode": 400,
4
- "message": "Parameters are not valid"
5
- }
6
- }
@@ -1,56 +0,0 @@
1
- [
2
- {
3
- "moniker": "340116",
4
- "uprn": "340116",
5
- "lines": [
6
- "ENVIRONMENT AGENCY",
7
- "DEANERY ROAD"
8
- ],
9
- "town": "BRISTOL",
10
- "postcode": "BS1 5AH",
11
- "easting": "358205",
12
- "northing": "172708",
13
- "country": "",
14
- "dependentLocality": "",
15
- "dependentThroughfare": "",
16
- "administrativeArea": "BRISTOL",
17
- "localAuthorityUpdateDate": "",
18
- "royalMailUpdateDate": "",
19
- "partial": "ENVIRONMENT AGENCY, HORIZON HOUSE, DEANERY ROAD, BRISTOL, BS1 5AH",
20
- "subBuildingName": "",
21
- "buildingName": "HORIZON HOUSE",
22
- "thoroughfareName": "DEANERY ROAD",
23
- "organisationName": "ENVIRONMENT AGENCY",
24
- "buildingNumber": "",
25
- "postOfficeBoxNumber": "",
26
- "departmentName": "",
27
- "doubleDependentLocality": ""
28
- },
29
- {
30
- "moniker": "340117",
31
- "uprn": "340117",
32
- "lines": [
33
- "THRIVE RENEWABLES PLC",
34
- "DEANERY ROAD"
35
- ],
36
- "town": "BRISTOL",
37
- "postcode": "BS1 5AH",
38
- "easting": "358130",
39
- "northing": "172687",
40
- "country": "",
41
- "dependentLocality": "",
42
- "dependentThroughfare": "",
43
- "administrativeArea": "BRISTOL",
44
- "localAuthorityUpdateDate": "",
45
- "royalMailUpdateDate": "",
46
- "partial": "THRIVE RENEWABLES PLC, DEANERY ROAD, BRISTOL, BS1 5AH",
47
- "subBuildingName": "",
48
- "buildingName": "",
49
- "thoroughfareName": "DEANERY ROAD",
50
- "organisationName": "THRIVE RENEWABLES PLC",
51
- "buildingNumber": "",
52
- "postOfficeBoxNumber": "",
53
- "departmentName": "",
54
- "doubleDependentLocality": ""
55
- }
56
- ]
data/spec/spec_helper.rb DELETED
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/setup"
4
-
5
- # Require and run our simplecov initializer as the very first thing we do.
6
- # This is as per its docs https://github.com/colszowka/simplecov#getting-started
7
- require "./spec/support/simplecov"
8
-
9
- # Requires supporting ruby files with custom matchers and macros, etc, in
10
- # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
11
- # run as spec files by default. This means that files in spec/support that end
12
- # in _spec.rb will both be required and run as specs, causing the specs to be
13
- # run twice. It is recommended that you do not name files matching this glob to
14
- # end with _spec.rb. You can configure this pattern with the --pattern
15
- # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
16
- #
17
- # We make an exception for simplecov because that will already have been
18
- # required and run at the very top of spec_helper.rb
19
- support_files = Dir["./spec/support/**/*.rb"].reject { |file| file == "./spec/support/simplecov.rb" }
20
- support_files.each { |f| require f }
21
-
22
- RSpec.configure do |config|
23
- # rspec-expectations config goes here. You can use an alternate
24
- # assertion/expectation library such as wrong or the stdlib/minitest
25
- # assertions if you prefer.
26
- config.expect_with :rspec do |expectations|
27
- # This option will default to `true` in RSpec 4. It makes the `description`
28
- # and `failure_message` of custom matchers include text for helper methods
29
- # defined using `chain`, e.g.:
30
- # be_bigger_than(2).and_smaller_than(4).description
31
- # # => "be bigger than 2 and smaller than 4"
32
- # ...rather than:
33
- # # => "be bigger than 2"
34
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
- end
36
-
37
- # rspec-mocks config goes here. You can use an alternate test double
38
- # library (such as bogus or mocha) by changing the `mock_with` option here.
39
- config.mock_with :rspec do |mocks|
40
- # Prevents you from mocking or stubbing a method that does not exist on
41
- # a real object. This is generally recommended, and will default to
42
- # `true` in RSpec 4.
43
- mocks.verify_partial_doubles = true
44
- end
45
-
46
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
47
- # have no way to turn it off -- the option exists only for backwards
48
- # compatibility in RSpec 3). It causes shared context metadata to be
49
- # inherited by the metadata hash of host groups and examples, rather than
50
- # triggering implicit auto-inclusion in groups with matching metadata.
51
- config.shared_context_metadata_behavior = :apply_to_host_groups
52
-
53
- # This allows you to limit a spec run to individual examples or groups
54
- # you care about by tagging them with `:focus` metadata. When nothing
55
- # is tagged with `:focus`, all examples get run. RSpec also provides
56
- # aliases for `it`, `describe`, and `context` that include `:focus`
57
- # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58
- config.filter_run_when_matching :focus
59
-
60
- # Allows RSpec to persist some state between runs in order to support
61
- # the `--only-failures` and `--next-failure` CLI options. We recommend
62
- # you configure your source control system to ignore this file.
63
- config.example_status_persistence_file_path = "spec/examples.txt"
64
-
65
- # Limits the available syntax to the non-monkey patched syntax that is
66
- # recommended. For more details, see:
67
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70
- config.disable_monkey_patching!
71
-
72
- # Run specs in random order to surface order dependencies. If you find an
73
- # order dependency and want to debug it, you can fix the order by providing
74
- # the seed, which is printed after each run.
75
- # --seed 1234
76
- config.order = :random
77
-
78
- # Seed global randomization in this process using the `--seed` CLI option.
79
- # Setting this allows you to use `--seed` to deterministically reproduce
80
- # test failures related to randomization by passing the same `--seed` value
81
- # as the one that triggered the failure.
82
- Kernel.srand config.seed
83
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Need to require our actual code files.
4
- require "defra_ruby/address"
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Load env vars from a text file
4
- require "dotenv/load"
data/spec/support/pry.rb DELETED
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Support debugging in the tests. Add `binding.pry` wherever you want execution
4
- # to stop and the debugger to kick in.
5
- # Details on the debugging commands can be found here
6
- # https://github.com/deivid-rodriguez/pry-byebug#commands
7
- require "pry-byebug"
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples "handle request errors" do
4
- context "when there is a problem with the address lookup" do
5
-
6
- context "and the request times out" do
7
- before { stub_request(:get, url).to_timeout }
8
-
9
- it "returns a failed response" do
10
- response = described_class.run(postcode)
11
-
12
- expect(response).to be_a(DefraRuby::Address::Response)
13
- expect(response).to_not be_successful
14
- expect(response.results).to be_empty
15
- expect(response.error).to_not be_nil
16
- end
17
- end
18
-
19
- context "and the request returns an error" do
20
- before { stub_request(:get, url).to_raise(SocketError) }
21
-
22
- it "returns a failed response" do
23
- response = described_class.run(postcode)
24
-
25
- expect(response).to be_a(DefraRuby::Address::Response)
26
- expect(response).to_not be_successful
27
- expect(response.results).to be_empty
28
- expect(response.error).to_not be_nil
29
- end
30
- end
31
- end
32
- end