dns_mock 1.0.0 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc32cd03521879fd373e554a2dbb29ae26ca002586418675fdc066b7ad5eab57
4
- data.tar.gz: f309b21a3e48780dedef123a95bab5267dc3679ec3809def258a189485f5a6c4
3
+ metadata.gz: 66e5860c3ab25815cc94543f7703b1318c13fa55492921de37db8649f4f28ea7
4
+ data.tar.gz: 2e2d5ac9dfce7a0fb5d16bc8ac90b0a964face183eb4535e75d291c6613363d8
5
5
  SHA512:
6
- metadata.gz: fa16a2db1e2c9b8e903b29241f08d2b7695dfa3b98c9364c7d8ea87b361a67b21e72f898378d64b75500f9bc0ab90d14a33b94443561760ec99a820e02c0d8b4
7
- data.tar.gz: 3f236e1c88970784a9d137994562595b06f3d78c0555aa3279810ae1821792d5b46c50f56e8bb63b3c66c060f9f495e4e09f6ada7ee6ae0588772a2ebb7d1a72
6
+ metadata.gz: 6a8decdc20ec9e3ae7e829e9baa82b2f736c4e13c0306447c98eae9c84919299811afe25ddaece1b7cf1949aee817c3533fd692e11a40f3332bead029a89fe36
7
+ data.tar.gz: e48f73f649d5ba827362bc7db39c0ad0bd30f67601694ec54ee5038fbae9519f4bffa12303047f6395b15f6be3f6de3a2c738e89583817c454b5472cb3f10bfe
data/.circleci/config.yml CHANGED
@@ -1,11 +1,21 @@
1
+ version: 2.1
2
+
1
3
  defaults: &defaults
2
4
  working_directory: ~/ruby-dns-mock
3
5
  docker:
4
- - image: circleci/ruby:2.5.0-node
6
+ - image: cimg/ruby:<< parameters.ruby-version >>
5
7
  environment:
6
8
  CC_TEST_REPORTER_ID: 18fba9e7d6885c48453a80a0f019a60d9ffa3fd80467652a6b3c95fef5ea9a50
7
9
 
10
+ orbs:
11
+ ruby: circleci/ruby@1.1.3
12
+
8
13
  references:
14
+ install_bundler: &install_bundler
15
+ run:
16
+ name: Installing bundler
17
+ command: gem i bundler -v $(tail -1 Gemfile.lock | tr -d ' ')
18
+
9
19
  restore_bundle_cache: &restore_bundle_cache
10
20
  restore_cache:
11
21
  keys:
@@ -24,19 +34,23 @@ references:
24
34
 
25
35
  install_codeclimate_reporter: &install_codeclimate_reporter
26
36
  run:
27
- name: Install Code Climate Test Reporter
37
+ name: Install Code Climate test reporter
28
38
  command: |
29
39
  curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
30
40
  chmod +x ./cc-test-reporter
31
41
 
32
- version: 2
33
42
  jobs:
34
- linters:
43
+ linters-with-ruby:
44
+ parameters:
45
+ ruby-version:
46
+ type: string
47
+
35
48
  <<: *defaults
36
49
 
37
50
  steps:
38
51
  - checkout
39
52
 
53
+ - <<: *install_bundler
40
54
  - <<: *restore_bundle_cache
41
55
  - <<: *bundle_install
42
56
  - <<: *save_bundle_cache
@@ -47,12 +61,17 @@ jobs:
47
61
  bundle exec overcommit -s
48
62
  SKIP=AuthorEmail,AuthorName bundle exec overcommit -r
49
63
 
50
- tests:
64
+ tests-and-coverage-with-ruby:
65
+ parameters:
66
+ ruby-version:
67
+ type: string
68
+
51
69
  <<: *defaults
52
70
 
53
71
  steps:
54
72
  - checkout
55
73
 
74
+ - <<: *install_bundler
56
75
  - <<: *restore_bundle_cache
57
76
  - <<: *bundle_install
58
77
  - <<: *save_bundle_cache
@@ -61,7 +80,6 @@ jobs:
61
80
  - run:
62
81
  name: Running tests
63
82
  command: |
64
- mkdir /tmp/test-results
65
83
  ./cc-test-reporter before-build
66
84
  bundle exec rspec
67
85
 
