-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathgit_spec.rb
More file actions
92 lines (72 loc) · 2 KB
/
git_spec.rb
File metadata and controls
92 lines (72 loc) · 2 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require "spec_helper"
describe Bummr::Git do
before(:all) do
puts "\n<< Bummr::Git >>\n"
end
describe "#add" do
it "stages specified files with git" do
git = stub_git
files = "Gemfile Gemfile.lock"
git.add(files)
expect(git).to have_received(:system).with(
"git add #{files}"
)
end
end
describe "#commit" do
it "logs the commit" do
git = stub_git
commit_message = "Update Foo from 0.0.1 to 0.0.2"
git.commit(commit_message)
expect(git).to have_received(:log).with(
/Commit: #{commit_message}/
)
end
it "commits with a message" do
git = stub_git
commit_message = "Update Foo from 0.0.1 to 0.0.2"
git.commit(commit_message)
expect(git).to have_received(:system).with(
"git commit -m '#{commit_message}'"
)
end
describe "when BUMMR_GIT_COMMIT is defined" do
it "commits using defined value" do
allow(ENV).to receive(:fetch).with("BUMMR_GIT_COMMIT").and_return("git commit --no-verify")
git = stub_git
commit_message = "Update Foo from 0.0.1 to 0.0.2"
git.commit(commit_message)
expect(git).to have_received(:system).with(
"git commit --no-verify -m '#{commit_message}'"
)
end
end
end
describe "#rebase_interactive" do
it "runs git interactive rebase to the given sha" do
git = stub_git
sha = "b39dcd8"
git.rebase_interactive(sha)
expect(git).to have_received(:system).with(
"git rebase -i #{BASE_BRANCH}"
)
end
end
describe "#message" do
it "displays the commit message for a given sha" do
git = stub_git
sha = "b39dcd8"
git.message(sha)
expect(git).to have_received(:`).with(
"git log --pretty=format:'%s' -n 1 #{sha}"
)
end
end
def stub_git
git = Bummr::Git.clone.instance
allow(git).to receive(:log)
allow(git).to receive(:system)
allow(git).to receive(:`)
git
end
end