Add specs for regexp filters

This commit is contained in:
Markus Schirp 2013-09-07 19:16:21 +02:00
parent 7b0f5d78ff
commit 5f17145d17
2 changed files with 68 additions and 6 deletions

View file

@ -20,6 +20,28 @@ module Mutant
object.public_send(attribute_name)
end
# Regexp based attribute filter
class Regexp < self
# Test for match
#
# @param [Object] object
#
# @return [true]
# if attribute value matches expectation
#
# @return [false]
# otherwise
#
# @api private
#
def match?(object)
!!(expectation =~ value(object))
end
end # Regexp
# Equality based attribute filter
class Equality < self
# Test for match
@ -35,7 +57,7 @@ module Mutant
# @api private
#
def match?(object)
value(object).eql?(value)
expectation.eql?(value(object))
end
PATTERN = /\A(code):([a-f0-9]{1,6})\z/.freeze
@ -58,7 +80,7 @@ module Mutant
new(match[1].to_sym, match[2])
end
end # Code
end # Equality
end # Attribute
end # Filter
end # Mutant

View file

@ -12,6 +12,8 @@ filter_helpers = proc do
end
end
end
subject { object.match?(item) }
end
describe Mutant::Filter::Whitelist do
@ -21,8 +23,6 @@ describe Mutant::Filter::Whitelist do
describe '#match?' do
subject { object.match?(item) }
context 'with empty whitelist' do
let(:whitelist) { [] }
@ -57,8 +57,6 @@ describe Mutant::Filter::Blacklist do
describe '#match?' do
subject { object.match?(item) }
context 'with empty whitelist' do
let(:whitelist) { [] }
@ -90,4 +88,46 @@ describe Mutant::Filter::Attribute::Equality do
instance_eval(&filter_helpers)
let(:object) { described_class.new(attribute_name, expected_value) }
let(:item) { double('Item', attribute_name => actual_value) }
let(:attribute_name) { :foo }
let(:expected_value) { 'value' }
describe '#match?' do
context 'not matching' do
let(:actual_value) { 'other-value' }
it { should be(false) }
end
context 'matching' do
let(:actual_value) { 'value' }
it { should be(true) }
end
end
end
describe Mutant::Filter::Attribute::Regexp do
instance_eval(&filter_helpers)
let(:object) { described_class.new(attribute_name, expectation) }
let(:item) { double('Item', attribute_name => actual_value) }
let(:attribute_name) { :foo }
let(:expectation) { /\Avalue\z/ }
describe '#match?' do
context 'not matching' do
let(:actual_value) { 'other-value' }
it { should be(false) }
end
context 'matching' do
let(:actual_value) { 'value' }
it { should be(true) }
end
end
end