@@ -70,20 +88,41 @@ jobs:
70
88
  command: |
71
89
  ./cc-test-reporter format-coverage -t simplecov -o "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
72
90
 
73
- - store_test_results:
74
- path: /tmp/test-results
75
-
76
91
  - store_artifacts:
77
- path: /tmp/test-results
78
- destination: test-results
92
+ path: ~/ruby-dns-mock/coverage
93
+ destination: coverage
79
94
 
80
95
  - deploy:
81
96
  command: |
82
97
  ./cc-test-reporter sum-coverage --output - --parts $CIRCLE_NODE_TOTAL coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
83
98
 
99
+ compatibility-with-ruby:
100
+ parameters:
101
+ ruby-version:
102
+ type: string
103
+ docker:
104
+ - image: cimg/ruby:<< parameters.ruby-version >>
105
+ steps:
106
+ - checkout
107
+ - ruby/install-deps:
108
+ with-cache: false
109
+ path: './vendor/custom_bundle'
110
+ - run:
111
+ name: Running compatibility tests
112
+ command: bundle exec rspec
113
+
84
114
  workflows:
85
- version: 2
86
- build:
115
+ build_and_test:
87
116
  jobs:
88
- - linters
89
- - tests
117
+ - linters-with-ruby:
118
+ matrix:
119
+ parameters:
120
+ ruby-version: ["2.5"]
121
+ - tests-and-coverage-with-ruby:
122
+ matrix:
123
+ parameters:
124
+ ruby-version: ["2.5"]
125
+ - compatibility-with-ruby:
126
+ matrix:
127
+ parameters:
128
+ ruby-version: ["2.6", "2.7", "3.0"]
data/.codeclimate.yml CHANGED
@@ -7,7 +7,7 @@ checks:
7
7
  plugins:
8
8
  rubocop:
9
9
  enabled: true
10
- channel: rubocop-1-9
10
+ channel: rubocop-1-14
11
11
 
12
12
  reek:
13
13
  enabled: true
data/.reek.yml CHANGED
@@ -21,6 +21,8 @@ detectors:
21
21
  - DnsMock::ServerHelper#start_random_server
22
22
  - DnsMock::ServerHelper#stop_all_running_servers
23
23
  - DnsMock::Server::RecordsDictionaryBuilder#rdns_lookup_prefix
24
+ - DnsMock::ContextGeneratorHelper#random_port_number
25
+ - DnsMock::TestFramework::RSpec::Helper#dns_mock_server
24
26
 
25
27
  ControlParameter:
26
28
  exclude:
@@ -51,3 +53,7 @@ detectors:
51
53
  exclude:
52
54
  - DnsMock::Server#initialize
53
55
  - DnsMock#start_server
56
+
57
+ NilCheck:
58
+ exclude:
59
+ - DnsMock::Record::Builder::Mx#build
data/.rubocop.yml CHANGED
@@ -121,6 +121,12 @@ Style/HashExcept:
121
121
  Style/IfWithBooleanLiteralBranches:
122
122
  Enabled: true
123
123
 
124
+ Style/HashConversion:
125
+ Enabled: true
126
+
127
+ Style/StringChars:
128
+ Enabled: true
129
+
124
130
  Layout/LineLength:
125
131
  Max: 150
126
132
 
@@ -218,6 +224,9 @@ Lint/SymbolConversion:
218
224
  Lint/TripleQuotes:
219
225
  Enabled: true
220
226
 
227
+ Gemspec/DateAssignment:
228
+ Enabled: true
229
+
221
230
  Performance/AncestorsInclude:
222
231
  Enabled: true
223
232
 
@@ -257,6 +266,15 @@ Performance/MethodObjectAsBlock:
257
266
  Performance/Sum:
258
267
  Enabled: true
259
268
 
269
+ Performance/RedundantEqualityComparisonBlock:
270
+ Enabled: true
271
+
272
+ Performance/RedundantSplitRegexpArgument:
273
+ Enabled: true
274
+
275
+ Performance/MapCompact:
276
+ Enabled: true
277
+
260
278
  RSpec/ExampleLength:
261
279
  Enabled: false
262
280
 
data/CHANGELOG.md CHANGED
@@ -2,6 +2,99 @@
2
2
 
3
3
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
4
 
