Sha256: 487c76734a5426e41a97e033ad3e3717afe6409e75fa83f64884cf18bdc5a043
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
require 'spec_helper' describe MacAddressValidator do context "MAC address has valid format" do let(:klass) do Class.new do include ActiveModel::Validations attr_accessor :mac, :name validates :mac, mac_address: true end end subject { klass.new } # Valid formats it { should allow_value("08:00:2b:01:02:03").for(:mac) } it { should allow_value("08-00-2b-01-02-03").for(:mac) } it { should allow_value("08.00.2b.01.02.03").for(:mac) } it { should allow_value("08 00 2b 01 02 03").for(:mac) } it { should allow_value("08002b:010203").for(:mac) } it { should allow_value("08002b.010203").for(:mac) } it { should allow_value("08002b-010203").for(:mac) } it { should allow_value("0800.2b01.0203").for(:mac) } it { should allow_value("0800-2b01-0203").for(:mac) } it { should allow_value("0800 2b01 0203").for(:mac) } it { should allow_value("08002b010203").for(:mac) } # Mixed Separators it { should_not allow_value("08-00:2b:01:02:03").for(:mac) } it { should_not allow_value("08.00:2b:01:02:03").for(:mac) } it { should_not allow_value("08 00:2b:01:02:03").for(:mac) } it { should_not allow_value("0800-2b01:0203").for(:mac) } it { should_not allow_value("0800 2b01:0203").for(:mac) } # Too Short it { should_not allow_value("08:00:2b:01:02").for(:mac) } it { should_not allow_value("08-00-2b-01-02").for(:mac) } # Too Long it { should_not allow_value("08:00:2b:01:02:03:04").for(:mac) } # Non-Hex Characters it { should_not allow_value("qq:00:00:00:00:00").for(:mac) } it { should_not allow_value(' ').for(:mac) } it { should_not allow_value(nil).for(:mac) } it { should_not allow_value("invalid").for(:mac) } it { should ensure_valid_mac_address_format_of(:mac) } it { should_not ensure_valid_mac_address_format_of(:name) } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
flash_validators-1.0.0 | spec/lib/mac_address_validator_spec.rb |
flash_validators-0.0.1 | spec/lib/mac_address_validator_spec.rb |