build_eval 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/build_eval/http.rb +16 -0
- data/lib/build_eval/monitor/base.rb +13 -0
- data/lib/build_eval/monitor/composite.rb +17 -0
- data/lib/build_eval/monitor/server.rb +18 -0
- data/lib/build_eval/result/build_result.rb +41 -0
- data/lib/build_eval/result/composite_result.rb +25 -0
- data/lib/build_eval/result/server_result.rb +26 -0
- data/lib/build_eval/result/status.rb +54 -0
- data/lib/build_eval/{ci_server → server}/decorator.rb +3 -3
- data/lib/build_eval/server/team_city.rb +28 -0
- data/lib/build_eval/server/travis.rb +26 -0
- data/lib/build_eval/version.rb +1 -1
- data/lib/build_eval.rb +13 -8
- data/spec/lib/build_eval/http_spec.rb +82 -0
- data/spec/lib/build_eval/monitor/base_spec.rb +29 -0
- data/spec/lib/build_eval/monitor/composite_spec.rb +38 -0
- data/spec/lib/build_eval/monitor/server_spec.rb +43 -0
- data/spec/lib/build_eval/{build_result_spec.rb → result/build_result_spec.rb} +9 -9
- data/spec/lib/build_eval/result/composite_result_spec.rb +84 -0
- data/spec/lib/build_eval/result/server_result_spec.rb +92 -0
- data/spec/lib/build_eval/{status_spec.rb → result/status_spec.rb} +36 -15
- data/spec/lib/build_eval/server/decorator_spec.rb +97 -0
- data/spec/lib/build_eval/server/team_city_spec.rb +119 -0
- data/spec/lib/build_eval/server/travis_spec.rb +92 -0
- data/spec/lib/build_eval_spec.rb +8 -8
- metadata +35 -20
- data/lib/build_eval/build_result.rb +0 -39
- data/lib/build_eval/build_results.rb +0 -23
- data/lib/build_eval/ci_server/team_city.rb +0 -33
- data/lib/build_eval/monitor.rb +0 -15
- data/lib/build_eval/status.rb +0 -51
- data/spec/lib/build_eval/build_results_spec.rb +0 -82
- data/spec/lib/build_eval/ci_server/decorator_spec.rb +0 -97
- data/spec/lib/build_eval/ci_server/team_city_spec.rb +0 -111
- data/spec/lib/build_eval/monitor_spec.rb +0 -37
@@ -0,0 +1,84 @@
|
|
1
|
+
describe BuildEval::Result::CompositeResult do
|
2
|
+
|
3
|
+
let(:results) { (1..2).map { double("BuildEval::Result") } }
|
4
|
+
|
5
|
+
let(:composite_result) { described_class.new(results) }
|
6
|
+
|
7
|
+
describe "#status" do
|
8
|
+
|
9
|
+
let(:statuses) { results.map { instance_double(BuildEval::Result::Status) } }
|
10
|
+
|
11
|
+
subject { composite_result.status }
|
12
|
+
|
13
|
+
before(:example) do
|
14
|
+
results.zip(statuses).each { |result, status| allow(result).to receive(:status).and_return(status) }
|
15
|
+
end
|
16
|
+
|
17
|
+
before(:example) { allow(BuildEval::Result::Status).to receive(:effective_status) }
|
18
|
+
|
19
|
+
it "determines the status of the results" do
|
20
|
+
results.each { |underlying_array| expect(underlying_array).to receive(:status) }
|
21
|
+
|
22
|
+
subject
|
23
|
+
end
|
24
|
+
|
25
|
+
it "determines the effective status of the result statuses" do
|
26
|
+
expect(BuildEval::Result::Status).to receive(:effective_status).with(statuses)
|
27
|
+
|
28
|
+
subject
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns the effective status" do
|
32
|
+
effective_status = instance_double(BuildEval::Result::Status)
|
33
|
+
allow(BuildEval::Result::Status).to receive(:effective_status).and_return(effective_status)
|
34
|
+
|
35
|
+
expect(subject).to eql(effective_status)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#unsuccessful" do
|
41
|
+
|
42
|
+
let(:unsuccessful_builds_array) { results.map { (1..3).map { instance_double(BuildEval::Result::BuildResult) } } }
|
43
|
+
|
44
|
+
subject { composite_result.unsuccessful }
|
45
|
+
|
46
|
+
before(:example) do
|
47
|
+
results.zip(unsuccessful_builds_array).each do |result, unsuccessful_builds|
|
48
|
+
allow(result).to receive(:unsuccessful).and_return(unsuccessful_builds)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "determines the unsuccessful builds from the results" do
|
53
|
+
results.each { |result| expect(result).to receive(:unsuccessful) }
|
54
|
+
|
55
|
+
subject
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns all unsuccessful builds" do
|
59
|
+
expect(subject).to eql(unsuccessful_builds_array.flatten)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#to_s" do
|
65
|
+
|
66
|
+
let(:results_string_representations) { (1..results.length).map { |i| "Result #{i}" } }
|
67
|
+
|
68
|
+
subject { composite_result.to_s }
|
69
|
+
|
70
|
+
before(:example) do
|
71
|
+
results.zip(results_string_representations).each do |result, string_representation|
|
72
|
+
allow(result).to receive(:to_s).and_return(string_representation)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns a string containing the string representation of each result" do
|
77
|
+
results_string_representations.each do |string_representation|
|
78
|
+
expect(subject).to include(string_representation)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
describe BuildEval::Result::ServerResult do
|
2
|
+
|
3
|
+
let(:server) { double("BuildEval::Server") }
|
4
|
+
let(:build_results) { (1..3).map { instance_double(BuildEval::Result::BuildResult) } }
|
5
|
+
|
6
|
+
let(:server_result) { described_class.new(server, build_results) }
|
7
|
+
|
8
|
+
describe "#status" do
|
9
|
+
|
10
|
+
let(:statuses) { build_results.map { instance_double(BuildEval::Result::Status) } }
|
11
|
+
|
12
|
+
subject { server_result.status }
|
13
|
+
|
14
|
+
before(:example) do
|
15
|
+
build_results.zip(statuses).each do |build_result, status|
|
16
|
+
allow(build_result).to receive(:status).and_return(status)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "determines the effective status of the build results" do
|
21
|
+
expect(BuildEval::Result::Status).to receive(:effective_status).with(statuses)
|
22
|
+
|
23
|
+
subject
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the effective status" do
|
27
|
+
status = instance_double(BuildEval::Result::Status)
|
28
|
+
allow(BuildEval::Result::Status).to receive(:effective_status).and_return(status)
|
29
|
+
|
30
|
+
expect(subject).to be(status)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#unsuccessful" do
|
36
|
+
|
37
|
+
subject { server_result.unsuccessful }
|
38
|
+
|
39
|
+
before(:example) do
|
40
|
+
build_results.each do |build_result|
|
41
|
+
allow(build_result).to receive(:unsuccessful?).and_return(unsuccessful_results.include?(build_result))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when some build results are unsuccessful" do
|
46
|
+
|
47
|
+
let(:unsuccessful_results) { [ build_results[0], build_results[2] ] }
|
48
|
+
|
49
|
+
it "returns the unsuccessful build results" do
|
50
|
+
expect(subject).to eql(unsuccessful_results)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when no build results are unsuccessful" do
|
56
|
+
|
57
|
+
let(:unsuccessful_results) { [] }
|
58
|
+
|
59
|
+
it "returns an empty array" do
|
60
|
+
expect(subject).to eql([])
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#to_s" do
|
68
|
+
|
69
|
+
let(:server_string_representation) { "Server description" }
|
70
|
+
let(:result_string_representations) { build_results.each_with_index.map { |_, i| "Build result ##{i}" } }
|
71
|
+
|
72
|
+
subject { server_result.to_s }
|
73
|
+
|
74
|
+
before(:example) { allow(server).to receive(:to_s).and_return(server_string_representation) }
|
75
|
+
|
76
|
+
before(:example) do
|
77
|
+
build_results.zip(result_string_representations).each do |build_result, string|
|
78
|
+
allow(build_result).to receive(:to_s).and_return(string)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "contains the string representation of the server" do
|
83
|
+
expect(subject).to include(server_string_representation)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "contains the string representation of each result" do
|
87
|
+
result_string_representations.each { |string| expect(subject).to include(string) }
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe BuildEval::Status do
|
1
|
+
describe BuildEval::Result::Status do
|
2
2
|
|
3
3
|
describe "::find" do
|
4
4
|
|
@@ -9,7 +9,17 @@ describe BuildEval::Status do
|
|
9
9
|
let(:name) { "UNKNOWN" }
|
10
10
|
|
11
11
|
it "returns the constant" do
|
12
|
-
expect(subject).to be(BuildEval::Status::UNKNOWN)
|
12
|
+
expect(subject).to be(BuildEval::Result::Status::UNKNOWN)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when the name matches a status constant name with different casing" do
|
18
|
+
|
19
|
+
let(:name) { "Success" }
|
20
|
+
|
21
|
+
it "returns the constant" do
|
22
|
+
expect(subject).to be(BuildEval::Result::Status::SUCCESS)
|
13
23
|
end
|
14
24
|
|
15
25
|
end
|
@@ -32,30 +42,40 @@ describe BuildEval::Status do
|
|
32
42
|
|
33
43
|
context "when a single status is provided" do
|
34
44
|
|
35
|
-
let(:statuses) { [ BuildEval::Status::UNKNOWN ] }
|
45
|
+
let(:statuses) { [ BuildEval::Result::Status::UNKNOWN ] }
|
36
46
|
|
37
47
|
it "returns the status" do
|
38
|
-
expect(subject).to eql(BuildEval::Status::UNKNOWN)
|
48
|
+
expect(subject).to eql(BuildEval::Result::Status::UNKNOWN)
|
39
49
|
end
|
40
50
|
|
41
51
|
end
|
42
52
|
|
43
53
|
context "when the statuses are ordered in descending severity" do
|
44
54
|
|
45
|
-
let(:statuses)
|
55
|
+
let(:statuses) do
|
56
|
+
[ BuildEval::Result::Status::ERROR,
|
57
|
+
BuildEval::Result::Status::FAILURE,
|
58
|
+
BuildEval::Result::Status::UNKNOWN,
|
59
|
+
BuildEval::Result::Status::SUCCESS ]
|
60
|
+
end
|
46
61
|
|
47
62
|
it "returns the most severe status" do
|
48
|
-
expect(subject).to eql(BuildEval::Status::
|
63
|
+
expect(subject).to eql(BuildEval::Result::Status::ERROR)
|
49
64
|
end
|
50
65
|
|
51
66
|
end
|
52
67
|
|
53
68
|
context "when the statuses are ordered in ascending severity" do
|
54
69
|
|
55
|
-
let(:statuses)
|
70
|
+
let(:statuses) do
|
71
|
+
[ BuildEval::Result::Status::SUCCESS,
|
72
|
+
BuildEval::Result::Status::UNKNOWN,
|
73
|
+
BuildEval::Result::Status::FAILURE,
|
74
|
+
BuildEval::Result::Status::ERROR ]
|
75
|
+
end
|
56
76
|
|
57
77
|
it "returns the most severe status" do
|
58
|
-
expect(subject).to eql(BuildEval::Status::
|
78
|
+
expect(subject).to eql(BuildEval::Result::Status::ERROR)
|
59
79
|
end
|
60
80
|
|
61
81
|
end
|
@@ -68,7 +88,7 @@ describe BuildEval::Status do
|
|
68
88
|
|
69
89
|
context "when the status is SUCCESS" do
|
70
90
|
|
71
|
-
let(:status) { BuildEval::Status::SUCCESS }
|
91
|
+
let(:status) { BuildEval::Result::Status::SUCCESS }
|
72
92
|
|
73
93
|
it "returns false" do
|
74
94
|
expect(subject).to be(false)
|
@@ -77,8 +97,9 @@ describe BuildEval::Status do
|
|
77
97
|
end
|
78
98
|
|
79
99
|
{
|
80
|
-
"
|
81
|
-
"
|
100
|
+
"UNKNOWN" => BuildEval::Result::Status::UNKNOWN,
|
101
|
+
"FAILURE" => BuildEval::Result::Status::FAILURE,
|
102
|
+
"ERROR" => BuildEval::Result::Status::ERROR
|
82
103
|
}.each do |name, status|
|
83
104
|
|
84
105
|
context "when the status is #{name}" do
|
@@ -99,11 +120,11 @@ describe BuildEval::Status do
|
|
99
120
|
|
100
121
|
subject { status.to_sym }
|
101
122
|
|
102
|
-
{ SUCCESS: :success!, FAILURE: :failed!,
|
123
|
+
{ SUCCESS: :success!, UNKNOWN: :warning!, FAILURE: :failed!, ERROR: :failed! }.each do |name, expected_symbol|
|
103
124
|
|
104
125
|
context "when the status is #{name}" do
|
105
126
|
|
106
|
-
let(:status) { BuildEval::Status.const_get(name) }
|
127
|
+
let(:status) { BuildEval::Result::Status.const_get(name) }
|
107
128
|
|
108
129
|
it "returns success!" do
|
109
130
|
expect(subject).to eql(expected_symbol)
|
@@ -119,11 +140,11 @@ describe BuildEval::Status do
|
|
119
140
|
|
120
141
|
subject { status.to_s }
|
121
142
|
|
122
|
-
{ SUCCESS: "succeeded", FAILURE: "failed",
|
143
|
+
{ SUCCESS: "succeeded", UNKNOWN: "unknown", FAILURE: "failed", ERROR: "errored" }.each do |name, expected_string|
|
123
144
|
|
124
145
|
context "when the status is #{name}" do
|
125
146
|
|
126
|
-
let(:status) { BuildEval::Status.const_get(name) }
|
147
|
+
let(:status) { BuildEval::Result::Status.const_get(name) }
|
127
148
|
|
128
149
|
it "returns success!" do
|
129
150
|
expect(subject).to eql(expected_string)
|
@@ -0,0 +1,97 @@
|
|
1
|
+
describe BuildEval::Server::Decorator do
|
2
|
+
|
3
|
+
let(:server) { double("BuildEval::Server::Server") }
|
4
|
+
|
5
|
+
let(:decorator) { described_class.new(server) }
|
6
|
+
|
7
|
+
describe "#build_result" do
|
8
|
+
|
9
|
+
let(:build_name) { "some build name" }
|
10
|
+
|
11
|
+
subject { decorator.build_result(build_name) }
|
12
|
+
|
13
|
+
it "delegates to the decorated server" do
|
14
|
+
expect(server).to receive(:build_result).with(build_name)
|
15
|
+
|
16
|
+
subject
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when the decorated server returns a result" do
|
20
|
+
|
21
|
+
let(:build_result) { instance_double(BuildEval::Result::BuildResult) }
|
22
|
+
|
23
|
+
before(:example) { allow(server).to receive(:build_result).and_return(build_result) }
|
24
|
+
|
25
|
+
it "returns the result" do
|
26
|
+
expect(subject).to eql(build_result)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when the decorated server raises an error" do
|
32
|
+
|
33
|
+
before(:example) { allow(server).to receive(:build_result).and_raise("Forced error") }
|
34
|
+
|
35
|
+
it "creates an unknown result" do
|
36
|
+
expect(BuildEval::Result::BuildResult).to receive(:unknown).with(build_name)
|
37
|
+
|
38
|
+
subject
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the unknown result" do
|
42
|
+
unknown_build_result = instance_double(BuildEval::Result::BuildResult)
|
43
|
+
allow(BuildEval::Result::BuildResult).to receive(:unknown).and_return(unknown_build_result)
|
44
|
+
|
45
|
+
expect(subject).to eql(unknown_build_result)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#monitor" do
|
53
|
+
|
54
|
+
let(:build_names) { (1..3).map { |i| "build##{i}" } }
|
55
|
+
|
56
|
+
subject { decorator.monitor(*build_names) }
|
57
|
+
|
58
|
+
it "creates a server monitor for the decorated server" do
|
59
|
+
expect(BuildEval::Monitor::Server).to receive(:new).with(hash_including(server: server))
|
60
|
+
|
61
|
+
subject
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns the server monitor" do
|
65
|
+
monitor = instance_double(BuildEval::Monitor::Server)
|
66
|
+
allow(BuildEval::Monitor::Server).to receive(:new).and_return(monitor)
|
67
|
+
|
68
|
+
expect(subject).to eql(monitor)
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when an array of build names is provided" do
|
72
|
+
|
73
|
+
subject { decorator.monitor(build_names) }
|
74
|
+
|
75
|
+
it "creates a server monitor for the provided build names" do
|
76
|
+
expect(BuildEval::Monitor::Server).to receive(:new).with(hash_including(build_names: build_names))
|
77
|
+
|
78
|
+
subject
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when variable argument list of build names is provided" do
|
84
|
+
|
85
|
+
subject { decorator.monitor(*build_names) }
|
86
|
+
|
87
|
+
it "creates a server monitor for the provided build names" do
|
88
|
+
expect(BuildEval::Monitor::Server).to receive(:new).with(hash_including(build_names: build_names))
|
89
|
+
|
90
|
+
subject
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
describe BuildEval::Server::TeamCity do
|
2
|
+
|
3
|
+
let(:uri) { "https://some.teamcity.server" }
|
4
|
+
let(:username) { "some_username" }
|
5
|
+
let(:password) { "some_password" }
|
6
|
+
|
7
|
+
let(:team_city) { described_class.new(uri: uri, username: username, password: password) }
|
8
|
+
|
9
|
+
describe "#build_result" do
|
10
|
+
|
11
|
+
let(:build_name) { "some_build_name" }
|
12
|
+
let(:response_code) { nil }
|
13
|
+
let(:response_message) { nil }
|
14
|
+
let(:response_body) { nil }
|
15
|
+
let(:response) do
|
16
|
+
instance_double(Net::HTTPResponse, code: response_code, message: response_message, body: response_body)
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { team_city.build_result(build_name) }
|
20
|
+
|
21
|
+
before(:example) { allow(BuildEval::Http).to receive(:get).and_return(response) }
|
22
|
+
|
23
|
+
it "issues a get request for the build" do
|
24
|
+
expected_uri = "#{uri}/httpAuth/app/rest/buildTypes/id:#{build_name}/builds"
|
25
|
+
expect(BuildEval::Http).to receive(:get).with(expected_uri, anything)
|
26
|
+
|
27
|
+
subject rescue Exception
|
28
|
+
end
|
29
|
+
|
30
|
+
it "issues a get request with the provided basic authentication credentials" do
|
31
|
+
expect(BuildEval::Http).to receive(:get).with(anything, username: username, password: password)
|
32
|
+
|
33
|
+
subject rescue Exception
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when the server responds with build results" do
|
37
|
+
|
38
|
+
let(:response_code) { "200" }
|
39
|
+
let(:response_message) { "OK" }
|
40
|
+
let(:latest_build_status) { "FAILED" }
|
41
|
+
let(:response_body) do
|
42
|
+
<<-RESPONSE
|
43
|
+
<builds count="3" href="/httpAuth/app/rest/buildTypes/#{build_name}/builds/" nextHref="/httpAuth/app/rest/buildTypes/#{build_name}/builds/?count=3&start=3">
|
44
|
+
<build id="87735" buildTypeId="#{build_name}" number="2062" status="#{latest_build_status}" state="finished" href="/httpAuth/app/rest/builds/id:87735" webUrl="#{uri}/viewLog.html?buildId=87735&buildTypeId=#{build_name}"/>
|
45
|
+
<build id="87723" buildTypeId="#{build_name}" number="2061" status="SUCCESS" state="finished" href="/httpAuth/app/rest/builds/id:87723" webUrl="#{uri}/viewLog.html?buildId=87723&buildTypeId=#{build_name}"/>
|
46
|
+
<build id="87658" buildTypeId="#{build_name}" number="2060" status="SUCCESS" state="finished" href="/httpAuth/app/rest/builds/id:87658" webUrl="#{uri}/viewLog.html?buildId=87658&buildTypeId=#{build_name}"/>
|
47
|
+
</builds>
|
48
|
+
RESPONSE
|
49
|
+
end
|
50
|
+
|
51
|
+
it "creates a build result containing the build name" do
|
52
|
+
expect(BuildEval::Result::BuildResult).to receive(:create).with(hash_including(build_name: build_name))
|
53
|
+
|
54
|
+
subject
|
55
|
+
end
|
56
|
+
|
57
|
+
it "creates a build result containing the latest build status" do
|
58
|
+
expect(BuildEval::Result::BuildResult).to(
|
59
|
+
receive(:create).with(hash_including(status_name: latest_build_status))
|
60
|
+
)
|
61
|
+
|
62
|
+
subject
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns the created result" do
|
66
|
+
build_result = instance_double(BuildEval::Result::BuildResult)
|
67
|
+
allow(BuildEval::Result::BuildResult).to receive(:create).and_return(build_result)
|
68
|
+
|
69
|
+
expect(subject).to eql(build_result)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when the server authentication request fails" do
|
75
|
+
|
76
|
+
let(:response_code) { "401" }
|
77
|
+
let(:response_message) { "Unauthorized" }
|
78
|
+
let(:response_body) { "Incorrect username or password" }
|
79
|
+
|
80
|
+
it "raises an error" do
|
81
|
+
expect { subject }.to raise_error(/Unauthorized/)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
context "when the build is not found" do
|
87
|
+
|
88
|
+
let(:response_code) { "404" }
|
89
|
+
let(:response_message) { "Not Found" }
|
90
|
+
let(:response_body) do
|
91
|
+
<<-BODY
|
92
|
+
Error has occurred during request processing (Not Found).
|
93
|
+
Error: jetbrains.buildServer.server.rest.errors.NotFoundException: No build type nor template is found by id '#{build_name}'.
|
94
|
+
BODY
|
95
|
+
end
|
96
|
+
|
97
|
+
it "raises an error" do
|
98
|
+
expect { subject }.to raise_error(/Not Found/)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#to_s" do
|
106
|
+
|
107
|
+
subject { team_city.to_s }
|
108
|
+
|
109
|
+
it "returns a string indicating it is a TeamCity server" do
|
110
|
+
expect(subject).to include("TeamCity")
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns a string containing the uri to the server" do
|
114
|
+
expect(subject).to include(uri)
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
describe BuildEval::Server::Travis do
|
2
|
+
|
3
|
+
let(:username) { "some_username" }
|
4
|
+
|
5
|
+
let(:travis) { described_class.new(username: username) }
|
6
|
+
|
7
|
+
describe "#build_result" do
|
8
|
+
|
9
|
+
let(:build_name) { "some_build_name" }
|
10
|
+
let(:response_code) { nil }
|
11
|
+
let(:response_message) { nil }
|
12
|
+
let(:response_body) { nil }
|
13
|
+
let(:response) do
|
14
|
+
instance_double(Net::HTTPResponse, code: response_code, message: response_message, body: response_body)
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { travis.build_result(build_name) }
|
18
|
+
|
19
|
+
before(:example) { allow(BuildEval::Http).to receive(:get).and_return(response) }
|
20
|
+
|
21
|
+
it "issues a get request for the build" do
|
22
|
+
expected_uri = "https://api.travis-ci.org/repositories/#{username}/#{build_name}/cc.xml"
|
23
|
+
expect(BuildEval::Http).to receive(:get).with(expected_uri)
|
24
|
+
|
25
|
+
subject rescue Exception
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when the server responds with build results" do
|
29
|
+
|
30
|
+
let(:response_code) { "200" }
|
31
|
+
let(:response_message) { "OK" }
|
32
|
+
let(:latest_build_status) { "Success" }
|
33
|
+
let(:response_body) do
|
34
|
+
<<-RESPONSE
|
35
|
+
<Projects>
|
36
|
+
<Project name="#{username}/#{build_name}" activity="Sleeping" lastBuildStatus="#{latest_build_status}" lastBuildLabel="2" lastBuildTime="2015-08-13T08:31:27.000+0000" webUrl="https://travis-ci.org/#{username}/#{build_name}" />
|
37
|
+
</Projects>
|
38
|
+
RESPONSE
|
39
|
+
end
|
40
|
+
|
41
|
+
it "creates a build result containing the build name" do
|
42
|
+
expect(BuildEval::Result::BuildResult).to receive(:create).with(hash_including(build_name: build_name))
|
43
|
+
|
44
|
+
subject
|
45
|
+
end
|
46
|
+
|
47
|
+
it "creates a build result containing the latest build status" do
|
48
|
+
expect(BuildEval::Result::BuildResult).to(
|
49
|
+
receive(:create).with(hash_including(status_name: latest_build_status))
|
50
|
+
)
|
51
|
+
|
52
|
+
subject
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns the created result" do
|
56
|
+
build_result = instance_double(BuildEval::Result::BuildResult)
|
57
|
+
allow(BuildEval::Result::BuildResult).to receive(:create).and_return(build_result)
|
58
|
+
|
59
|
+
expect(subject).to eql(build_result)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when the build is not found" do
|
65
|
+
|
66
|
+
let(:response_code) { "404" }
|
67
|
+
let(:response_message) { "Not Found" }
|
68
|
+
let(:response_body) { { "file" => "not found" }.to_json }
|
69
|
+
|
70
|
+
it "raises an error" do
|
71
|
+
expect { subject }.to raise_error(/Not Found/)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#to_s" do
|
79
|
+
|
80
|
+
subject { travis.to_s }
|
81
|
+
|
82
|
+
it "returns a string indicating it uses the Travis CI service" do
|
83
|
+
expect(subject).to include("Travis CI")
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns a string containing the username" do
|
87
|
+
expect(subject).to include(username)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
data/spec/lib/build_eval_spec.rb
CHANGED
@@ -2,7 +2,7 @@ describe BuildEval do
|
|
2
2
|
|
3
3
|
describe "::server" do
|
4
4
|
|
5
|
-
class BuildEval::
|
5
|
+
class BuildEval::Server::TestableServer
|
6
6
|
|
7
7
|
def initialize(_args)
|
8
8
|
# Intentionally blank
|
@@ -17,28 +17,28 @@ describe BuildEval do
|
|
17
17
|
subject { described_class.server(args) }
|
18
18
|
|
19
19
|
it "constructs an instance of the server with the provided type" do
|
20
|
-
expect(BuildEval::
|
20
|
+
expect(BuildEval::Server::TestableServer).to receive(:new)
|
21
21
|
|
22
22
|
subject
|
23
23
|
end
|
24
24
|
|
25
25
|
it "constructs the instance with additional arguments" do
|
26
|
-
expect(BuildEval::
|
26
|
+
expect(BuildEval::Server::TestableServer).to receive(:new).with(server_arguments)
|
27
27
|
|
28
28
|
subject
|
29
29
|
end
|
30
30
|
|
31
31
|
it "decorates the server with standard server behaviour" do
|
32
|
-
server = instance_double(BuildEval::
|
33
|
-
allow(BuildEval::
|
34
|
-
expect(BuildEval::
|
32
|
+
server = instance_double(BuildEval::Server::TestableServer)
|
33
|
+
allow(BuildEval::Server::TestableServer).to receive(:new).and_return(server)
|
34
|
+
expect(BuildEval::Server::Decorator).to receive(:new).with(server)
|
35
35
|
|
36
36
|
subject
|
37
37
|
end
|
38
38
|
|
39
39
|
it "returns the decorated server" do
|
40
|
-
server_decorator = instance_double(BuildEval::
|
41
|
-
allow(BuildEval::
|
40
|
+
server_decorator = instance_double(BuildEval::Server::Decorator)
|
41
|
+
allow(BuildEval::Server::Decorator).to receive(:new).and_return(server_decorator)
|
42
42
|
|
43
43
|
expect(subject).to eql(server_decorator)
|
44
44
|
end
|