dns_mock 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.reek.yml +2 -0
- data/CHANGELOG.md +34 -0
- data/Gemfile.lock +1 -1
- data/README.md +63 -0
- data/lib/dns_mock/test_framework/rspec.rb +12 -0
- data/lib/dns_mock/test_framework/rspec/helper.rb +15 -0
- data/lib/dns_mock/test_framework/rspec/interface.rb +35 -0
- data/lib/dns_mock/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5b0d9099a1f5c837df39abb203d6217f0216dd0669acc7a209ce86cb00c2651
|
4
|
+
data.tar.gz: db3089761cf77aae5e69af2fdd961f5a26fdaf21abd7383113f3c86512676169
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d14b6560b60a00c542db1930cbbfde077f75d9a89866543c2477817edb8951e4004df904930980ed2ce91815d7ca01e2d6d82fc25449d45347577dfe7ea464bc
|
7
|
+
data.tar.gz: 5a6fc8492af617c15229262a2faf6a4c5349504e40936f4be7954807db96d12f4954d9e667b9334aeb68fa8a2aeb11ae934049db52f8f08434f21010147edecc
|
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:
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,40 @@
|
|
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.1.0] - 2021-02-01
|
6
|
+
|
7
|
+
### RSpec native support
|
8
|
+
|
9
|
+
Added DnsMock helper which can simplify integration with RSpec.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# spec/support/config/dns_mock.rb
|
13
|
+
require 'dns_mock/test_framework/rspec'
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.include DnsMock::TestFramework::RSpec::Helper
|
17
|
+
end
|
18
|
+
|
19
|
+
# your awesome first_a_record_spec.rb
|
20
|
+
RSpec.describe FirstARecord do
|
21
|
+
subject(:service) do
|
22
|
+
described_class.call(
|
23
|
+
hostname,
|
24
|
+
dns_gateway_host: 'localhost',
|
25
|
+
dns_gateway_port: dns_mock_server.port
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:hostname) { 'example.com' }
|
30
|
+
let(:first_a_record) { '1.2.3.4' }
|
31
|
+
let(:records) { { hostname => { a: [first_a_record] } } }
|
32
|
+
|
33
|
+
before { dns_mock_server.assign_mocks(records) }
|
34
|
+
|
35
|
+
it { is_expected.to eq(first_a_record) }
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
5
39
|
## [1.0.0] - 2021-01-29
|
6
40
|
|
7
41
|
### Configurable record not found behaviour
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
- [Requirements](#requirements)
|
17
17
|
- [Installation](#installation)
|
18
18
|
- [Usage](#usage)
|
19
|
+
- [RSpec](#rspec)
|
19
20
|
- [Contributing](#contributing)
|
20
21
|
- [License](#license)
|
21
22
|
- [Code of Conduct](#code-of-conduct)
|
@@ -110,6 +111,68 @@ DnsMock.running_servers # => [DnsMock::Server instance]
|
|
110
111
|
DnsMock.stop_running_servers! # => true
|
111
112
|
```
|
112
113
|
|
114
|
+
### RSpec
|
115
|
+
|
116
|
+
Require this either in your Gemfile or in RSpec's support scripts. So either:
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
# Gemfile
|
120
|
+
group :test do
|
121
|
+
gem 'rspec'
|
122
|
+
gem 'dns_mock', require: 'dns_mock/test_framework/rspec'
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
or
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
# spec/support/config/dns_mock.rb
|
130
|
+
require 'dns_mock/test_framework/rspec'
|
131
|
+
```
|
132
|
+
|
133
|
+
#### DnsMock RSpec helper
|
134
|
+
|
135
|
+
Just add `DnsMock::TestFramework::RSpec::Helper` if you wanna have shortcut for DnsMock server instance into your RSpec.describe blocks:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
# spec/support/config/dns_mock.rb
|
139
|
+
RSpec.configure do |config|
|
140
|
+
config.include DnsMock::TestFramework::RSpec::Helper
|
141
|
+
end
|
142
|
+
```
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
# your awesome first_a_record_spec.rb
|
146
|
+
RSpec.describe FirstARecord do
|
147
|
+
subject(:service) do
|
148
|
+
described_class.call(
|
149
|
+
hostname,
|
150
|
+
dns_gateway_host: 'localhost',
|
151
|
+
dns_gateway_port: dns_mock_server.port
|
152
|
+
)
|
153
|
+
end
|
154
|
+
|
155
|
+
let(:hostname) { 'example.com' }
|
156
|
+
let(:first_a_record) { '1.2.3.4' }
|
157
|
+
let(:records) { { hostname => { a: [first_a_record] } } }
|
158
|
+
|
159
|
+
before { dns_mock_server.assign_mocks(records) }
|
160
|
+
|
161
|
+
it { is_expected.to eq(first_a_record) }
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
#### DnsMock RSpec interface
|
166
|
+
|
167
|
+
If you won't use `DnsMock::TestFramework::RSpec::Helper` you can use `DnsMock::TestFramework::RSpec::Interface` directly instead:
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
DnsMock::TestFramework::RSpec::Interface.start_server # creates and runs DnsMock server instance
|
171
|
+
DnsMock::TestFramework::RSpec::Interface.stop_server! # stops current DnsMock server instance
|
172
|
+
DnsMock::TestFramework::RSpec::Interface.reset_mocks! # resets mocks in current DnsMock server instance
|
173
|
+
DnsMock::TestFramework::RSpec::Interface.clear_server! # stops and clears current DnsMock server instance
|
174
|
+
```
|
175
|
+
|
113
176
|
## Contributing
|
114
177
|
|
115
178
|
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).
|
@@ -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
|
data/lib/dns_mock/version.rb
CHANGED
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.
|
4
|
+
version: 1.1.0
|
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
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -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:
|