2013-07-28 16:03:06 -07:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2012-11-21 22:28:08 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
shared_examples_for 'an invalid cli run' do
|
|
|
|
it 'should raise error' do
|
2013-07-28 23:52:05 +02:00
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.to raise_error(Mutant::CLI::Error, expected_message)
|
2012-11-21 22:28:08 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'a cli parser' do
|
2013-04-20 21:10:14 +02:00
|
|
|
subject { cli.config }
|
2013-06-25 00:37:45 -07:00
|
|
|
|
2014-02-17 04:04:19 +02:00
|
|
|
it { expect(subject.strategy).to eql(expected_strategy) }
|
|
|
|
it { expect(subject.reporter).to eql(expected_reporter) }
|
|
|
|
it { expect(subject.matcher).to eql(expected_matcher) }
|
2012-11-21 22:28:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe Mutant::CLI, '.new' do
|
|
|
|
let(:object) { described_class }
|
2013-06-25 00:37:45 -07:00
|
|
|
let(:time) { Time.now }
|
2013-01-15 23:46:05 +01:00
|
|
|
|
|
|
|
before do
|
2013-09-08 22:12:23 +02:00
|
|
|
Time.stub(now: time)
|
2013-01-15 23:46:05 +01:00
|
|
|
end
|
2012-11-21 22:28:08 +01:00
|
|
|
|
|
|
|
# Defaults
|
2014-02-02 22:48:08 +01:00
|
|
|
let(:expected_filter) { Morpher.evaluator(s(:true)) }
|
2014-01-18 00:25:16 +01:00
|
|
|
let(:expected_strategy) { Mutant::Strategy::Null.new }
|
2013-04-20 21:10:14 +02:00
|
|
|
let(:expected_reporter) { Mutant::Reporter::CLI.new($stdout) }
|
2012-11-21 22:28:08 +01:00
|
|
|
|
2013-09-13 22:28:04 +02:00
|
|
|
let(:ns) { Mutant::Matcher }
|
|
|
|
let(:cache) { Mutant::Cache.new }
|
2013-07-28 23:52:05 +02:00
|
|
|
|
2013-04-20 21:10:14 +02:00
|
|
|
let(:cli) { object.new(arguments) }
|
|
|
|
|
|
|
|
subject { cli }
|
2012-11-21 22:28:08 +01:00
|
|
|
|
2013-01-14 14:13:39 +01:00
|
|
|
context 'with unknown flag' do
|
|
|
|
let(:arguments) { %w(--invalid) }
|
|
|
|
|
2013-05-14 18:25:16 -07:00
|
|
|
let(:expected_message) { 'invalid option: --invalid' }
|
2013-01-14 14:13:39 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
2012-11-21 22:28:08 +01:00
|
|
|
context 'with unknown option' do
|
|
|
|
let(:arguments) { %w(--invalid Foo) }
|
|
|
|
|
2013-05-14 18:25:16 -07:00
|
|
|
let(:expected_message) { 'invalid option: --invalid' }
|
2012-11-21 22:28:08 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without arguments' do
|
|
|
|
let(:arguments) { [] }
|
|
|
|
|
2014-02-02 22:48:08 +01:00
|
|
|
let(:expected_message) { 'No patterns given' }
|
2012-11-21 22:28:08 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with code filter and missing argument' do
|
2014-01-18 00:25:16 +01:00
|
|
|
let(:arguments) { %w(--code) }
|
2013-05-14 18:25:16 -07:00
|
|
|
let(:expected_message) { 'missing argument: --code' }
|
2012-11-21 22:28:08 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
2014-02-02 22:48:08 +01:00
|
|
|
context 'with explicit method pattern' do
|
2014-01-18 00:25:16 +01:00
|
|
|
let(:arguments) { %w(TestApp::Literal#float) }
|
2014-02-02 22:48:08 +01:00
|
|
|
|
|
|
|
let(:expected_matcher) do
|
|
|
|
ns::Method::Instance.new(cache, TestApp::Literal, TestApp::Literal.instance_method(:float))
|
|
|
|
end
|
2012-11-21 22:28:08 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
end
|
|
|
|
|
2013-08-04 23:52:38 +02:00
|
|
|
context 'with debug flag' do
|
2014-02-02 22:48:08 +01:00
|
|
|
let(:pattern) { '::TestApp*' }
|
|
|
|
let(:arguments) { %W(--debug #{pattern}) }
|
2013-09-13 22:28:04 +02:00
|
|
|
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
|
2013-08-04 23:52:38 +02:00
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'should set the debug option' do
|
2014-02-02 22:48:08 +01:00
|
|
|
expect(subject.config.debug).to be(true)
|
2013-08-04 23:52:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with zombie flag' do
|
2014-02-02 22:48:08 +01:00
|
|
|
let(:pattern) { '::TestApp*' }
|
|
|
|
let(:arguments) { %W(--zombie #{pattern}) }
|
2013-09-13 22:28:04 +02:00
|
|
|
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
|
2013-08-04 23:52:38 +02:00
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'should set the zombie option' do
|
2014-02-02 22:48:08 +01:00
|
|
|
expect(subject.config.zombie).to be(true)
|
2013-08-04 23:52:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-02 22:48:08 +01:00
|
|
|
context 'with namespace pattern' do
|
|
|
|
let(:pattern) { '::TestApp*' }
|
|
|
|
let(:arguments) { %W(#{pattern}) }
|
2013-09-13 22:28:04 +02:00
|
|
|
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
|
2012-11-21 22:28:08 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
end
|
|
|
|
|
2014-02-02 22:48:08 +01:00
|
|
|
context 'with subject code filter' do
|
|
|
|
let(:pattern) { 'TestApp::Literal#float' }
|
|
|
|
let(:arguments) { %W(--code faa --code bbb #{pattern}) }
|
|
|
|
|
|
|
|
let(:expected_filter) do
|
|
|
|
Morpher.evaluator(
|
|
|
|
s(:mxor,
|
|
|
|
s(:eql, s(:attribute, :code), s(:value, 'faa')),
|
|
|
|
s(:eql, s(:attribute, :code), s(:value, 'bbb'))
|
|
|
|
)
|
|
|
|
)
|
2012-11-21 22:28:08 +01:00
|
|
|
end
|
|
|
|
|
2014-02-02 22:48:08 +01:00
|
|
|
let(:expected_matcher) do
|
|
|
|
matcher = ns::Method::Instance.new(
|
|
|
|
cache,
|
|
|
|
TestApp::Literal, TestApp::Literal.instance_method(:float)
|
|
|
|
)
|
2014-03-09 00:00:46 +00:00
|
|
|
predicate = Morpher.compile(
|
2014-02-02 22:48:08 +01:00
|
|
|
s(:or,
|
|
|
|
s(:eql,
|
|
|
|
s(:attribute, :code),
|
|
|
|
s(:static, 'faa')
|
|
|
|
),
|
|
|
|
s(:eql,
|
|
|
|
s(:attribute, :code),
|
|
|
|
s(:static, 'bbb')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
ns::Filter.new(matcher, predicate)
|
|
|
|
end
|
2012-11-21 22:28:08 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
end
|
|
|
|
end
|