rspec-dns 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWZlNDcxN2JiNWZiMmY4OWVmZDdjZDJmMmNiMGQwYmQ2OTI5OTAwMA==
4
+ YWZhYzZhZTc5ZjFiZWY2MzRhMjIwMWMyYzhhNjQ2N2M3YWQxYWEyZg==
5
5
  data.tar.gz: !binary |-
6
- YWUyZWRmMTQwOWU4ZDVhYjM3YTIzMTQ5ZWY2NGQwMTU0ODYzNDMzZg==
6
+ YTNiNTQyZWU5ZTBmM2ZhYTMzMmI4MjFhMjAyNGFmMWFhYWE3ZGQ0MQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ODk0NGEwYThiMThmNGQyY2ZiYWE4NmY5MWViMWU1NzM4ZDM5YThjM2JlM2U0
10
- MzU3MjcyYThjODNkNGQxNDgxMGQyZDc2YTA5ZWQ3NGMzYmNmZGEzOGQ0YjQ2
11
- ZDJlNjdiNjc4NmJmNWQ4ODhiZjllMjE4MjU0MDMxYmE4NGFjNmU=
9
+ ZTAyZWQ5NGM5YWRhNmI3YzIxOWNiZGUxMzcxNWE5ZTI1ZjY1YjVkYjY5YjI2
10
+ YjBhMTEzMWQ2OGEzYWYxYTE4MGJjOTFlYzRiNWQ0ZjJkODcyZmUzZmNhZjgw
11
+ YWFiZWE1MzQzMTk0Mzk0OTMyZDk3ZjcyOTI4YmZlNjJkNjYwN2I=
12
12
  data.tar.gz: !binary |-
13
- ZDRjNTFhNTY1ZTRkNWNkYzViMWU1YjY5NGJmZDIwNjdkODgxMjQ1OWJjNGM2
14
- NjliZmI0MzAzYTc0NDgwMGRhMjE0OTU1Y2M1NzlkYThmYWE3OGE0ZDkxY2I4
15
- ZjQyMjc3OTAyMzJkMTUyYjk1Y2MwNjNmYTVjMjIyZDY4Mzk2OWY=
13
+ NmEzYmE0ZjdiYmJhODJlZjllYjhjMjVkZGQ3MjMxZDc0Njc1NDE5ZjAxZjZj
14
+ YTdiNDE3ZjQzMTQxZjc1ODhlMjZlZTgzMTQyNTZjNTY1Y2M1M2NmYTE4ZTJm
15
+ MDIwZTIzOTRmZWUxNzE0ZmYyNzY0YjA5ZDg2ZGJkZjA1Y2YyZDE=
data/README.md CHANGED
@@ -35,7 +35,7 @@ Then, create a spec like this:
35
35
  require 'spec_helper'
36
36
 
37
37
  describe 'www.example.com' do
38
- it { should have_dns.with_type('TXT').and_ttl(300).and_data('a=b') }
38
+ it { is_expected.to have_dns.with_type('TXT').and_ttl(300).and_data('a=b') }
39
39
  end
40
40
  ```
41
41
 
@@ -46,8 +46,9 @@ require 'spec_helper'
46
46
 
47
47
  describe 'DNS tests' do
48
48
  it 'passes some tests' do
49
- 'www.example.com'.should have_dns.with_type('TXT').and_ttl(300).and_data('a=b')
50
- 'www.example.com'.should have_dns.with_type('A').and_ttl(300).and_address('1.2.3.4')
49
+ expect('www.example.com').to have_dns.with_type('TXT').and_ttl(300).and_data('a=b')
50
+ expect('www.example.com').to have_dns.with_type('A').and_ttl(300).and_address('192.0.2.4')
51
+ expect('192.0.2.4').to have_dns.with_type('PTR').and_domainname('www.example.com')
51
52
  end
52
53
  end
53
54
  ```
@@ -59,20 +60,25 @@ Currently the following chaining methods are supported:
59
60
  - at\_least
