diff --git a/features/cli/ruby_features.feature b/features/cli/ruby_features.feature new file mode 100644 index 0000000..ff60e3d --- /dev/null +++ b/features/cli/ruby_features.feature @@ -0,0 +1,5 @@ +Feature: ruby feature require CLI option + + Scenario: requires a ruby feature + When I run uhwm with option -v -r abbrev + Then the current output must match /load.+abbrev.+ruby feature/i diff --git a/features/steps/output_steps.rb b/features/steps/output_steps.rb index abf73d8..9c7999e 100644 --- a/features/steps/output_steps.rb +++ b/features/steps/output_steps.rb @@ -23,6 +23,7 @@ options: -h, --help print this message -v, --version enable verbose mode -d, --debug enable debug mode + -r, --require PATH require ruby feature eoh end diff --git a/lib/uh/wm/cli.rb b/lib/uh/wm/cli.rb index 6bb70bf..cc61bce 100644 --- a/lib/uh/wm/cli.rb +++ b/lib/uh/wm/cli.rb @@ -58,6 +58,11 @@ module Uh @env.debug = true @env.log_logger_level end + + opts.on '-r', '--require PATH', 'require ruby feature' do |feature| + require feature + @env.log "Loaded `#{feature}' ruby feature" + end end end end diff --git a/spec/uh/wm/cli_spec.rb b/spec/uh/wm/cli_spec.rb index 4fd9f7f..3f2f3f0 100644 --- a/spec/uh/wm/cli_spec.rb +++ b/spec/uh/wm/cli_spec.rb @@ -116,6 +116,21 @@ module Uh end end + context 'with require option' do + let(:arguments) { %w[-r abbrev] } + + it 'requires the given ruby feature' do + expect { cli.parse_arguments! } + .to change { $LOADED_FEATURES.grep(/abbrev/).any? } + .from(false).to(true) + end + + it 'logs a message about the feature being loaded' do + expect(cli.env).to receive(:log).with /load.+abbrev.+ruby feature/i + cli.parse_arguments! + end + end + context 'with invalid option' do let(:arguments) { %w[--unknown-option] }