free_mutant/spec/unit/mutant/cli_new_spec.rb

135 lines
3.7 KiB
Ruby
Raw Normal View History

# encoding: utf-8
require 'spec_helper'
shared_examples_for 'an invalid cli run' do
it 'should raise error' do
expect do
subject
end.to raise_error(Mutant::CLI::Error, expected_message)
end
end
shared_examples_for 'a cli parser' do
subject { cli.config }
2013-06-25 03:37:45 -04:00
its(:strategy) { should eql(expected_strategy) }
its(:reporter) { should eql(expected_reporter) }
its(:matcher) { should eql(expected_matcher) }
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
# Defaults
let(:expected_filter) { Mutant::Predicate::TAUTOLOGY }
let(:expected_strategy) { Mutant::Strategy::Rspec.new(0) }
let(:expected_reporter) { Mutant::Reporter::CLI.new($stdout) }
let(:ns) { Mutant::Matcher }
let(:cache) { Mutant::Cache.new }
let(:cli) { object.new(arguments) }
subject { cli }
2013-01-14 08:13:39 -05:00
context 'with unknown flag' do
let(:arguments) { %w(--invalid) }
let(:expected_message) { 'invalid option: --invalid' }
2013-01-14 08:13:39 -05:00
it_should_behave_like 'an invalid cli run'
end
context 'with unknown option' do
let(:arguments) { %w(--invalid Foo) }
let(:expected_message) { 'invalid option: --invalid' }
it_should_behave_like 'an invalid cli run'
end
2013-01-14 08:13:39 -05:00
context 'with many strategy flags' do
let(:arguments) { %w(--rspec --rspec TestApp) }
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
context 'without arguments' do
let(:arguments) { [] }
let(:expected_message) { 'No matchers given' }
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) }
let(:expected_message) { 'missing argument: --code' }
it_should_behave_like 'an invalid cli run'
end
context 'with explicit method matcher' do
let(:arguments) { %w(--rspec TestApp::Literal#float) }
let(:expected_matcher) { ns::Method::Instance.new(cache, TestApp::Literal, TestApp::Literal.instance_method(:float)) }
it_should_behave_like 'a cli parser'
end
context 'with debug flag' do
let(:matcher) { '::TestApp*' }
let(:arguments) { %W(--debug --rspec #{matcher}) }
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
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
let(:matcher) { '::TestApp*' }
let(:arguments) { %W(--zombie --rspec #{matcher}) }
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
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
let(:matcher) { '::TestApp*' }
let(:arguments) { %W(--rspec #{matcher}) }
let(:expected_matcher) { ns::Namespace.new(cache, TestApp) }
it_should_behave_like 'a cli parser'
end
context 'with code filter' do
let(:matcher) { 'TestApp::Literal#float' }
let(:arguments) { %W(--rspec --code faa --code bbb #{matcher}) }
let(:filters) do
[
2013-09-07 17:12:03 -04:00
Mutant::Predicate::Attribute.new(:code, 'faa'),
Mutant::Predicate::Attribute.new(:code, 'bbb'),
]
end
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) }
it_should_behave_like 'a cli parser'
end
end