60
61
  - in\_authority
61
62
  - refuse\_request
63
+ - config
62
64
 
63
65
  Here's some usage examples:
64
66
 
65
67
  ```ruby
66
68
  it 'checks if recursion is disabled' do
67
- 'google.com'.should have_dns.refuse_request
69
+ expect('google.com').to have_dns.refuse_request
68
70
  end
69
71
 
70
72
  it 'checks if gslb subdomain is delegated to dynect' do
71
- 'gslb.example.com'.should have_dns.in_authority.with_type('NS').and_name(/dynect/).at_least(3)
73
+ expect('gslb.example.com').to have_dns.in_authority.with_type('NS').and_name(/dynect/).at_least(3)
72
74
  end
73
75
 
74
76
  it 'checks number of hosts in round robin' do
75
- 'example.com'.should have_dns.with_type('A').at_least(3)
77
+ expect('example.com').to have_dns.with_type('A').at_least(3)
78
+ end
79
+
80
+ it 'check with configuration' do
81
+ expect('example.com').to have_dns.with_type('A').config(nameserver: '192.0.2.4')
76
82
  end
77
83
  ```
78
84
 
@@ -109,7 +115,7 @@ Depending on the type of record, the following attributes may be available:
109
115
  If you try checking an attribute on a record that is non-existent (like checking the `rmailbx` on an `A` record), you'll get an error like this:
110
116
 
111
117
  ```text
112
- Failure/Error: it { should have_dns.with_type('TXT').and_ftl(300).and_data('a=b') }
118
+ Failure/Error: it { is_expected.to have_dns.with_type('TXT').and_ftl(300).and_data('a=b') }
113
119
  got 1 exception(s): undefined method `rmailbx' for #<Dnsruby::RR::IN::A:0x007f66a0339b00>
114
120
  ```
115
121
 
@@ -117,7 +123,7 @@ For this reason, you should always check the `type` attribute first in your chai
117
123
 
118
124
  Configuring
119
125
  -----------
120
- All configurations must be in your project root at `config/dns.yml`. This YAML file directly corresponds to the Resolv DNS initializer.
126
+ All configurations can be in your project root at `config/dns.yml`. This YAML file directly corresponds to the Resolv DNS initializer.
121
127
 
122
128
  For example, to directly query your DNS servers (necessary for correct TTL tests), create a `config/dns.yml` file like this:
123
129
 
@@ -128,8 +134,9 @@ nameserver:
128
134
  ```
129
135
 
130
136
  If this file is missing Resolv will use the settings in /etc/resolv.conf.
137
+ You can also configure with `config` chain.
131
138
 
