2014-08-10 21:04:05 +00:00
|
|
|
RSpec.describe Mutant::Expression do
|
2014-07-06 02:34:01 +00:00
|
|
|
let(:object) { described_class }
|
|
|
|
|
2015-06-21 14:44:33 +00:00
|
|
|
let(:parser) { Mutant::Config::DEFAULT.expression_parser }
|
2014-07-06 02:34:01 +00:00
|
|
|
|
2015-06-21 14:44:07 +00:00
|
|
|
describe '#prefix?' do
|
2015-06-21 14:44:33 +00:00
|
|
|
let(:object) { parser.call('Foo*') }
|
2015-06-21 14:44:07 +00:00
|
|
|
|
|
|
|
subject { object.prefix?(other) }
|
|
|
|
|
|
|
|
context 'when object is a prefix of other' do
|
2015-06-21 14:44:33 +00:00
|
|
|
let(:other) { parser.call('Foo::Bar') }
|
2015-06-21 14:44:07 +00:00
|
|
|
|
|
|
|
it { should be(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when other is not a prefix of other' do
|
2015-06-21 14:44:33 +00:00
|
|
|
let(:other) { parser.call('Bar') }
|
2015-06-21 14:44:07 +00:00
|
|
|
|
|
|
|
it { should be(false) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-21 14:44:33 +00:00
|
|
|
describe '.try_parse' do
|
|
|
|
let(:object) do
|
|
|
|
Class.new(described_class) do
|
|
|
|
include Anima.new(:foo)
|
2014-07-06 02:34:01 +00:00
|
|
|
|
2015-06-21 14:44:33 +00:00
|
|
|
const_set(:REGEXP, /(?<foo>foo)/)
|
2014-07-06 02:34:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-21 14:44:33 +00:00
|
|
|
subject { object.try_parse(input) }
|
|
|
|
|
|
|
|
context 'on succesful parse' do
|
|
|
|
let(:input) { 'foo' }
|
2014-07-06 02:34:01 +00:00
|
|
|
|
2015-06-21 14:44:33 +00:00
|
|
|
it { should eql(object.new(foo: 'foo')) }
|
2014-07-06 02:34:01 +00:00
|
|
|
end
|
2014-12-22 17:54:18 +00:00
|
|
|
|
2015-06-21 14:44:33 +00:00
|
|
|
context 'on unsuccesful parse' do
|
|
|
|
let(:input) { 'bar' }
|
2014-12-22 17:54:18 +00:00
|
|
|
|
2015-06-21 14:44:33 +00:00
|
|
|
it { should be(nil) }
|
|
|
|
end
|
2014-12-22 17:54:18 +00:00
|
|
|
end
|
2014-07-06 02:34:01 +00:00
|
|
|
end
|