Skip to content

Commit

Permalink
fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
evanbattaglia committed Jul 28, 2024
1 parent bf05e60 commit 5e71e71
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 5 deletions.
1 change: 0 additions & 1 deletion lib/tabry/options_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/tabry/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
7 changes: 7 additions & 0 deletions spec/tabry/cli/all_in_one_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
6 changes: 6 additions & 0 deletions spec/tabry/models/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion spec/tabry/models/dir_option_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion spec/tabry/models/file_option_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 3 additions & 1 deletion spec/tabry/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e71e71

Please sign in to comment.