132
- The full list of configuration options can be found on the [Dnsruby docs](http://dnsruby.rubyforge.org/classes/Dnsruby/Config.html).
139
+ The full list of configuration options can be found on the [Dnsruby docs](http://www.ruby-doc.org/gems/docs/d/Dnsruby-1.0/Dnsruby/Config.html).
133
140
 
134
141
  ### Configuring connection timeout
135
142
 
@@ -161,11 +168,13 @@ License & Authors
161
168
  - Seth Vargo (sethvargo@gmail.com)
162
169
  - Johannes Russek (jrussek@spotify.com)
163
170
  - Alexey Lapitsky (lex@realisticgroup.com)
171
+ - Hiroshi OTA (otahi.pub@gmail.com)
164
172
 
165
173
  ```text
166
174
  Copyright 2012-2013 Seth Vargo
167
175
  Copyright 2012-2013 CustomInk, LLC
168
176
  Copyright 2013-2014 Spotify AB
177
+ Copyright 2013-2014 Hiroshi OTA
169
178
 
170
179
  Licensed under the Apache License, Version 2.0 (the "License");
171
180
  you may not use this file except in compliance with the License.
data/lib/rspec-dns.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'erb'
2
2
  require 'dnsruby'
3
+ require 'ipaddr'
3
4
  require 'rspec/expectations'
4
5
 
5
6
  require 'rspec-dns/have_dns'
@@ -80,6 +80,10 @@ RSpec::Matchers.define :have_dns do
80
80
  @refuse_request = true
81
81
  end
82
82
 
83
+ chain :config do |c|
84
+ @config = c
85
+ end
86
+
83
87
  def method_missing(m, *args, &block)
84
88
  if m.to_s =~ /(and\_with|and|with)?\_(.*)$/
85
89
  _options[$2.to_sym] = args.first
@@ -129,7 +133,11 @@ RSpec::Matchers.define :have_dns do
129
133
  Timeout::timeout(query_timeout + 0.2) do
130
134
  resolver = Dnsruby::Resolver.new(config)
131
135
  resolver.query_timeout = query_timeout
132
- resolver.query(@dns, Dnsruby::Types.ANY)
136
+ if (IPAddr.new(@dns) rescue nil) # Check if IPAddr(v4,v6)
137
+ resolver.query(@dns, Dnsruby::Types.PTR)
138
+ else
139
+ resolver.query(@dns, Dnsruby::Types.ANY)
140
+ end
133
141
  end
134
142
  rescue Exception => e
135
143
  if Dnsruby::NXDomain === e
data/rspec-dns.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
- s.version = '0.1.2'
2
+ s.version = '0.1.3'
3
3
  s.name = 'rspec-dns'
4
- s.authors = ['Seth Vargo', 'Alexey Lapitsky', 'Johannes Russek']
4
+ s.authors = ['Seth Vargo', 'Alexey Lapitsky', 'Johannes Russek', 'Hiroshi OTA']
5
5
  s.email = 'alexey@spotify.com'
6
6
  s.description = 'Easily test your DNS entries with RSpec'
7
7
  s.summary = 'rspec-dns provides an easy-to-use DSL for testing your DNS records are responding as they should.'
@@ -3,11 +3,11 @@ require 'spec_helper'
3
3
  def stub_records(strings)
4
4
  records = strings.map { |s| Dnsruby::RR.new_from_string(s) }
5
5
  resolver = Dnsruby::Resolver.new
6
- Dnsruby::Resolver.stub(:new) do
6
+ allow(Dnsruby::Resolver).to receive(:new) do
7
7
  yield if block_given?
8
8
  resolver
9
9
  end
10
- resolver.stub_chain(:query, :answer).and_return(records)
10
+ allow(resolver).to receive_message_chain(:query, :answer).and_return(records)
11
11
  end
12
12
 
13
13
  describe 'rspec-dns matchers' do
@@ -15,68 +15,68 @@ describe 'rspec-dns matchers' do
15
15
  describe '#have_dns' do
16
16
  context 'with a sigle record' do
17
17
  it 'can evalutate an A record' do
18
- stub_records(['example.com 86400 A 192.168.100.100'])
18
+ stub_records(['example.com 86400 A 192.0.2.4'])
19
19
 
20
- 'example.com'.should have_dns.with_type('A')
21
- 'example.com'.should_not have_dns.with_type('TXT')
22
- 'example.com'.should have_dns.with_type('A').and_address('192.168.100.100')
20
+ expect('example.com').to have_dns.with_type('A')
21
+ expect('example.com').to_not have_dns.with_type('TXT')
22
+ expect('example.com').to have_dns.with_type('A').and_address('192.0.2.4')
23
23
  end
24
24
 
25
25
  it 'can evalutate a AAAA record' do
26
- stub_records(['example.com 86400 AAAA 2001:0002:6c::430'])
26
+ stub_records(['example.com 86400 AAAA 2001:DB8:6c::430'])
27
27
 
28
- 'example.com'.should have_dns.with_type('AAAA')
29
- 'example.com'.should_not have_dns.with_type('A')
30
- 'example.com'.should have_dns.with_type('AAAA')
31
- .and_address('2001:2:6C::430')
28
+ expect('example.com').to have_dns.with_type('AAAA')
29
+ expect('example.com').to_not have_dns.with_type('A')
30
+ expect('example.com').to have_dns.with_type('AAAA')
31
+ .and_address('2001:DB8:6C::430')
32
32
  end
33
33
 
34
34
  it 'can evalutate a CNAME record' do
35
35
  stub_records(['www.example.com 300 IN CNAME example.com'])
36
36
 
37
- 'example.com'.should have_dns.with_type('CNAME')
38
- 'example.com'.should_not have_dns.with_type('AAAA')
39
- 'example.com'.should have_dns.with_type('CNAME').and_name('www.example.com')
37
+ expect('example.com').to have_dns.with_type('CNAME')
38
+ expect('example.com').to_not have_dns.with_type('AAAA')
39
+ expect('example.com').to have_dns.with_type('CNAME').and_name('www.example.com')
40
40
  end
41
41
 
42
42
  it 'can evalutate an MX record' do
43
43
  stub_records(['example.com. 7200 MX 40 mail.example.com.'])
44
44
 
45
- 'example.com'.should have_dns.with_type('MX')
46
- 'example.com'.should_not have_dns.with_type('CNAME')
47
- 'example.com'.should have_dns.with_type('MX').and_preference(40)
48
- 'example.com'.should have_dns.with_type('MX')
45
+ expect('example.com').to have_dns.with_type('MX')
46
+ expect('example.com').to_not have_dns.with_type('CNAME')
47
+ expect('example.com').to have_dns.with_type('MX').and_preference(40)
48
+ expect('example.com').to have_dns.with_type('MX')
49
49
  .and_preference(40).and_exchange('mail.example.com')
50
- 'example.com'.should_not have_dns.with_type('MX')
50
+ expect('example.com').to_not have_dns.with_type('MX')
51
51
  .and_preference(30).and_exchange('mail.example.com')
52
- 'example.com'.should_not have_dns.with_type('MX')
52
+ expect('example.com').to_not have_dns.with_type('MX')
53
53
  .and_preference(40).and_exchange('example.com')
54
54
  end
55
55
 
56
56
  it 'can evalutate an NS record' do
57
57
  stub_records(['sub.example.com. 300 IN NS ns.sub.example.com.'])
58
58
 
59
- 'example.com'.should have_dns.with_type('NS')
60
- 'example.com'.should_not have_dns.with_type('MX')
61
- 'example.com'.should have_dns.with_type('NS').and_domainname('ns.sub.example.com')
62
- 'example.com'.should_not have_dns.with_type('NS').and_domainname('sub.example.com')
59
+ expect('example.com').to have_dns.with_type('NS')
60
+ expect('example.com').to_not have_dns.with_type('MX')
61
+ expect('example.com').to have_dns.with_type('NS').and_domainname('ns.sub.example.com')
62
+ expect('example.com').to_not have_dns.with_type('NS').and_domainname('sub.example.com')
63
63
  end
64
64
 
65
65
  it 'can evalutate a PTR record' do
66
66
  stub_records(['ptrs.example.com. 300 IN PTR ptr.example.com.'])
67
67
 
68
- '192.168.100.100'.should have_dns.with_type('PTR')
69
- '192.168.100.100'.should_not have_dns.with_type('MX')
70
- '192.168.100.100'.should have_dns.with_type('PTR').and_domainname('ptr.example.com')
71
- '192.168.100.100'.should_not have_dns.with_type('PTR').and_domainname('ptrs.example.com')
68
+ expect('192.168.100.100').to have_dns.with_type('PTR')
69
+ expect('192.168.100.100').to_not have_dns.with_type('MX')
70
+ expect('192.168.100.100').to have_dns.with_type('PTR').and_domainname('ptr.example.com')
71
+ expect('192.168.100.100').to_not have_dns.with_type('PTR').and_domainname('ptrs.example.com')
72
72
  end
73
73
 
74
74
  it 'can evalutate an SOA record' do
75
75
  stub_records(['example.com 210 IN SOA ns.example.com a.example.com. 2014030712 60 25 3628800 900'])
76
76
 
77
- 'example.com'.should have_dns.with_type('SOA')
78
- 'example.com'.should_not have_dns.with_type('PTR')
79
- 'example.com'.should have_dns.with_type('SOA')
77
+ expect('example.com').to have_dns.with_type('SOA')
78
+ expect('example.com').to_not have_dns.with_type('PTR')
79
+ expect('example.com').to have_dns.with_type('SOA')
80
80
  .and_mname('ns.example.com')
81
81
  .and_rname('a.example.com')
82
82
  .and_serial('2014030712')
@@ -84,34 +84,42 @@ describe 'rspec-dns matchers' do
84
84
  .and_retry(25)
85
85
  .and_expire(3628800)
86
86
  .and_minimum(900)
87
- 'example.com'.should_not have_dns.with_type('SOA')
87
+ expect('example.com').to_not have_dns.with_type('SOA')
88
88
  .and_mname('nstest.example.com')
89
89
  end
90
90
 
91
91
  it 'can evalutate a TXT record' do
92
92
  stub_records(['example.com. 300 IN TXT "v=spf1 a:example.com ~all"'])
93
93
 
94
- 'example.com'.should have_dns.with_type('TXT')
95
- 'example.com'.should_not have_dns.with_type('SOA')
96
- 'example.com'.should have_dns.with_type('TXT').and_data('v=spf1 a:example.com ~all')
97
- 'example.com'.should_not have_dns.with_type('TXT').and_data('v=spf2 a:example.com ~all')
94
+ expect('example.com').to have_dns.with_type('TXT')
95
+ expect('example.com').to_not have_dns.with_type('SOA')
96
+ expect('example.com').to have_dns.with_type('TXT').and_data('v=spf1 a:example.com ~all')
97
+ expect('example.com').to_not have_dns.with_type('TXT').and_data('v=spf2 a:example.com ~all')
98
+ end
99
+ end
100
+
101
+ context 'with config chain' do
102
+ it 'should accept config chain' do
103
+ stub_records(['example.com 86400 A 192.0.2.1'])
104
+ expect('example.com').to have_dns.with_type('A')
105
+ .config(nameserver: '192.0.2.4')
98
106
  end
99
107
  end
100
108
 
101
109
  context 'with changable connection timeout' do
102
- it 'should timeout within 3 seconds in default' do
110
+ it 'is_expected.to timeout within 3 seconds in default' do
103
111
  stub_records(['example.com 86400 A 192.168.100.100']) do
104
112
  sleep 3
105
113
  end
106
- 'example.com'.should_not have_dns.with_type('A')
114
+ expect('example.com').to_not have_dns.with_type('A')
107
115
  end
108
116
 
109
- it 'should not timeout within 3 seconds when timeout is 5' do
117
+ it 'is_expected.to not timeout within 3 seconds when timeout is 5' do
110
118
  RSpec.configuration.rspec_dns_connection_timeout = 5
111
119
  stub_records(['example.com 86400 A 192.168.100.100']) do
112
120
  sleep 3
113
121
  end
114
- 'example.com'.should have_dns.with_type('A')
122
+ expect('example.com').to have_dns.with_type('A')
115
123
  end
116
124
  end
117
125
  end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-dns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
8
8
  - Alexey Lapitsky
9
9
  - Johannes Russek
10
+ - Hiroshi OTA
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2014-06-24 00:00:00.000000000 Z
14
+ date: 2014-10-19 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: rake
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  version: '0'
93
94
  requirements: []
94
95
  rubyforge_project:
95
- rubygems_version: 2.0.3
96
+ rubygems_version: 2.0.14
96
97
  signing_key:
97
98
  specification_version: 4
98
99
  summary: rspec-dns provides an easy-to-use DSL for testing your DNS records are responding