2013-09-09 01:37:07 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2013-09-07 12:57:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
filter_helpers = proc do
|
2013-09-08 16:12:23 -04:00
|
|
|
let(:input_a) { double('Input A', foo: 'bar') }
|
|
|
|
let(:input_b) { double('Input B', foo: 'baz') }
|
2013-09-07 12:57:06 -04:00
|
|
|
|
|
|
|
let(:filter_a) do
|
2013-09-07 17:12:03 -04:00
|
|
|
input_a = self.input_a
|
2013-09-07 12:57:06 -04:00
|
|
|
Module.new do
|
2013-09-07 17:12:03 -04:00
|
|
|
define_singleton_method(:match?) do |input|
|
|
|
|
input == input_a
|
2013-09-07 12:57:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-09-07 13:16:21 -04:00
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
subject { object.match?(input) }
|
2013-09-07 12:57:06 -04:00
|
|
|
end
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
describe Mutant::Predicate::Whitelist do
|
2013-09-07 12:57:06 -04:00
|
|
|
instance_eval(&filter_helpers)
|
|
|
|
|
|
|
|
let(:object) { described_class.new(whitelist) }
|
|
|
|
|
|
|
|
describe '#match?' do
|
|
|
|
|
|
|
|
context 'with empty whitelist' do
|
|
|
|
let(:whitelist) { [] }
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
it 'accepts all inputs' do
|
|
|
|
expect(object.match?(input_a)).to be(false)
|
|
|
|
expect(object.match?(input_b)).to be(false)
|
2013-09-07 12:57:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with non empty whitelist' do
|
|
|
|
let(:whitelist) { [filter_a] }
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
context 'with whitelisted input' do
|
|
|
|
let(:input) { input_a }
|
2013-09-07 12:57:06 -04:00
|
|
|
|
|
|
|
it { should be(true) }
|
|
|
|
end
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
context 'with non whitelisted input' do
|
|
|
|
let(:input) { input_b }
|
2013-09-07 12:57:06 -04:00
|
|
|
|
|
|
|
it { should be(false) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
describe Mutant::Predicate::Blacklist do
|
2013-09-07 12:57:06 -04:00
|
|
|
instance_eval(&filter_helpers)
|
|
|
|
|
|
|
|
let(:object) { described_class.new(whitelist) }
|
|
|
|
|
|
|
|
describe '#match?' do
|
|
|
|
|
|
|
|
context 'with empty whitelist' do
|
|
|
|
let(:whitelist) { [] }
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
it 'accepts all inputs' do
|
|
|
|
expect(object.match?(input_a)).to be(true)
|
|
|
|
expect(object.match?(input_b)).to be(true)
|
2013-09-07 12:57:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with non empty whitelist' do
|
|
|
|
let(:whitelist) { [filter_a] }
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
context 'with whitelisted input' do
|
|
|
|
let(:input) { input_a }
|
2013-09-07 12:57:06 -04:00
|
|
|
|
|
|
|
it { should be(false) }
|
|
|
|
end
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
context 'with non whitelisted input' do
|
|
|
|
let(:input) { input_b }
|
2013-09-07 12:57:06 -04:00
|
|
|
|
|
|
|
it { should be(true) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
describe Mutant::Predicate::Attribute::Equality do
|
2013-09-07 12:57:06 -04:00
|
|
|
instance_eval(&filter_helpers)
|
|
|
|
|
|
|
|
let(:object) { described_class.new(attribute_name, expected_value) }
|
2013-09-07 17:12:03 -04:00
|
|
|
let(:input) { double('Input', attribute_name => actual_value) }
|
2013-09-07 13:16:21 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-09-07 17:12:03 -04:00
|
|
|
describe Mutant::Predicate::Attribute::Regexp do
|
2013-09-07 13:16:21 -04:00
|
|
|
instance_eval(&filter_helpers)
|
|
|
|
|
|
|
|
let(:object) { described_class.new(attribute_name, expectation) }
|
2013-09-07 17:12:03 -04:00
|
|
|
let(:input) { double('Input', attribute_name => actual_value) }
|
2013-09-07 13:16:21 -04:00
|
|
|
|
|
|
|
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
|
2013-09-07 12:57:06 -04:00
|
|
|
end
|