/
runner_spec.rb
104 lines (78 loc) · 3.64 KB
/
runner_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
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
93
94
95
96
97
98
99
100
101
102
103
104
require 'spec_helper'
describe Propel::Runner do
before do
@git_repository = Propel::GitRepository.new
Propel::GitRepository.should_receive(:new).and_return(@git_repository)
@git_repository.stub!(:changed?).and_return(true)
end
describe ".start" do
it "should not call propel! if there is nothing to push" do
runner = Propel::Runner.new
runner.stub!(:logger).and_return(stub_logger)
@git_repository.should_receive(:changed?).and_return(false)
runner.should_not_receive(:propel!)
runner.start
end
it "should call propel! if there are changes to the current branch" do
runner = Propel::Runner.new
runner.stub!(:logger).and_return(stub_logger)
@git_repository.stub!(:changed?).and_return(true)
@git_repository.stub!(:remote_config).and_return('origin')
@git_repository.stub!(:remote_config).and_return('refs/heads/master')
runner.should_receive(:propel!)
runner.start
end
it "should call propel! if the remote build is configured and passing" do
runner = Propel::Runner.new(%w[ --status-url http://ci.example.com/status ])
runner.stub!(:remote_build_configured?).and_return(true)
runner.stub!(:remote_build_green?).and_return(true)
runner.stub!(:logger).and_return(stub_logger)
runner.should_receive(:propel!)
runner.start
end
it "should call propel! if the remote build is not configured" do
runner = Propel::Runner.new
runner.stub!(:remote_build_configured?).and_return false
runner.should_receive(:propel!)
runner.stub!(:logger).and_return(stub_logger)
runner.logger.should_receive(:warn).with("Remote build is not configured, you should point propel to the status URL of your CI server.")
runner.start
end
class TestError < StandardError ; end
it "should send an alert about the broken build if the remote build is configured but not passing" do
runner = Propel::Runner.new
runner.stub!(:remote_build_configured?).and_return true
runner.stub!(:remote_build_green?).and_return false
runner.should_receive(:alert_broken_build_and_exit).and_raise(TestError.new("Execution should be aborted here"))
runner.should_not_receive(:propel!)
runner.stub!(:logger).and_return(stub_logger)
lambda {
runner.start
}.should raise_error(TestError)
end
it "should call propel! when the remote build is failing if --fix-ci is specified" do
runner = Propel::Runner.new %w[ --fix-ci ]
runner.stub!(:remote_build_configured?).and_return true
runner.logger.should_receive(:puts).with("Thanks for trying to fix the build!", :green)
runner.stub!(:remote_build_passing?).and_return false
runner.should_receive(:propel!)
runner.start
end
it "should call propel! when the remote build is not configured if --fix-ci is specified" do
runner = Propel::Runner.new %w[ --fix-ci ]
runner.stub!(:remote_build_configured?).and_return false
runner.logger.should_receive(:warn).with("Remote build is not configured, you should point propel to the status URL of your CI server.")
runner.should_receive(:propel!)
runner.start
end
it "should wait for the build to pass if the user specifies the --wait option" do
runner = Propel::Runner.new(%w[--wait])
runner.stub!(:remote_build_configured?).and_return true
runner.stub!(:logger).and_return(stub_logger)
runner.should_receive(:remote_build_green?).twice.and_return(false, true)
runner.should_receive(:say_duration).and_yield
runner.should_receive(:propel!)
runner.start
end
end
end