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"