From 5e71e71b052b06b17c4957422533a79e6290c8a9 Mon Sep 17 00:00:00 2001 From: Evan Battaglia Date: Sun, 28 Jul 2024 15:10:35 -0230 Subject: [PATCH] fix specs --- lib/tabry/options_finder.rb | 1 - lib/tabry/result.rb | 3 ++- spec/tabry/cli/all_in_one_spec.rb | 7 +++++++ spec/tabry/models/config_spec.rb | 6 ++++++ spec/tabry/models/dir_option_spec.rb | 2 +- spec/tabry/models/file_option_spec.rb | 2 +- spec/tabry/runner_spec.rb | 4 +++- 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/tabry/options_finder.rb b/lib/tabry/options_finder.rb index 646598c..2a2b76e 100644 --- a/lib/tabry/options_finder.rb +++ b/lib/tabry/options_finder.rb @@ -32,7 +32,6 @@ def options(token) { subcommand: :options_subcommand, flagarg: :options_flagarg }[state.mode], token || "" ) - send(:"options_#{state.mode}", token || "") ensure ENV["TABRY_AUTOCOMPLETE_STATE"] = before_env end diff --git a/lib/tabry/result.rb b/lib/tabry/result.rb index fe23a85..3035e3a 100644 --- a/lib/tabry/result.rb +++ b/lib/tabry/result.rb @@ -24,7 +24,8 @@ def sub_stack def invalid_usage_reason waiting_on_flag_arg? || wrong_number_of_args? || - missing_required_flags? + missing_required_flags? || + nil end def waiting_on_flag_arg? diff --git a/spec/tabry/cli/all_in_one_spec.rb b/spec/tabry/cli/all_in_one_spec.rb index ba5a83f..870ab57 100644 --- a/spec/tabry/cli/all_in_one_spec.rb +++ b/spec/tabry/cli/all_in_one_spec.rb @@ -76,6 +76,13 @@ def foo2__bar2 cli.run(["completion", "bash"]) end + it "creates a #completion__json method which generates tabry JSON" do + expect_any_instance_of(Kernel).to receive(:puts) do |_, json| + expect(JSON.parse(json)).to eq(JSON.parse(cli.runner.config.as_json.to_json)) + end + cli.run(["completion", "json"]) + end + it "creates a #completion method which generates options" do expect(Tabry::Bash::Wrapper).to receive(:run).with("cmd line", "6", config: instance_of(Tabry::Models::Config)) cli.run(["completion", "cmd line", "6"]) diff --git a/spec/tabry/models/config_spec.rb b/spec/tabry/models/config_spec.rb index 13c8e6c..7f81f49 100644 --- a/spec/tabry/models/config_spec.rb +++ b/spec/tabry/models/config_spec.rb @@ -33,6 +33,12 @@ } end + describe "#as_json" do + it "returns the config as a hash" do + expect(subject.as_json).to eq(config_hash) + end + end + describe "#dig_sub_array" do it "returns the array of subcommands leading up to the specified subcommand" do res = subject.dig_sub_array(%w[sub1 sub1.1]) diff --git a/spec/tabry/models/dir_option_spec.rb b/spec/tabry/models/dir_option_spec.rb index 8e8a8e6..493b68f 100644 --- a/spec/tabry/models/dir_option_spec.rb +++ b/spec/tabry/models/dir_option_spec.rb @@ -8,7 +8,7 @@ described_class.new(root: double, raw: { "type" => "dir" }) end - # Handled by tabru=bash/tabry-bash.sh/shell, we just return a symbol to + # Handled by tabry-bash/tabry-bash.sh/shell, we just return a symbol to # communicate to tabry-bash it "returns a array with a symbol" do expect(subject.options("whatever", {})).to eq([:directory]) diff --git a/spec/tabry/models/file_option_spec.rb b/spec/tabry/models/file_option_spec.rb index 9d74f5c..dcfd430 100644 --- a/spec/tabry/models/file_option_spec.rb +++ b/spec/tabry/models/file_option_spec.rb @@ -8,7 +8,7 @@ described_class.new(root: double, raw: { "type" => "file" }) end - # Handled by tabru=bash/tabry-bash.sh/shell, we just return a symbol to + # Handled by tabry-bash/tabry-bash.sh/shell, we just return a symbol to # communicate to tabry-bash it "returns a array with a symbol" do expect(subject.options("whatever", {})).to eq([:file]) diff --git a/spec/tabry/runner_spec.rb b/spec/tabry/runner_spec.rb index 92919cd..f35a594 100644 --- a/spec/tabry/runner_spec.rb +++ b/spec/tabry/runner_spec.rb @@ -28,7 +28,9 @@ it "runs OptionsFinder" do res = instance_double(Tabry::Result) expect(subject).to receive(:parse).with(%w[foo bar]).and_return res - expect(Tabry::OptionsFinder).to receive(:options).with(res, "waz", {}).and_return %w[a b c] + opts_finder = instance_double(Tabry::OptionsFinder) + expect(Tabry::OptionsFinder).to receive(:new).with(res, {}).and_return opts_finder + expect(opts_finder).to receive(:options).with("waz").and_return %w[a b c] expect(subject.options(%w[foo bar], "waz")).to eq(%w[a b c]) end end