2013-07-28 19:03:06 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2012-11-21 16:28:08 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
shared_examples_for 'an invalid cli run' do
|
|
|
|
it 'should raise error' do
|
2013-07-28 17:52:05 -04:00
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.to raise_error(Mutant::CLI::Error, expected_message)
|
2012-11-21 16:28:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'a cli parser' do
|
2013-04-20 15:10:14 -04:00
|
|
|
subject { cli.config }
|
2013-06-25 03:37:45 -04:00
|
|
|
|
2013-06-15 10:32:40 -04:00
|
|
|
its(:strategy) { should eql(expected_strategy) }
|
|
|
|
its(:reporter) { should eql(expected_reporter) }
|
|
|
|
its(:matcher) { should eql(expected_matcher) }
|
2012-11-21 16:28:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe Mutant::CLI, '.new' do
|
|
|
|
let(:object) { described_class }
|
2013-06-25 03:37:45 -04:00
|
|
|
let(:time) { Time.now }
|
2013-01-15 17:46:05 -05:00
|
|
|
|
|
|
|
before do
|
2013-09-08 16:12:23 -04:00
|
|
|
Time.stub(now: time)
|
2013-01-15 17:46:05 -05:00
|
|
|
end
|
2012-11-21 16:28:08 -05:00
|
|
|
|
|
|
|
# Defaults
|
2013-09-13 16:28:04 -04:00
|
|
|
let(:expected_filter) { Mutant::Predicate::TAUTOLOGY }
|
2013-09-01 18:07:55 -04:00
|
|
|
let(:expected_strategy) { Mutant::Strategy::Rspec.new(0) }
|
2013-04-20 15:10:14 -04:00
|
|
|
let(:expected_reporter) { Mutant::Reporter::CLI.new($stdout) }
|
2012-11-21 16:28:08 -05:00
|
|
|
|
2013-09-13 16:28:04 -04:00
|
|
|
let(:ns) { Mutant::Matcher }
|
|
|
|
let(:cache) { Mutant::Cache.new }
|
2013-07-28 17:52:05 -04:00
|
|
|
|
2013-04-20 15:10:14 -04:00
|
|
|
let(:cli) { object.new(arguments) }
|
|
|
|
|
|
|
|
subject { cli }
|
2012-11-21 16:28:08 -05:00
|
|
|
|
2013-01-14 08:13:39 -05:00
|
|
|
context 'with unknown flag' do
|
|
|
|
let(:arguments) { %w(--invalid) }
|
|
|
|
|
2013-05-14 21:25:16 -04:00
|
|
|
let(:expected_message) { 'invalid option: --invalid' }
|
2013-01-14 08:13:39 -05:00
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
2012-11-21 16:28:08 -05:00
|
|
|
context 'with unknown option' do
|
|
|
|
let(:arguments) { %w(--invalid Foo) }
|
|
|
|
|
2013-05-14 21:25:16 -04:00
|
|
|
let(:expected_message) { 'invalid option: --invalid' }
|
2012-11-21 16:28:08 -05:00
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
2013-01-14 08:13:39 -05:00
|
|
|
context 'with many strategy flags' do
|
2013-09-01 18:07:55 -04:00
|
|
|
let(:arguments) { %w(--rspec --rspec TestApp) }
|
2013-09-13 16:28:04 -04:00
|
|
|
let(:expected_matcher) { Mutant::Matcher::Scope.new(cache, TestApp) }
|
2013-01-14 08:13:39 -05:00
|
|
|
|
2013-07-17 14:03:52 -04:00
|
|
|
it_should_behave_like 'a cli parser'
|
2013-01-14 08:13:39 -05:00
|
|
|
end
|
|
|
|
|
2012-11-21 16:28:08 -05:00
|
|
|
context 'without arguments' do
|
|
|
|
let(:arguments) { [] }
|
|
|
|
|
2013-09-01 18:07:55 -04:00
|
|
|
let(:expected_message) { 'No matchers given' }
|
2012-11-21 16:28:08 -05:00
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with code filter and missing argument' do
|
2013-07-17 13:45:47 -04:00
|
|
|
let(:arguments) { %w(--rspec --code) }
|
2013-05-14 21:25:16 -04:00
|
|
|
let(:expected_message) { 'missing argument: --code' }
|
2012-11-21 16:28:08 -05:00
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with explicit method matcher' do
|
2013-07-28 19:22:37 -04:00
|
|
|
let(:arguments) { %w(--rspec TestApp::Literal#float) }
|
2013-09-13 16:28:04 -04:00
|
|
|
let(:expected_matcher) { ns::Method::Instance.new(cache, TestApp::Literal, TestApp::Literal.instance_method(:float)) }
|
2012-11-21 16:28:08 -05:00
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
end
|
|
|
|
|
2013-08-04 17:52:38 -04:00
|
|
|
context 'with debug flag' do
|
2013-09-13 16:28:04 -04:00
|
|
|
let(:matcher) { '::TestApp*' }
|
|
|
|
let(:arguments) { %W(--debug --rspec #{matcher}) }
|
|
|
|
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
|
2013-08-04 17:52:38 -04:00
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'should set the debug option' do
|
|
|
|
subject.config.debug.should be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with zombie flag' do
|
2013-09-13 16:28:04 -04:00
|
|
|
let(:matcher) { '::TestApp*' }
|
|
|
|
let(:arguments) { %W(--zombie --rspec #{matcher}) }
|
|
|
|
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
|
2013-08-04 17:52:38 -04:00
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'should set the zombie option' do
|
|
|
|
subject.config.zombie.should be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-14 08:13:39 -05:00
|
|
|
context 'with namespace matcher' do
|
2013-09-13 16:28:04 -04:00
|
|
|
let(:matcher) { '::TestApp*' }
|
|
|
|
let(:arguments) { %W(--rspec #{matcher}) }
|
|
|
|
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
|
2012-11-21 16:28:08 -05:00
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with code filter' do
|
2013-07-28 19:22:37 -04:00
|
|
|
let(:matcher) { 'TestApp::Literal#float' }
|
|
|
|
let(:arguments) { %W(--rspec --code faa --code bbb #{matcher}) }
|
2012-11-21 16:28:08 -05:00
|
|
|
|
|
|
|
let(:filters) do
|
|
|
|
[
|
2013-09-07 17:12:03 -04:00
|
|
|
Mutant::Predicate::Attribute.new(:code, 'faa'),
|
|
|
|
Mutant::Predicate::Attribute.new(:code, 'bbb'),
|
2012-11-21 16:28:08 -05:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2013-09-13 16:28:04 -04:00
|
|
|
let(:expected_matcher) { ns::Method::Instance.new(cache, TestApp::Literal, TestApp::Literal.instance_method(:float)) }
|
2013-09-07 17:12:03 -04:00
|
|
|
let(:expected_filter) { Mutant::Predicate::Whitelist.new(filters) }
|
2012-11-21 16:28:08 -05:00
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
end
|
|
|
|
end
|