5
+ ## [1.2.3] - 2021-05-11
6
+
7
+ ### Changed
8
+
9
+ - Updated gem development dependencies
10
+ - Updated CircleCI config
11
+
12
+ ## [1.2.2] - 2021-05-06
13
+
14
+ ### Changed
15
+
16
+ - Updated gem development dependencies
17
+ - Updated rubocop/codeclimate config
18
+ - Updated ci config
19
+
20
+ ## [1.2.1] - 2021-03-23
21
+
22
+ ### Changed
23
+
24
+ - Updated gem development dependencies
25
+ - Updated rubocop/codeclimate config
26
+ - Updated gem documentation
27
+ - Updated tests
28
+
29
+ ## [1.2.0] - 2021-02-04
30
+
31
+ ### Ability to specify MX record priority
32
+
33
+ Added ability to specify custom priority of MX record if it needed. Now it impossible to define null or backup MX records. Please note, if you haven't specified a priority of MX record, it will be assigned automatically. MX records builder is assigning priority with step 10 from first item of defined MX records array.
34
+
35
+ ```ruby
36
+ records = {
37
+ 'example.com' => {
38
+ mx: %w[.:0 mx1.domain.com:10 mx2.domain.com:10 mx3.domain.com] # .:0 - null MX record
39
+ }
40
+ }
41
+
42
+ DnsMock.start_server(records: records)
43
+ ```
44
+
45
+ ```bash
46
+ dig @localhost -p 5300 MX example.com
47
+ ```
48
+
49
+ ```
50
+ ; <<>> DiG 9.10.6 <<>> @localhost -p 5300 MX example.com
51
+
52
+ ;; ANSWER SECTION:
53
+ example.com. 1 IN MX 0 .
54
+ example.com. 1 IN MX 10 mx1.domain.com.
55
+ example.com. 1 IN MX 10 mx2.domain.com.
56
+ example.com. 1 IN MX 40 mx3.domain.com.
57
+
58
+ ;; Query time: 0 msec
59
+ ;; SERVER: 127.0.0.1#5300(127.0.0.1)
60
+ ;; WHEN: Wed Feb 03 20:19:51 EET 2021
61
+ ;; MSG SIZE rcvd: 102
62
+ ```
63
+
64
+ ## [1.1.0] - 2021-02-01
65
+
66
+ ### RSpec native support
67
+
68
+ Added DnsMock helper which can simplify integration with RSpec.
69
+
70
+ ```ruby
71
+ # spec/support/config/dns_mock.rb
72
+ require 'dns_mock/test_framework/rspec'
73
+
74
+ RSpec.configure do |config|
75
+ config.include DnsMock::TestFramework::RSpec::Helper
76
+ end
77
+
78
+ # your awesome first_a_record_spec.rb
79
+ RSpec.describe FirstARecord do
80
+ subject(:service) do
81
+ described_class.call(
82
+ hostname,
83
+ dns_gateway_host: 'localhost',
84
+ dns_gateway_port: dns_mock_server.port
85
+ )
86
+ end
87
+
88
+ let(:hostname) { 'example.com' }
89
+ let(:first_a_record) { '1.2.3.4' }
90
+ let(:records) { { hostname => { a: [first_a_record] } } }
91
+
92
+ before { dns_mock_server.assign_mocks(records) }
93
+
94
+ it { is_expected.to eq(first_a_record) }
95
+ end
96
+ ```
97
+
5
98
  ## [1.0.0] - 2021-01-29
6
99
 
