Skip to content

Instantly share code, notes, and snippets.

@kalabiyau
Created February 16, 2017 13:48
Show Gist options
  • Save kalabiyau/c83f885021aa2d7b32a57773d4bd48cc to your computer and use it in GitHub Desktop.
Save kalabiyau/c83f885021aa2d7b32a57773d4bd48cc to your computer and use it in GitHub Desktop.
require 'ipaddr'
require 'test/unit'
class TC_MyTest < Test::Unit::TestCase
REGEX_UNDER_QUESTION = %r{172\.(?:[1][6-9]|[2][0-9]|[3][0-1])\.\d+\.\d+}
def setup
start = IPAddr.new('172.16.0.0')
finish = IPAddr.new('172.31.255.255')
@ip_range = (start..finish).map(&:to_s)
end
def test_green
assert_block 'Range is not covered' do
@ip_range.select{|x| !x[REGEX_UNDER_QUESTION]}.empty?
end
end
def test_red
assert_block 'Poke teh range!' do
@ip_range += %w{ 172.12.1.2 172.32.1.1 168.12.21.1 }
@ip_range.select{|x| !x[REGEX_UNDER_QUESTION]}.size.eql?(3)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment