rspec-networking 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27e1529533844c6f359735dc609ecb1a937762787f2c609a147d4a30bdb700ee
4
- data.tar.gz: 9c6856542b1477181e7b5ee82c39525e5295ed145e1a6edeaadfbd8feac6b500
3
+ metadata.gz: c23ab357e131d559918e6f06633477b8b7a6db590f90a13ab8337b53a2d2f1d3
4
+ data.tar.gz: 3de02a615ac9a9f49af41e648de4bd8782d2d702b753e9d29c0b7f477e28c92b
5
5
  SHA512:
6
- metadata.gz: 0eb7ec667852a07380d2bc2344c04a175066b03ad86bfc5630f3b45f692555947e6ad02a505200fb73e76b0ff801214a684f19b2697baecf9bc52e941da5a326
7
- data.tar.gz: 3a2521fe2955a92542c82e322d0f82eb602f8967aaf208e814f303586fd6de72cb42680b8f6df59dd3fa77fedceda74ce3292e656922e012c9f96ba40275a68e
6
+ metadata.gz: a40ebea318ce0a503558b3e62bc26e907d1f2da926ccb3b90ba78c2a86922fa43aca0cfe072be5853cb194e13ce6687f232dc07d444bde3dcdc48f2061e67255
7
+ data.tar.gz: d6802ad3a46dda23b9a7908657ab4d822b1dd994d50225f5b0c6f8f0edc1afc188eead8ab18fc9e0b5cd8da334171449e41f4d6ddc36c7f5c59a47232436ae2e
data/CHANGELOG.md CHANGED
@@ -1,2 +1,7 @@
1
+ ### 0.1.0 (2024-08-31)
2
+ - ip address
3
+ - mac addresses
4
+ - manufacturers
5
+
1
6
  ### 0.0.1 (2024-08-30)
2
7
  init
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-networking (0.0.1)
4
+ rspec-networking (0.1.0)
5
5
  rspec-expectations (>= 3)
6
6
 
7
7
  GEM
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