From f95b41ba54ac4ae5ad00a1142544423d067c1298 Mon Sep 17 00:00:00 2001 From: "Andrew W. Lee" Date: Mon, 10 Jul 2023 22:11:36 -0700 Subject: [PATCH] Add CLI specs using `aruba` gem (#43) This PR adds `aruba` to the project and also adds some CLI specs. This is my first time using the gem so there may be better ways of doing things. --- Gemfile | 5 +---- exe/annotaterb | 2 +- spec/integration/cli.rb | 31 +++++++++++++++++++++++++++++++ spec/support/aruba.rb | 3 +++ 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 spec/integration/cli.rb create mode 100644 spec/support/aruba.rb diff --git a/Gemfile b/Gemfile index f0d540b6..58e5416e 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ gem "rake" gem "rspec" group :development, :test do + gem "aruba", "~> 2.1.0", require: false gem "byebug" gem "guard-rspec", require: false @@ -17,7 +18,3 @@ group :development, :test do gem "pry-byebug", require: false end end - -group :test do - gem "git", require: false -end diff --git a/exe/annotaterb b/exe/annotaterb index 144d56b5..a152c0b4 100755 --- a/exe/annotaterb +++ b/exe/annotaterb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -unless File.exist?("./Rakefile") || File.exist?("./Gemfile") +if !File.exist?("./Rakefile") && !File.exist?("./Gemfile") abort "Please run annotaterb from the root of the project." end diff --git a/spec/integration/cli.rb b/spec/integration/cli.rb new file mode 100644 index 00000000..7e20f3ff --- /dev/null +++ b/spec/integration/cli.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +RSpec.describe "CLI", type: "aruba" do + context "when running in a non-Rails project directory" do + before do + # Assumes there's no Rakefile or Gemfile + run_command("annotaterb") + end + + let(:error_message) { "Please run annotaterb from the root of the project." } + + it "exits and outputs an error message" do + expect(last_command_started).to have_exit_status(1) + expect(last_command_started).to have_output_on_stderr(error_message) + end + end + + context "when running in a directory with a Rakefile and a Gemfile" do + before do + touch("Rakefile", "Gemfile") + run_command("annotaterb") + end + + let(:help_banner_fragment) { "Usage: annotaterb [command] [options]" } + + it "outputs the help message" do + expect(last_command_started).to be_successfully_executed + expect(last_command_started.stdout).to include(help_banner_fragment) + end + end +end diff --git a/spec/support/aruba.rb b/spec/support/aruba.rb new file mode 100644 index 00000000..c3219676 --- /dev/null +++ b/spec/support/aruba.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require "aruba/rspec"