-
-
Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathgit_utils_spec.rb
56 lines (46 loc) · 1.98 KB
/
git_utils_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 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
end
end
end