rspec-networking 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +41 -0
- data/lib/rspec/networking/ip_address.rb +54 -0
- data/lib/rspec/networking/mac_address/apple.txt +1271 -0
- data/lib/rspec/networking/mac_address/eero.txt +68 -0
- data/lib/rspec/networking/mac_address/google.txt +82 -0
- data/lib/rspec/networking/mac_address/microsoft.txt +100 -0
- data/lib/rspec/networking/mac_address/nokia.txt +324 -0
- data/lib/rspec/networking/mac_address/oracle.txt +11 -0
- data/lib/rspec/networking/mac_address/sony.txt +122 -0
- data/lib/rspec/networking/mac_address/texas_instruments.txt +335 -0
- data/lib/rspec/networking/mac_address/toshiba.txt +25 -0
- data/lib/rspec/networking/mac_address/xerox.txt +14 -0
- data/lib/rspec/networking/mac_address/xiaomi.txt +262 -0
- data/lib/rspec/networking/mac_address/zyxel.txt +55 -0
- data/lib/rspec/networking/mac_address.rb +108 -4
- data/lib/rspec/networking/mac_address_manufacturers.rb +19 -0
- data/lib/rspec/networking/version.rb +1 -1
- metadata +15 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c23ab357e131d559918e6f06633477b8b7a6db590f90a13ab8337b53a2d2f1d3
|
4
|
+
data.tar.gz: 3de02a615ac9a9f49af41e648de4bd8782d2d702b753e9d29c0b7f477e28c92b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a40ebea318ce0a503558b3e62bc26e907d1f2da926ccb3b90ba78c2a86922fa43aca0cfe072be5853cb194e13ce6687f232dc07d444bde3dcdc48f2061e67255
|
7
|
+
data.tar.gz: d6802ad3a46dda23b9a7908657ab4d822b1dd994d50225f5b0c6f8f0edc1afc188eead8ab18fc9e0b5cd8da334171449e41f4d6ddc36c7f5c59a47232436ae2e
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,11 +6,52 @@ RSpec::Networking
|
|
6
6
|
RSpec matchers for IP and MAC Addresses
|
7
7
|
|
8
8
|
|
9
|
+
### Install
|
10
|
+
```bash
|
11
|
+
gem install rspec-networking
|
12
|
+
```
|
13
|
+
|
14
|
+
|
15
|
+
### Usage
|
16
|
+
|
9
17
|
```ruby
|
10
18
|
require "rspec/networking"
|
19
|
+
|
20
|
+
expect(obj).to be_an_ip_address
|
21
|
+
|
22
|
+
# check version
|
23
|
+
expect(obj).to be_an_ip_address.v4
|
24
|
+
|
25
|
+
# check for localhost
|
26
|
+
expect(obj).to be_an_ip_address.localhost
|
27
|
+
|
28
|
+
# compose with other matchers
|
29
|
+
expect(data).to include(addr: an_ip_address)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
### match a MAC address ###
|
34
|
+
expect(obj).to be_a_mac_address
|
35
|
+
|
36
|
+
expect(obj).to be_a_mac_address.broadcast
|
37
|
+
expect(obj).to be_a_mac_address.multicast
|
38
|
+
expect(obj).to be_a_mac_address.unicast
|
39
|
+
|
40
|
+
# check manufacturer or specific device
|
41
|
+
expect(obj).to be_a_mac_address.from("xerox")
|
42
|
+
expect(obj).to be_a_mac_address.for(device)
|
43
|
+
|
44
|
+
# compose with other matchers
|
45
|
+
expect(data).to include(addr: a_mac_address)
|
11
46
|
```
|
12
47
|
|
13
48
|
|
49
|
+
### Resources
|
50
|
+
- https://en.wikipedia.org/wiki/IP_address
|
51
|
+
- https://en.wikipedia.org/wiki/MAC_address
|
52
|
+
- https://www.lifewire.com/introduction-to-mac-addresses-817937
|
53
|
+
|
54
|
+
|
14
55
|
----
|
15
56
|
## Contributing
|
16
57
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "ipaddr"
|
2
|
+
|
3
|
+
RSpec::Matchers.define :be_an_ip_address do
|
4
|
+
chain :v4 do
|
5
|
+
@version = 4
|
6
|
+
end
|
7
|
+
|
8
|
+
chain :v6 do
|
9
|
+
@version = 6
|
10
|
+
end
|
11
|
+
|
12
|
+
chain :localhost do
|
13
|
+
@localhost = true
|
14
|
+
end
|
15
|
+
|
16
|
+
match do |actual|
|
17
|
+
@actual = actual
|
18
|
+
|
19
|
+
return false unless actual.is_a?(String) || actual.is_a?(IPAddr)
|
20
|
+
|
21
|
+
addr = actual.is_a?(IPAddr) ? actual : IPAddr.new(actual)
|
22
|
+
|
23
|
+
if @version
|
24
|
+
return false unless @version == 4 ? addr.ipv4? : addr.ipv6?
|
25
|
+
end
|
26
|
+
|
27
|
+
if @localhost
|
28
|
+
return false unless addr.loopback?
|
29
|
+
end
|
30
|
+
|
31
|
+
true
|
32
|
+
rescue IPAddr::InvalidAddressError
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
description do
|
37
|
+
if @version
|
38
|
+
addr = @localhost ? "localhost " : "address"
|
39
|
+
"an IPv#{@version} #{addr}"
|
40
|
+
else
|
41
|
+
@localhost ? "a localhost" : "an IP address"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
failure_message do
|
46
|
+
"expected '#{@actual}' to be #{description}"
|
47
|
+
end
|
48
|
+
|
49
|
+
failure_message_when_negated do
|
50
|
+
"expected '#{@actual}' not to be #{description}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
RSpec::Matchers.alias_matcher :an_ip_address, :be_an_ip_address
|