Skip to content

Commit

Permalink
Add CLI specs using aruba gem (#43)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
drwl authored Jul 11, 2023
1 parent bb37f5b commit f95b41b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -17,7 +18,3 @@ group :development, :test do
gem "pry-byebug", require: false
end
end

group :test do
gem "git", require: false
end
2 changes: 1 addition & 1 deletion exe/annotaterb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
31 changes: 31 additions & 0 deletions spec/integration/cli.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions spec/support/aruba.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require "aruba/rspec"

0 comments on commit f95b41b

Please sign in to comment.