Skip to content

Commit 13a7f29

Browse files
authored
Merge pull request #896 from mbj/add/env-warn
Add env warn
2 parents d0e3f0d + f8e8e66 commit 13a7f29

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

lib/mutant/env.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ def selections
4343
end
4444
memoize :selections
4545

46+
# Emit warning
47+
#
48+
# @param [String] warning
49+
#
50+
# @return [self]
51+
def warn(message)
52+
config.reporter.warn(message)
53+
self
54+
end
55+
4656
private
4757

4858
# Kill mutation under isolation with integration

spec/unit/mutant/env_spec.rb

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
RSpec.describe Mutant::Env do
4-
let(:object) do
4+
subject do
55
described_class.new(
66
config: config,
77
integration: integration,
@@ -19,6 +19,7 @@
1919
let(:isolation) { Mutant::Isolation::None.new }
2020
let(:kernel) { instance_double(Object, 'kernel') }
2121
let(:mutation_subject) { instance_double(Mutant::Subject) }
22+
let(:reporter) { instance_double(Mutant::Reporter) }
2223
let(:selector) { instance_double(Mutant::Selector) }
2324
let(:test_a) { instance_double(Mutant::Test) }
2425
let(:test_b) { instance_double(Mutant::Test) }
@@ -32,9 +33,11 @@
3233
end
3334

3435
let(:config) do
35-
Mutant::Config::DEFAULT.with(
36+
instance_double(
37+
Mutant::Config,
38+
integration: integration_class,
3639
isolation: isolation,
37-
integration: integration_class
40+
reporter: reporter
3841
)
3942
end
4043

@@ -55,7 +58,7 @@
5558

5659
describe '#kill' do
5760
def apply
58-
object.kill(mutation)
61+
subject.kill(mutation)
5962
end
6063

6164
before do
@@ -120,10 +123,34 @@ def apply
120123
end
121124

122125
describe '#selections' do
123-
subject { object.selections }
126+
def apply
127+
subject.selections
128+
end
124129

125130
it 'returns expected selections' do
126-
expect(subject).to eql(mutation_subject => tests)
131+
expect(apply).to eql(mutation_subject => tests)
132+
end
133+
end
134+
135+
describe '#warn' do
136+
def apply
137+
subject.warn(message)
138+
end
139+
140+
before do
141+
allow(reporter).to receive_messages(warn: reporter)
142+
end
143+
144+
let(:message) { 'test-warning' }
145+
146+
it 'warns via the reporter' do
147+
apply
148+
149+
expect(reporter).to have_received(:warn).with(message)
150+
end
151+
152+
it 'returns self' do
153+
expect(apply).to be(subject)
127154
end
128155
end
129156
end

0 commit comments

Comments
 (0)