From 4feee324f274dbc4adf1472b14cded84283584cf Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 17 Oct 2021 02:03:06 +0000 Subject: [PATCH] Add mutant environment irb subcommand --- Changelog.md | 7 +++++ Gemfile.lock | 4 +-- lib/mutant.rb | 2 ++ lib/mutant/cli/command/environment/irb.rb | 21 +++++++++++++++ lib/mutant/cli/command/root.rb | 2 +- lib/mutant/version.rb | 2 +- spec/unit/mutant/cli_spec.rb | 33 +++++++++++++++++++++++ 7 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 lib/mutant/cli/command/environment/irb.rb diff --git a/Changelog.md b/Changelog.md index 349234f47..22dce3a7f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,10 @@ +# v0.10.35 2021-10-17 + +* [#1269](https://github.com/mbj/mutant/pull/1269) + Add `mutant environment irb` command. Starts an IRB session for the + configured mutant environment. Very useful for iterating on environment + setup issues. + # v0.10.34 2021-08-30 * [#1252](https://github.com/mbj/mutant/pull/1252) diff --git a/Gemfile.lock b/Gemfile.lock index 5153c4771..b9ed66a24 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - mutant (0.10.34) + mutant (0.10.35) diff-lcs (~> 1.3) parser (~> 3.0.0) regexp_parser (~> 2.0, >= 2.0.3) @@ -69,4 +69,4 @@ DEPENDENCIES rubocop (~> 1.7) BUNDLED WITH - 2.2.25 + 2.2.29 diff --git a/lib/mutant.rb b/lib/mutant.rb index 9ebe002c0..1073a0ff2 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -4,6 +4,7 @@ require 'diff/lcs/hunk' require 'digest/sha1' require 'etc' +require 'irb' require 'json' require 'open3' require 'optparse' @@ -194,6 +195,7 @@ module Mutant require 'mutant/cli/command' require 'mutant/cli/command/subscription' require 'mutant/cli/command/environment' +require 'mutant/cli/command/environment/irb' require 'mutant/cli/command/environment/run' require 'mutant/cli/command/environment/show' require 'mutant/cli/command/environment/subject' diff --git a/lib/mutant/cli/command/environment/irb.rb b/lib/mutant/cli/command/environment/irb.rb new file mode 100644 index 000000000..87b2f8f33 --- /dev/null +++ b/lib/mutant/cli/command/environment/irb.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Mutant + module CLI + class Command + class Environment + class IRB < self + NAME = 'irb' + SHORT_DESCRIPTION = 'Run irb with mutant environment loaded' + SUBCOMMANDS = EMPTY_ARRAY + + private + + def action + bootstrap.fmap { TOPLEVEL_BINDING.irb } + end + end # IRB + end # Environment + end # Command + end # CLI +end # Mutant diff --git a/lib/mutant/cli/command/root.rb b/lib/mutant/cli/command/root.rb index 2d862551a..f3a857709 100644 --- a/lib/mutant/cli/command/root.rb +++ b/lib/mutant/cli/command/root.rb @@ -4,7 +4,7 @@ module Mutant module CLI class Command class Environment < self - SUBCOMMANDS = [Environment::Subject, Environment::Show, Environment::Test].freeze + SUBCOMMANDS = [Environment::Subject, Environment::Show, Environment::IRB, Environment::Test].freeze end # Environment class Root < self diff --git a/lib/mutant/version.rb b/lib/mutant/version.rb index 464bbba71..977ae218b 100644 --- a/lib/mutant/version.rb +++ b/lib/mutant/version.rb @@ -2,5 +2,5 @@ module Mutant # Current mutant version - VERSION = '0.10.34' + VERSION = '0.10.35' end # Mutant diff --git a/spec/unit/mutant/cli_spec.rb b/spec/unit/mutant/cli_spec.rb index 68ee7c3e6..da0707c4d 100644 --- a/spec/unit/mutant/cli_spec.rb +++ b/spec/unit/mutant/cli_spec.rb @@ -557,6 +557,39 @@ def self.main_body end end + context 'environment irb' do + include_context 'environment' + + before do + allow(TOPLEVEL_BINDING).to receive(:irb) do + events << :irb_execution + end + end + + let(:arguments) { %w[environment irb] } + + context 'without additional arguments' do + let(:expected_exit) { true } + + let(:expected_events) do + [ + [ + :load_config_file, + world + ], + [ + :bootstrap, + world, + bootstrap_config.inspect + ], + :irb_execution + ] + end + + include_examples 'CLI run' + end + end + context 'environment test list' do include_context 'environment'