defra_ruby_area 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ module DefraRuby
6
+ module Area
7
+ RSpec.describe WaterManagementAreaService do
8
+ describe "#run" do
9
+
10
+ context "when the coordinates are valid and in England" do
11
+ before(:each) { VCR.insert_cassette("water_management_area_valid") }
12
+ after(:each) { VCR.eject_cassette }
13
+
14
+ let(:easting) { 408_602.61 }
15
+ let(:northing) { 257_535.31 }
16
+
17
+ it "returns a successful response" do
18
+ response = described_class.run(easting, northing)
19
+ expect(response).to be_a(Response)
20
+ expect(response.successful?).to eq(true)
21
+ expect(response.area).to eq("Staffordshire Warwickshire and West Midlands")
22
+ end
23
+
24
+ end
25
+
26
+ context "when the coordinates are invalid" do
27
+ context "because they are blank" do
28
+ before(:each) { VCR.insert_cassette("water_management_area_invalid_blank") }
29
+ after(:each) { VCR.eject_cassette }
30
+
31
+ let(:easting) { nil }
32
+ let(:northing) { nil }
33
+
34
+ it "returns a failed response" do
35
+ response = described_class.run(easting, northing)
36
+ expect(response).to be_a(Response)
37
+ expect(response).to_not be_successful
38
+ expect(response.area).to be_nil
39
+ expect(response.error).to_not be_nil
40
+ end
41
+ end
42
+
43
+ context "because they are not in an area" do
44
+ before(:each) { VCR.insert_cassette("water_management_area_invalid_coords") }
45
+ after(:each) { VCR.eject_cassette }
46
+
47
+ let(:easting) { 301_233.0 }
48
+ let(:northing) { 221_592.0 }
49
+
50
+ it "returns a failed response" do
51
+ response = described_class.run(easting, northing)
52
+ expect(response).to be_a(Response)
53
+ expect(response).to_not be_successful
54
+ expect(response.area).to be_nil
55
+ expect(response.error).to_not be_nil
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe DefraRuby::Area do
6
+ describe "VERSION" do
7
+ it "is a version string in the correct format" do
8
+ expect(DefraRuby::Area::VERSION).to be_a(String)
9
+ expect(DefraRuby::Area::VERSION).to match(/\d+\.\d+\.\d+/)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ example_id | status | run_time |
2
+ -------------------------------------------------------------------------------- | ------ | --------------- |
3
+ ./spec/defra_ruby/area/response_spec.rb[1:1:1:1] | passed | 0.00012 seconds |
4
+ ./spec/defra_ruby/area/response_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
5
+ ./spec/defra_ruby/area/response_spec.rb[1:2:1:1] | passed | 0.00017 seconds |
6
+ ./spec/defra_ruby/area/response_spec.rb[1:2:2:1] | passed | 0.00009 seconds |
7
+ ./spec/defra_ruby/area/response_spec.rb[1:3:1:1] | passed | 0.00012 seconds |
8
+ ./spec/defra_ruby/area/response_spec.rb[1:3:2:1] | passed | 0.0001 seconds |
9
+ ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:1:1] | passed | 6.86 seconds |
10
+ ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:2:1:1] | passed | 6.55 seconds |
11
+ ./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:2:2:1] | passed | 0.02233 seconds |
12
+ ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:1:1] | passed | 0.03547 seconds |
13
+ ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:2:1:1] | passed | 0.022 seconds |
14
+ ./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:2:2:1] | passed | 0.02539 seconds |
15
+ ./spec/defra_ruby/area_spec.rb[1:1:1] | passed | 0.00171 seconds |
@@ -0,0 +1,83 @@
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
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Need to require our actual code files.
4
+ require "defra_ruby/area"
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load env vars from a text file
4
+ require "dotenv/load"
@@ -0,0 +1,7 @@
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"
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
4
+
5
+ # We start it with the rails param to ensure it includes coverage for all code
6
+ # started by the rails app, and not just the files touched by our unit tests.
7
+ # This gives us the most accurate assessment of our unit test coverage
8
+ # https://github.com/colszowka/simplecov#getting-started
9
+ SimpleCov.start do
10
+ # We filter the spec folder, mainly to ensure that any dummy apps don't get
11
+ # included in the coverage report. However our intent is that nothing in the
12
+ # spec folder should be included
13
+ add_filter "/spec/"
14
+ # The version file is simply just that, so we do not feel the need to ensure
15
+ # we have a test for it
16
+ add_filter "lib/defra_ruby/validators/version"
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Stubbing HTTP requests
4
+ require "webmock/rspec"
5
+ # Auto generate fake responses for web-requests
6
+ require "vcr"
7
+
8
+ VCR.configure do |c|
9
+ c.cassette_library_dir = "spec/cassettes"
10
+ c.hook_into :webmock
11
+
12
+ c.ignore_hosts "127.0.0.1", "codeclimate.com"
13
+
14
+ SECONDS_IN_DAY = 24 * 60 * 60
15
+
16
+ c.default_cassette_options = { re_record_interval: (14 * SECONDS_IN_DAY) }
17
+ end
metadata ADDED
@@ -0,0 +1,261 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: defra_ruby_area
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Defra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: defra_ruby_style
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: github_changelog_generator
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: vcr
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '4.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '4.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: webmock
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '3.4'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '3.4'
181
+ description: Use to query the EA's administrative boundary Web Feature Services for
182
+ area names.
183
+ email:
184
+ - alan.cruikshanks@environment-agency.gov.uk
185
+ executables: []
186
+ extensions: []
187
+ extra_rdoc_files: []
188
+ files:
189
+ - LICENSE
190
+ - README.md
191
+ - Rakefile
192
+ - bin/console
193
+ - bin/setup
194
+ - lib/defra_ruby.rb
195
+ - lib/defra_ruby/area.rb
196
+ - lib/defra_ruby/area/no_match_error.rb
197
+ - lib/defra_ruby/area/response.rb
198
+ - lib/defra_ruby/area/services/base_area_service.rb
199
+ - lib/defra_ruby/area/services/public_face_area_service.rb
200
+ - lib/defra_ruby/area/services/water_management_area_service.rb
201
+ - lib/defra_ruby/area/version.rb
202
+ - spec/cassettes/public_face_area_invalid_blank.yml
203
+ - spec/cassettes/public_face_area_invalid_coords.yml
204
+ - spec/cassettes/public_face_area_valid.yml
205
+ - spec/cassettes/water_management_area_invalid_blank.yml
206
+ - spec/cassettes/water_management_area_invalid_coords.yml
207
+ - spec/cassettes/water_management_area_valid.yml
208
+ - spec/defra_ruby/area/response_spec.rb
209
+ - spec/defra_ruby/area/services/public_face_area_service_spec.rb
210
+ - spec/defra_ruby/area/services/water_management_area_service_spec.rb
211
+ - spec/defra_ruby/area_spec.rb
212
+ - spec/examples.txt
213
+ - spec/spec_helper.rb
214
+ - spec/support/defra_ruby_area.rb
215
+ - spec/support/dotenv.rb
216
+ - spec/support/pry.rb
217
+ - spec/support/simplecov.rb
218
+ - spec/support/vcr.rb
219
+ homepage: https://github.com/DEFRA/defra-ruby-area
220
+ licenses:
221
+ - The Open Government Licence (OGL) Version 3
222
+ metadata:
223
+ allowed_push_host: https://rubygems.org
224
+ post_install_message:
225
+ rdoc_options: []
226
+ require_paths:
227
+ - lib
228
+ required_ruby_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
233
+ required_rubygems_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ requirements: []
239
+ rubyforge_project:
240
+ rubygems_version: 2.6.13
241
+ signing_key:
242
+ specification_version: 4
243
+ summary: Defra ruby on rails EA administrative area lookup
244
+ test_files:
245
+ - spec/spec_helper.rb
246
+ - spec/defra_ruby/area/response_spec.rb
247
+ - spec/defra_ruby/area/services/water_management_area_service_spec.rb
248
+ - spec/defra_ruby/area/services/public_face_area_service_spec.rb
249
+ - spec/defra_ruby/area_spec.rb
250
+ - spec/examples.txt
251
+ - spec/cassettes/water_management_area_invalid_coords.yml
252
+ - spec/cassettes/public_face_area_invalid_coords.yml
253
+ - spec/cassettes/water_management_area_invalid_blank.yml
254
+ - spec/cassettes/public_face_area_valid.yml
255
+ - spec/cassettes/water_management_area_valid.yml
256
+ - spec/cassettes/public_face_area_invalid_blank.yml
257
+ - spec/support/defra_ruby_area.rb
258
+ - spec/support/simplecov.rb
259
+ - spec/support/vcr.rb
260
+ - spec/support/pry.rb
261
+ - spec/support/dotenv.rb