RSpec::Networking
RSpec matchers for IP and MAC Addresses
Install
gem install rspec-networkingUsage
require "rspec/networking"
### match an IP address ###
expect(obj).to be_an_ip_address
# check version
expect(obj).to be_an_ip_address.v4
expect(obj).to be_an_ip_address.v6
# check for localhost
expect(obj).to be_an_ip_address.localhost
# compose with other matchers
expect(data).to include(addr: an_ip_address)
### match a MAC address ###
# 00:11:22:33:44:55, 00-11-22-33-44-55, 0011.2233.4455, or EUI-64
expect(obj).to be_a_mac_address
expect(obj).to be_a_mac_address.bits(48)
expect(obj).to be_a_mac_address.broadcast
expect(obj).to be_a_mac_address.multicast
expect(obj).to be_a_mac_address.unicast
# check manufacturer or specific device
expect(obj).to be_a_mac_address.from("xerox")
expect(obj).to be_a_mac_address.from("00:00:0C")
expect(obj).to be_a_mac_address.for(device)
# compose with other matchers
expect(data).to include(addr: a_mac_address)Resources
- https://en.wikipedia.org/wiki/IP_address
- https://en.wikipedia.org/wiki/MAC_address
- https://www.lifewire.com/introduction-to-mac-addresses-817937
Contributing
Yes please :)
- Fork it
- Create your feature branch (
git checkout -b my-feature) - Ensure the tests pass (
bundle exec rspec) - Commit your changes (
git commit -am 'awesome new feature') - Push your branch (
git push origin my-feature) - Create a Pull Request
Manufacturer OUIs come from the IEEE registry; refresh them with script/update_manufacturers.