2014-08-10 17:04:05 -04:00
|
|
|
RSpec.describe Mutant::Reporter::CLI do
|
2014-10-23 07:37:53 -04:00
|
|
|
setup_shared_context
|
|
|
|
|
2014-08-10 18:09:29 -04:00
|
|
|
let(:object) { described_class.new(output, format) }
|
2015-05-02 18:25:36 -04:00
|
|
|
let(:output) { StringIO.new }
|
|
|
|
|
|
|
|
let(:tput) do
|
|
|
|
double(
|
|
|
|
'tput',
|
|
|
|
restore: '[tput-restore]',
|
|
|
|
prepare: '[tput-prepare]'
|
|
|
|
)
|
|
|
|
end
|
2014-07-03 17:16:12 -04:00
|
|
|
|
2014-08-11 10:29:32 -04:00
|
|
|
let(:framed_format) do
|
2014-08-10 18:09:29 -04:00
|
|
|
described_class::Format::Framed.new(
|
|
|
|
tty: false,
|
2015-05-02 18:25:36 -04:00
|
|
|
tput: tput
|
2014-08-10 18:09:29 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2015-05-02 20:21:30 -04:00
|
|
|
let(:tty?) { false }
|
|
|
|
|
2014-08-11 10:29:32 -04:00
|
|
|
let(:progressive_format) do
|
2015-05-02 20:21:30 -04:00
|
|
|
described_class::Format::Progressive.new(tty: tty?)
|
2014-08-11 10:29:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:format) { framed_format }
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
def contents
|
|
|
|
output.rewind
|
|
|
|
output.read
|
|
|
|
end
|
|
|
|
|
2014-08-11 10:29:32 -04:00
|
|
|
def self.it_reports(expected_content)
|
|
|
|
it 'writes expected report to output' do
|
2015-05-02 19:18:01 -04:00
|
|
|
expect(subject).to be(object)
|
2014-08-11 10:29:32 -04:00
|
|
|
expect(contents).to eql(strip_indent(expected_content))
|
|
|
|
end
|
2014-07-17 09:59:25 -04:00
|
|
|
end
|
|
|
|
|
2014-08-11 10:29:32 -04:00
|
|
|
before do
|
|
|
|
allow(Time).to receive(:now).and_return(Time.now)
|
2014-07-03 17:16:12 -04:00
|
|
|
end
|
|
|
|
|
2014-08-11 10:52:31 -04:00
|
|
|
describe '.build' do
|
|
|
|
subject { described_class.build(output) }
|
|
|
|
|
|
|
|
let(:progressive_format) do
|
2014-08-11 13:35:18 -04:00
|
|
|
described_class::Format::Progressive.new(tty: tty?)
|
2014-08-11 10:52:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:framed_format) do
|
|
|
|
described_class::Format::Framed.new(
|
|
|
|
tty: true,
|
2015-05-02 18:25:36 -04:00
|
|
|
tput: tput
|
2014-08-11 10:52:31 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
expect(ENV).to receive(:key?).with('CI').and_return(ci?)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:output) { double('Output', tty?: tty?) }
|
|
|
|
let(:tty?) { true }
|
|
|
|
let(:ci?) { false }
|
|
|
|
|
|
|
|
context 'when not on CI and on a tty' do
|
2015-05-02 18:25:36 -04:00
|
|
|
before do
|
|
|
|
expect(described_class::Tput).to receive(:detect).and_return(tput)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and tput is available' do
|
|
|
|
it { should eql(described_class.new(output, framed_format)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and tput is not available' do
|
|
|
|
let(:tput) { nil }
|
|
|
|
|
|
|
|
it { should eql(described_class.new(output, progressive_format)) }
|
|
|
|
end
|
2014-08-11 10:52:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when on CI' do
|
|
|
|
let(:ci?) { true }
|
|
|
|
it { should eql(described_class.new(output, progressive_format)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when output is not a tty?' do
|
|
|
|
let(:tty?) { false }
|
|
|
|
it { should eql(described_class.new(output, progressive_format)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when output does not respond to #tty?' do
|
|
|
|
let(:output) { double('Output') }
|
|
|
|
let(:tty?) { false }
|
|
|
|
|
|
|
|
it { should eql(described_class.new(output, progressive_format)) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-11 10:29:32 -04:00
|
|
|
describe '#warn' do
|
|
|
|
subject { object.warn(message) }
|
|
|
|
|
|
|
|
let(:message) { 'message' }
|
|
|
|
|
|
|
|
it_reports("message\n")
|
|
|
|
end
|
|
|
|
|
2014-12-08 13:13:49 -05:00
|
|
|
describe '#delay' do
|
|
|
|
subject { object.delay }
|
|
|
|
|
|
|
|
it { should eql(0.05) }
|
|
|
|
end
|
|
|
|
|
2014-08-11 10:29:32 -04:00
|
|
|
describe '#start' do
|
|
|
|
subject { object.start(env) }
|
|
|
|
|
|
|
|
context 'on progressive format' do
|
|
|
|
let(:format) { progressive_format }
|
|
|
|
|
|
|
|
it_reports(<<-REPORT)
|
|
|
|
Mutant configuration:
|
2015-07-07 17:17:45 -04:00
|
|
|
Matcher: #<Mutant::Matcher::Config empty>
|
2015-06-28 22:10:04 -04:00
|
|
|
Integration: Mutant::Integration::Null
|
2014-12-07 16:12:29 -05:00
|
|
|
Expect Coverage: 100.00%
|
|
|
|
Jobs: 1
|
|
|
|
Includes: []
|
|
|
|
Requires: []
|
2014-08-11 10:29:32 -04:00
|
|
|
REPORT
|
|
|
|
end
|
|
|
|
|
2015-05-02 20:21:30 -04:00
|
|
|
context 'with non default coverage expectation' do
|
|
|
|
let(:format) { progressive_format }
|
2015-09-04 16:20:56 -04:00
|
|
|
|
|
|
|
with(:config) { { expected_coverage: 0.1r } }
|
2015-05-02 20:21:30 -04:00
|
|
|
|
|
|
|
it_reports(<<-REPORT)
|
|
|
|
Mutant configuration:
|
2015-07-07 17:17:45 -04:00
|
|
|
Matcher: #<Mutant::Matcher::Config empty>
|
2015-06-28 22:10:04 -04:00
|
|
|
Integration: Mutant::Integration::Null
|
2015-05-02 20:21:30 -04:00
|
|
|
Expect Coverage: 10.00%
|
|
|
|
Jobs: 1
|
|
|
|
Includes: []
|
|
|
|
Requires: []
|
|
|
|
REPORT
|
|
|
|
end
|
|
|
|
|
2014-08-11 10:29:32 -04:00
|
|
|
context 'on framed format' do
|
2015-05-02 18:25:36 -04:00
|
|
|
it_reports '[tput-prepare]'
|
2014-08-11 10:29:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-02 20:21:30 -04:00
|
|
|
describe '#report' do
|
|
|
|
subject { object.report(env_result) }
|
|
|
|
|
|
|
|
it_reports(<<-REPORT)
|
|
|
|
Mutant configuration:
|
2015-07-07 17:17:45 -04:00
|
|
|
Matcher: #<Mutant::Matcher::Config empty>
|
2015-06-28 22:10:04 -04:00
|
|
|
Integration: Mutant::Integration::Null
|
2015-05-02 20:21:30 -04:00
|
|
|
Expect Coverage: 100.00%
|
|
|
|
Jobs: 1
|
|
|
|
Includes: []
|
|
|
|
Requires: []
|
|
|
|
Subjects: 1
|
|
|
|
Mutations: 2
|
2015-11-01 15:46:19 -05:00
|
|
|
Results: 2
|
2015-05-02 20:21:30 -04:00
|
|
|
Kills: 2
|
|
|
|
Alive: 0
|
|
|
|
Runtime: 4.00s
|
|
|
|
Killtime: 2.00s
|
|
|
|
Overhead: 100.00%
|
2015-11-01 15:46:19 -05:00
|
|
|
Mutations/s: 0.50
|
2015-05-02 20:21:30 -04:00
|
|
|
Coverage: 100.00%
|
|
|
|
Expected: 100.00%
|
|
|
|
REPORT
|
|
|
|
end
|
|
|
|
|
2014-07-06 17:51:22 -04:00
|
|
|
describe '#progress' do
|
2014-10-23 07:37:53 -04:00
|
|
|
subject { object.progress(status) }
|
2014-07-06 17:51:22 -04:00
|
|
|
|
2015-05-02 20:21:30 -04:00
|
|
|
context 'on framed format' do
|
|
|
|
let(:format) { framed_format }
|
|
|
|
|
|
|
|
it_reports(<<-REPORT)
|
|
|
|
[tput-restore]Mutant configuration:
|
2015-07-07 17:17:45 -04:00
|
|
|
Matcher: #<Mutant::Matcher::Config empty>
|
2015-06-28 22:10:04 -04:00
|
|
|
Integration: Mutant::Integration::Null
|
2015-05-02 20:21:30 -04:00
|
|
|
Expect Coverage: 100.00%
|
|
|
|
Jobs: 1
|
|
|
|
Includes: []
|
|
|
|
Requires: []
|
|
|
|
Subjects: 1
|
|
|
|
Mutations: 2
|
2015-11-01 15:46:19 -05:00
|
|
|
Results: 2
|
2015-05-02 20:21:30 -04:00
|
|
|
Kills: 2
|
|
|
|
Alive: 0
|
|
|
|
Runtime: 4.00s
|
|
|
|
Killtime: 2.00s
|
|
|
|
Overhead: 100.00%
|
2015-11-01 15:46:19 -05:00
|
|
|
Mutations/s: 0.50
|
2015-05-02 20:21:30 -04:00
|
|
|
Coverage: 100.00%
|
|
|
|
Expected: 100.00%
|
|
|
|
Active subjects: 0
|
|
|
|
REPORT
|
|
|
|
end
|
|
|
|
|
2014-08-11 10:29:32 -04:00
|
|
|
context 'on progressive format' do
|
|
|
|
let(:format) { progressive_format }
|
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
context 'with empty scheduler' do
|
2015-09-04 16:20:56 -04:00
|
|
|
with(:env_result) { { subject_results: [] } }
|
2014-08-11 10:29:32 -04:00
|
|
|
|
2015-05-02 20:21:30 -04:00
|
|
|
let(:tty?) { true }
|
|
|
|
|
2015-07-21 16:08:55 -04:00
|
|
|
it_reports Mutant::Color::GREEN.format('(00/02) 100% - killtime: 0.00s runtime: 4.00s overhead: 4.00s') << "\n"
|
2014-07-17 09:59:25 -04:00
|
|
|
end
|
|
|
|
|
2014-08-11 10:29:32 -04:00
|
|
|
context 'with last mutation present' do
|
2015-09-04 16:20:56 -04:00
|
|
|
with(:env_result) { { subject_results: [subject_a_result] } }
|
2014-08-11 10:29:32 -04:00
|
|
|
|
|
|
|
context 'when mutation is successful' do
|
2014-12-08 13:13:49 -05:00
|
|
|
it_reports "(02/02) 100% - killtime: 2.00s runtime: 4.00s overhead: 2.00s\n"
|
2014-08-11 10:29:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when mutation is NOT successful' do
|
2015-09-04 16:20:56 -04:00
|
|
|
with(:mutation_a_test_result) { { passed: true } }
|
|
|
|
|
2014-12-08 13:13:49 -05:00
|
|
|
it_reports "(01/02) 50% - killtime: 2.00s runtime: 4.00s overhead: 2.00s\n"
|
2014-08-11 10:29:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-07-03 17:16:12 -04:00
|
|
|
end
|
|
|
|
end
|