|
1 | 1 | require "git_tracker/prepare_commit_message" |
2 | 2 |
|
3 | 3 | RSpec.describe GitTracker::PrepareCommitMessage do |
4 | | - subject(:prepare_commit_message) { GitTracker::PrepareCommitMessage } |
5 | | - |
6 | | - describe ".run" do |
7 | | - let(:hook) { double("PrepareCommitMessage") } |
8 | | - before do |
9 | | - allow(prepare_commit_message).to receive(:new) { hook } |
10 | | - end |
11 | | - |
12 | | - it "runs the hook" do |
13 | | - expect(hook).to receive(:run) |
14 | | - prepare_commit_message.run("FILE1", "hook_source", "sha1234") |
15 | | - end |
16 | | - end |
17 | | - |
18 | | - describe ".new" do |
| 4 | + describe "initialization" do |
19 | 5 | it "requires the name of the commit message file" do |
20 | | - expect { prepare_commit_message.new }.to raise_error(ArgumentError) |
| 6 | + expect { described_class.new }.to raise_error(ArgumentError) |
21 | 7 | end |
22 | 8 |
|
23 | 9 | it "remembers the name of the commit message file" do |
24 | | - expect(prepare_commit_message.new("FILE1").file).to eq("FILE1") |
| 10 | + expect(described_class.new("FILE1").file).to eq("FILE1") |
25 | 11 | end |
26 | 12 |
|
27 | 13 | it "optionally accepts a message source" do |
28 | | - hook = prepare_commit_message.new("FILE1", "merge").source |
| 14 | + hook = described_class.new("FILE1", "merge").source |
29 | 15 |
|
30 | 16 | expect(hook).to eq("merge") |
31 | 17 | end |
32 | 18 |
|
33 | 19 | it "optionally accepts the SHA-1 of a commit" do |
34 | | - hook = prepare_commit_message.new("FILE1", "commit", "abc1234").commit_sha |
| 20 | + hook = described_class.new("FILE1", "commit", "abc1234").commit_sha |
35 | 21 |
|
36 | 22 | expect(hook).to eq("abc1234") |
37 | 23 | end |
38 | 24 | end |
39 | 25 |
|
40 | | - describe "#run" do |
| 26 | + describe "#call" do |
41 | 27 | let(:hook) { GitTracker::PrepareCommitMessage.new("FILE1") } |
42 | 28 | let(:commit_message) { double("CommitMessage", append: nil) } |
43 | 29 |
|
|
50 | 36 | let(:hook) { described_class.new("FILE2", "commit", "60a086f3") } |
51 | 37 |
|
52 | 38 | it "exits with status code 0" do |
53 | | - expect { hook.run }.to succeed |
| 39 | + expect { hook.call }.to succeed |
54 | 40 | end |
55 | 41 | end |
56 | 42 |
|
57 | 43 | context "branch name without a Pivotal Tracker story number" do |
58 | 44 | let(:story) { nil } |
59 | 45 |
|
60 | 46 | it "exits without updating the commit message" do |
61 | | - expect { hook.run }.to succeed |
| 47 | + expect { hook.call }.to succeed |
62 | 48 | expect(commit_message).to_not have_received(:append) |
63 | 49 | end |
64 | 50 | end |
|
71 | 57 | end |
72 | 58 |
|
73 | 59 | it "appends the number to the commit message" do |
74 | | - hook.run |
| 60 | + hook.call |
75 | 61 | expect(commit_message).to have_received(:append).with("[#8675309]") |
76 | 62 | end |
77 | 63 |
|
|
81 | 67 | end |
82 | 68 |
|
83 | 69 | it "appends the keyword and the story number" do |
84 | | - hook.run |
| 70 | + hook.call |
85 | 71 | expect(commit_message).to have_received(:append).with("[Delivers #8675309]") |
86 | 72 | end |
87 | 73 | end |
|
92 | 78 | end |
93 | 79 |
|
94 | 80 | it "exits without updating the commit message" do |
95 | | - expect { hook.run }.to succeed |
| 81 | + expect { hook.call }.to succeed |
96 | 82 | expect(commit_message).to_not have_received(:append) |
97 | 83 | end |
98 | 84 | end |
|
0 commit comments