Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI specs using aruba gem #43

Merged
merged 7 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"