7
100
  ### Configurable record not found behaviour
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dns_mock (1.0.0)
4
+ dns_mock (1.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
- bundler-audit (0.7.0.1)
10
+ bundler-audit (0.8.0)
11
11
  bundler (>= 1.2.0, < 3)
12
- thor (>= 0.18, < 2)
12
+ thor (~> 1.0)
13
13
  byebug (11.1.3)
14
14
  childprocess (4.0.0)
15
15
  coderay (1.1.3)
@@ -19,12 +19,12 @@ GEM
19
19
  dnsruby (1.61.5)
20
20
  simpleidn (~> 0.1)
21
21
  docile (1.3.5)
22
- faker (2.15.1)
22
+ faker (2.17.0)
23
23
  i18n (>= 1.6, < 2)
24
- fasterer (0.8.3)
24
+ fasterer (0.9.0)
25
25
  colorize (~> 0.7)
26
26
  ruby_parser (>= 3.14.1)
27
- i18n (1.8.7)
27
+ i18n (1.8.10)
28
28
  concurrent-ruby (~> 1.0)
29
29
  iniparse (1.5.0)
30
30
  json (2.5.1)
@@ -34,7 +34,7 @@ GEM
34
34
  childprocess (>= 0.6.3, < 5)
35
35
  iniparse (~> 1.4)
36
36
  parallel (1.20.1)
37
- parser (3.0.0.0)
37
+ parser (3.0.1.1)
38
38
  ast (~> 2.4.1)
39
39
  pry (0.13.1)
40
40
  coderay (~> 1.1)
@@ -42,16 +42,16 @@ GEM
42
42
  pry-byebug (3.9.0)
43
43
  byebug (~> 11.0)
44
44
  pry (~> 0.13.0)
45
- psych (3.3.0)
45
+ psych (3.3.1)
46
46
  rainbow (3.0.0)
47
47
  rake (13.0.3)
48
- reek (6.0.3)
48
+ reek (6.0.4)
49
49
  kwalify (~> 0.7.0)
50
50
  parser (~> 3.0.0)
51
51
  psych (~> 3.1)
52
52
  rainbow (>= 2.0, < 4.0)
53
- regexp_parser (2.0.3)
54
- rexml (3.2.4)
53
+ regexp_parser (2.1.1)
54
+ rexml (3.2.5)
55
55
  rspec (3.10.0)
56
56
  rspec-core (~> 3.10.0)
57
57
  rspec-expectations (~> 3.10.0)
@@ -69,21 +69,21 @@ GEM
69
69
  diff-lcs (>= 1.2.0, < 2.0)
70
70
  rspec-support (~> 3.10.0)
71
71
  rspec-support (3.10.2)
72
- rubocop (1.9.0)
72
+ rubocop (1.14.0)
73
73
  parallel (~> 1.10)
74
74
  parser (>= 3.0.0.0)
75
75
  rainbow (>= 2.2.2, < 4.0)
76
76
  regexp_parser (>= 1.8, < 3.0)
77
77
  rexml
78
- rubocop-ast (>= 1.2.0, < 2.0)
78
+ rubocop-ast (>= 1.5.0, < 2.0)
79
79
  ruby-progressbar (~> 1.7)
80
80
  unicode-display_width (>= 1.4.0, < 3.0)
81
- rubocop-ast (1.4.1)
82
- parser (>= 2.7.1.5)
83
- rubocop-performance (1.9.2)
84
- rubocop (>= 0.90.0, < 2.0)
81
+ rubocop-ast (1.5.0)
82
+ parser (>= 3.0.1.1)
83
+ rubocop-performance (1.11.3)
84
+ rubocop (>= 1.7.0, < 2.0)
85
85
  rubocop-ast (>= 0.4.0)
86
- rubocop-rspec (2.1.0)
86
+ rubocop-rspec (2.3.0)
87
87
  rubocop (~> 1.0)
88
88
  rubocop-ast (>= 1.1.0)
89
89
  ruby-progressbar (1.11.0)
@@ -104,24 +104,24 @@ GEM
104
104
  unicode-display_width (2.0.0)
105
105
 
106
106
  PLATFORMS
107
- ruby
107
+ x86_64-darwin-19
108
108
 
109
109
  DEPENDENCIES
110
- bundler (~> 1.16)
111
- bundler-audit (~> 0.7.0.1)
110
+ bundler (~> 2.2, >= 2.2.17)
111
+ bundler-audit (~> 0.8.0)
112
112
  dns_mock!
113
- faker (~> 2.15, >= 2.15.1)
114
- fasterer (~> 0.8.3)
113
+ faker (~> 2.17)
114
+ fasterer (~> 0.9.0)
115
115
  overcommit (~> 0.57.0)
116
116
  pry-byebug (~> 3.9)
117
117
  rake (~> 13.0, >= 13.0.3)
118
- reek (~> 6.0, >= 6.0.3)
118
+ reek (~> 6.0, >= 6.0.4)
119
119
  rspec (~> 3.10)
120
120
  rspec-dns (~> 0.1.8)
121
- rubocop (~> 1.9)
122
- rubocop-performance (~> 1.9, >= 1.9.2)
123
- rubocop-rspec (~> 2.1)
121
+ rubocop (~> 1.14)
122
+ rubocop-performance (~> 1.11, >= 1.11.3)
123
+ rubocop-rspec (~> 2.3)
124
124
  simplecov (~> 0.17.1)
125
125
 
126
126
  BUNDLED WITH
127
- 1.16.6
127
+ 2.2.17
data/README.md CHANGED
@@ -16,6 +16,9 @@
16
16
  - [Requirements](#requirements)
17
17
  - [Installation](#installation)
18
18
  - [Usage](#usage)
19
+ - [RSpec](#rspec)
20
+ - [DnsMock RSpec helper](#dnsmock-rspec-helper)
21
+ - [DnsMock RSpec interface](#dnsmock-rspec-interface)
19
22
  - [Contributing](#contributing)
20
23
  - [License](#license)
21
24
  - [Code of Conduct](#code-of-conduct)
@@ -56,13 +59,13 @@ Or install it yourself as:
56
59
  ## Usage
57
60
 
58
61
  ```ruby
59
- # Example of mocked DNS records structure
62
+ # Example of mocked DNS records, please follow this data structure
60
63
  records = {
61
64
  'example.com' => {
62
65
  a: %w[1.1.1.1 2.2.2.2],
63
66
  aaaa: %w[2a00:1450:4001:81e::200e],
64
67
  ns: %w[ns1.domain.com ns2.domain.com],
65
- mx: %w[mx1.domain.com mx2.domain.com],
68
+ mx: %w[mx1.domain.com mx2.domain.com:50], # you can specify host(s) or host(s) with priority, use '.:0' for definition null MX record
66
69
  txt: %w[txt_record_1 txt_record_2],
67
70
  cname: 'some.domain.com',
68
71
  soa: [
@@ -110,6 +113,68 @@ DnsMock.running_servers # => [DnsMock::Server instance]
110
113
  DnsMock.stop_running_servers! # => true
111
114
  ```
112
115
 
116
+ ### RSpec
117
+
118
+ Require this either in your Gemfile or in RSpec's support scripts. So either:
119
+
120
+ ```ruby
121
+ # Gemfile
122
+ group :test do
123
+ gem 'rspec'
124
+ gem 'dns_mock', require: 'dns_mock/test_framework/rspec'
125
+ end
126
+ ```
127
+
128
+ or
129
+
130
+ ```ruby
131
+ # spec/support/config/dns_mock.rb
132
+ require 'dns_mock/test_framework/rspec'
133
+ ```
134
+
135
+ #### DnsMock RSpec helper
136
+
137
+ Just add `DnsMock::TestFramework::RSpec::Helper` if you wanna use shortcut `dns_mock_server` for DnsMock server instance into your `RSpec.describe` blocks:
138
+
139
+ ```ruby
140
+ # spec/support/config/dns_mock.rb
141
+ RSpec.configure do |config|
142
+ config.include DnsMock::TestFramework::RSpec::Helper
143
+ end
144
+ ```
145
+
146
+ ```ruby
147
+ # your awesome first_a_record_spec.rb
148
+ RSpec.describe FirstARecord do
149
+ subject(:service) do
150
+ described_class.call(
151
+ hostname,
152
+ dns_gateway_host: 'localhost',
153
+ dns_gateway_port: dns_mock_server.port
154
+ )
155
+ end
156
+
157
+ let(:hostname) { 'example.com' }
158
+ let(:first_a_record) { '1.2.3.4' }
159
+ let(:records) { { hostname => { a: [first_a_record] } } }
160
+
161
+ before { dns_mock_server.assign_mocks(records) }
162
+
163
+ it { is_expected.to eq(first_a_record) }
164
+ end
165
+ ```
166
+
167
+ #### DnsMock RSpec interface
168
+
169
+ If you won't use `DnsMock::TestFramework::RSpec::Helper` you can use `DnsMock::TestFramework::RSpec::Interface` directly instead:
170
+
171
+ ```ruby
172
+ DnsMock::TestFramework::RSpec::Interface.start_server # creates and runs DnsMock server instance
173
+ DnsMock::TestFramework::RSpec::Interface.stop_server! # stops current DnsMock server instance
174
+ DnsMock::TestFramework::RSpec::Interface.reset_mocks! # resets mocks in current DnsMock server instance
175
+ DnsMock::TestFramework::RSpec::Interface.clear_server! # stops and clears current DnsMock server instance
176
+ ```
177
+
113
178
  ## Contributing
114
179
 
115
180
  Bug reports and pull requests are welcome on GitHub at https://github.com/mocktools/ruby-dns-mock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. Please check the [open tikets](https://github.com/mocktools/ruby-dns-mock/issues). Be shure to follow Contributor Code of Conduct below and our [Contributing Guidelines](CONTRIBUTING.md).
data/dns_mock.gemspec CHANGED
@@ -31,18 +31,18 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ['lib']
33
33
 
34
- spec.add_development_dependency 'bundler', '~> 1.16'
35
- spec.add_development_dependency 'bundler-audit', '~> 0.7.0.1'
36
- spec.add_development_dependency 'faker', '~> 2.15', '>= 2.15.1'
37
- spec.add_development_dependency 'fasterer', '~> 0.8.3'
34
+ spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.17'
35
+ spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
36
+ spec.add_development_dependency 'faker', '~> 2.17'
37
+ spec.add_development_dependency 'fasterer', '~> 0.9.0'
38
38
  spec.add_development_dependency 'overcommit', '~> 0.57.0'
39
39
  spec.add_development_dependency 'pry-byebug', '~> 3.9'
40
40
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
41
- spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.3'
41
+ spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.4'
42
42
  spec.add_development_dependency 'rspec', '~> 3.10'
43
43
  spec.add_development_dependency 'rspec-dns', '~> 0.1.8'
44
- spec.add_development_dependency 'rubocop', '~> 1.9'
45
- spec.add_development_dependency 'rubocop-performance', '~> 1.9', '>= 1.9.2'
46
- spec.add_development_dependency 'rubocop-rspec', '~> 2.1'
44
+ spec.add_development_dependency 'rubocop', '~> 1.14'
45
+ spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.3'
46
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.3'
47
47
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
48
48
  end
@@ -4,18 +4,29 @@ module DnsMock
4
4
  module Record
5
5
  module Builder
6
6
  class Mx < DnsMock::Record::Builder::Base
7
+ include DnsMock::Error::Helper
8
+
9
+ MX_RECORD_REGEX_PATTERN = /\A(.+):(\d+)|(.+)\z/.freeze
7
10
  RECORD_PREFERENCE_STEP = 10
8
11
 
9
12
  def build
10
13
  records_data.map.with_index(1) do |record_data, record_preference|
14
+ record_data, custom_record_preference = parse_mx_record_data(record_data)
11
15
  target_factory.new(
12
16
  record_data: [
13
- record_preference * DnsMock::Record::Builder::Mx::RECORD_PREFERENCE_STEP,
17
+ custom_record_preference&.to_i || record_preference * DnsMock::Record::Builder::Mx::RECORD_PREFERENCE_STEP,
14
18
  record_data
15
19
  ]
16
20
  ).create
17
21
  end
18
22
  end
23
+
24
+ private
25
+
26
+ def parse_mx_record_data(record_data)
27
+ raise_record_context_type_error(:mx, record_data, ::String)
28
+ record_data.scan(DnsMock::Record::Builder::Mx::MX_RECORD_REGEX_PATTERN).flatten.compact
29
+ end
19
30
  end
20
31
  end
21
32
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/core'
4
+ require_relative '../../dns_mock'
5
+ require_relative './rspec/interface'
6
+ require_relative './rspec/helper'
7
+
8
+ RSpec.configure do |config|
9
+ config.before(:suite) { DnsMock::TestFramework::RSpec::Interface.start_server }
10
+ config.after(:suite) { DnsMock::TestFramework::RSpec::Interface.stop_server! }
11
+ config.after { DnsMock::TestFramework::RSpec::Interface.reset_mocks! }
12
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './interface'
4
+
5
+ module DnsMock
6
+ module TestFramework
7
+ module RSpec
8
+ module Helper
9
+ def dns_mock_server(**options)
10
+ DnsMock::TestFramework::RSpec::Interface.start_server(**options)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DnsMock
4
+ module TestFramework
5
+ module RSpec
6
+ module Interface
7
+ class << self
8
+ def start_server(**options)
9
+ @dns_mock_server ||= DnsMock.start_server(**options) # rubocop:disable Naming/MemoizedInstanceVariableName
10
+ end
11
+
12
+ def stop_server!
13
+ return unless dns_mock_server
14
+
15
+ dns_mock_server.stop!
16
+ end
17
+
18
+ def reset_mocks!
19
+ return unless dns_mock_server
20
+
21
+ dns_mock_server.reset_mocks!
22
+ end
23
+
24
+ def clear_server!
25
+ @dns_mock_server = nil
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :dns_mock_server
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DnsMock
4
- VERSION = '1.0.0'
4
+ VERSION = '1.2.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Trotsenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-29 00:00:00.000000000 Z
11
+ date: 2021-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,62 +16,62 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.2.17
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: '1.16'
29
+ version: '2.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.17
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: bundler-audit
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: 0.7.0.1
39
+ version: 0.8.0
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: 0.7.0.1
46
+ version: 0.8.0
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: faker
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '2.15'
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: 2.15.1
53
+ version: '2.17'
51
54
  type: :development
52
55
  prerelease: false
53
56
  version_requirements: !ruby/object:Gem::Requirement
54
57
  requirements:
55
58
  - - "~>"
56
59
  - !ruby/object:Gem::Version
57
- version: '2.15'
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: 2.15.1
60
+ version: '2.17'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: fasterer
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 0.8.3
67
+ version: 0.9.0
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 0.8.3
74
+ version: 0.9.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: overcommit
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +129,7 @@ dependencies:
129
129
  version: '6.0'
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: 6.0.3
132
+ version: 6.0.4
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
@@ -139,7 +139,7 @@ dependencies:
139
139
  version: '6.0'
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
- version: 6.0.3
142
+ version: 6.0.4
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: rspec
145
145
  requirement: !ruby/object:Gem::Requirement
@@ -174,48 +174,48 @@ dependencies:
174
174
  requirements:
175
175
  - - "~>"
176
176
  - !ruby/object:Gem::Version
177
- version: '1.9'
177
+ version: '1.14'
178
178
  type: :development
179
179
  prerelease: false
180
180
  version_requirements: !ruby/object:Gem::Requirement
181
181
  requirements:
182
182
  - - "~>"
183
183
  - !ruby/object:Gem::Version
184
- version: '1.9'
184
+ version: '1.14'
185
185
  - !ruby/object:Gem::Dependency
186
186
  name: rubocop-performance
187
187
  requirement: !ruby/object:Gem::Requirement
188
188
  requirements:
189
189
  - - "~>"
190
190
  - !ruby/object:Gem::Version
191
- version: '1.9'
191
+ version: '1.11'
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
- version: 1.9.2
194
+ version: 1.11.3
195
195
  type: :development
196
196
  prerelease: false
197
197
  version_requirements: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '1.9'
201
+ version: '1.11'
202
202
  - - ">="
203
203
  - !ruby/object:Gem::Version
204
- version: 1.9.2
204
+ version: 1.11.3
205
205
  - !ruby/object:Gem::Dependency
206
206
  name: rubocop-rspec
207
207
  requirement: !ruby/object:Gem::Requirement
208
208
  requirements:
209
209
  - - "~>"
210
210
  - !ruby/object:Gem::Version
211
- version: '2.1'
211
+ version: '2.3'
212
212
  type: :development
213
213
  prerelease: false
214
214
  version_requirements: !ruby/object:Gem::Requirement
215
215
  requirements:
216
216
  - - "~>"
217
217
  - !ruby/object:Gem::Version
218
- version: '2.1'
218
+ version: '2.3'
219
219
  - !ruby/object:Gem::Dependency
220
220
  name: simplecov
221
221
  requirement: !ruby/object:Gem::Requirement
@@ -298,6 +298,9 @@ files:
298
298
  - lib/dns_mock/server.rb
299
299
  - lib/dns_mock/server/random_available_port.rb
300
300
  - lib/dns_mock/server/records_dictionary_builder.rb
301
+ - lib/dns_mock/test_framework/rspec.rb
302
+ - lib/dns_mock/test_framework/rspec/helper.rb
303
+ - lib/dns_mock/test_framework/rspec/interface.rb
301
304
  - lib/dns_mock/version.rb
302
305
  homepage: https://github.com/mocktools/ruby-dns-mock
303
306
  licenses: