Skip to content

Commit

Permalink
Change to improved 0 test detected messaging
Browse files Browse the repository at this point in the history
[Fix #123]
  • Loading branch information
mbj committed Aug 30, 2021
1 parent edb7f6a commit d372b30
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
* [#1257](https://github.com/mbj/mutant/pull/1257)
Fix crash on numblock mutations.

* [#1258](https://github.com/mbj/mutant/pull/1258)
Add improved UI on detecting 0 tests.
This should be beneficial in onboarding scenarios or after manual
persistend rspec selections.

# v0.10.33 2021-08-25

* [#1249](https://github.com/mbj/mutant/pull/1249/files)
Expand Down
23 changes: 23 additions & 0 deletions lib/mutant/cli/command/environment/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ class Run < self
See https://github.com/mbj/mutant#licensing
MESSAGE

NO_TESTS_MESSAGE = <<~'MESSAGE'
===============
Mutant found no tests. Mutation testing cannot be started.
This can have various reasons:
* You did not setup an integration, see:
https://github.com/mbj/mutant/blob/main/docs/configuration.md#integration
* You set environment variables like RSPEC_OPTS that filter out all tests.
* You set configuration optiosn like `config.filter_run :focus` which do
make rspec to not report any test.
===============
MESSAGE

# Test if command needs to be executed in zombie environment
#
# @return [Bool]
Expand All @@ -28,10 +42,19 @@ def zombie?
def action
soft_fail(License.call(world))
.bind { bootstrap }
.bind(&method(:validate_tests))
.bind(&Runner.public_method(:call))
.bind(&method(:from_result))
end

def validate_tests(environment)
if environment.integration.all_tests.length.zero?
Either::Left.new(NO_TESTS_MESSAGE)
else
Either::Right.new(environment)
end
end

def from_result(result)
if result.success?
Either::Right.new(nil)
Expand Down
53 changes: 37 additions & 16 deletions spec/unit/mutant/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -748,28 +748,49 @@ def self.main_body
end

context 'on runner success with unsuccessful result' do
let(:expected_exit) { false }
let(:runner_result) { right(env_result) }
context 'on alive mutations' do
let(:expected_exit) { false }
let(:runner_result) { right(env_result) }

let(:env_result) do
instance_double(
Mutant::Result::Env,
success?: false
)
end

let(:env_result) do
instance_double(
Mutant::Result::Env,
success?: false
)
let(:expected_events) do
[
*super(),
[
:stderr,
:puts,
'Uncovered mutations detected, exiting nonzero!'
]
]
end

include_examples 'CLI run'
end

let(:expected_events) do
[
*super(),
context 'on not having found tests' do
let(:tests) { [] }

let(:expected_events) do
[
:stderr,
:puts,
'Uncovered mutations detected, exiting nonzero!'
*super()[0..-2],
[
:stderr,
:puts,
Mutant::CLI::Command::Environment::Run::NO_TESTS_MESSAGE
]
]
]
end
end

include_examples 'CLI run'
let(:expected_exit) { false }

include_examples 'CLI run'
end
end

context 'with valid subject expression' do
Expand Down

0 comments on commit d372b30

Please sign in to comment.