-
-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update #uncommitted_changes? to handle missing Git (#889)
* Update #uncommitted_changes? to handle missing Git - Fix for GitUtils.uncommitted_changes? throwing an error when called in an environment that does not have git installed - Add tests for GitUtils.uncommitted_changes? scenariors - Fixes #888 * Add explicit message when Git is not installed
- Loading branch information
1 parent
e6edd4f
commit 41e4c06
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "spec_helper" | ||
|
||
module ReactOnRails | ||
RSpec.describe GitUtils do | ||
describe ".uncommitted_changes?" do | ||
context "With uncommited git changes" do | ||
subject { "M file/path" } | ||
let(:message_handler) { instance_double("MessageHandler") } | ||
|
||
before do | ||
allow(described_class).to receive(:`).with("git status --porcelain").and_return(subject) | ||
allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) | ||
expect(message_handler).to receive(:add_error) | ||
.with("You have uncommitted code. Please commit or stash your changes before continuing") | ||
end | ||
|
||
it "returns true" do | ||
expect(described_class.uncommitted_changes?(message_handler)).to eq(true) | ||
end | ||
end | ||
|
||
context "With clean git status" do | ||
subject { "" } | ||
let(:message_handler) { instance_double("MessageHandler") } | ||
|
||
before do | ||
allow(described_class).to receive(:`).with("git status --porcelain").and_return(subject) | ||
allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) | ||
expect(message_handler).not_to receive(:add_error) | ||
end | ||
|
||
it "returns false" do | ||
expect(described_class.uncommitted_changes?(message_handler)).to eq(false) | ||
end | ||
end | ||
|
||
context "With git not installed" do | ||
subject { nil } | ||
let(:message_handler) { instance_double("MessageHandler") } | ||
|
||
before do | ||
allow(described_class).to receive(:`).with("git status --porcelain").and_return(subject) | ||
allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) | ||
expect(message_handler).to receive(:add_error) | ||
.with("You do not have Git installed. Please install Git, and commit your changes before continuing") | ||
end | ||
|
||
it "returns true" do | ||
expect(described_class.uncommitted_changes?(message_handler)).to eq(true) | ||
end | ||
end | ||
end | ||
end | ||
end |