bamboo-client 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,12 @@ Feature: Bamboo REST client
20
20
  When I fetch all results
21
21
  Then I should get a list of results
22
22
  And all results should have a state
23
-
23
+
24
+ Scenario: Fetch result for specific plan
25
+ When I fetch results for a specific plan
26
+ Then I should get a list of results
27
+ And all results should have a state
28
+
24
29
  Scenario: Authenticated API
25
30
  When I log in
26
31
  Then I should get a session ID
@@ -44,3 +44,8 @@ end
44
44
  Then /^I should get a session ID$/ do
45
45
  client.cookies.has_key? :JSESSIONID
46
46
  end
47
+
48
+ When /^I fetch results for a specific plan$/ do
49
+ key = client.plans.first.key
50
+ @results = client.results_for key
51
+ end
@@ -41,6 +41,10 @@ module Bamboo
41
41
  get("result/").auto_expand Result, @http
42
42
  end
43
43
 
44
+ def results_for(key)
45
+ get("result/#{URI.escape key}").auto_expand Result, @http
46
+ end
47
+
44
48
  private
45
49
 
46
50
  def get(what, params = nil)
@@ -113,6 +117,31 @@ module Bamboo
113
117
  @data.fetch("lifeCycleState").downcase.to_sym
114
118
  end
115
119
 
120
+ def successful?
121
+ state == :successful
122
+ end
123
+
124
+ def reason
125
+ details.fetch('buildReason')
126
+ end
127
+
128
+ def relative_time
129
+ details.fetch('buildRelativeTime')
130
+ end
131
+ alias_method :relative_date, :relative_time
132
+
133
+ def failed_test_count
134
+ details.fetch('failedTestCount')
135
+ end
136
+
137
+ def successful_test_count
138
+ details.fetch('successfulTestCount')
139
+ end
140
+
141
+ def start_time
142
+ Time.parse details.fetch('buildStartedTime')
143
+ end
144
+
116
145
  def number
117
146
  @data['number']
118
147
  end
@@ -121,6 +150,10 @@ module Bamboo
121
150
  @data['key']
122
151
  end
123
152
 
153
+ def plan_key
154
+ key[/^(.+)-\d+$/, 1]
155
+ end
156
+
124
157
  def id
125
158
  @data['id']
126
159
  end
@@ -142,6 +175,10 @@ module Bamboo
142
175
 
143
176
  private
144
177
 
178
+ def details
179
+ @details ||= @http.get(uri).data
180
+ end
181
+
145
182
  def fetch_details(expand)
146
183
  @http.get(uri, :expand => expand)
147
184
  end
@@ -1,5 +1,5 @@
1
1
  module Bamboo
2
2
  module Client
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -11,7 +11,7 @@ module Bamboo
11
11
  username = 'something'
12
12
  password = 'somethingelse'
13
13
  http.should_receive(:get_cookies).with(
14
- '/rest/api/latest/plan',
14
+ '/rest/api/latest/plan',
15
15
  {:os_authType => 'basic', :os_username => username, :os_password => password}).
16
16
  and_return({'JSESSIONID' => '1'})
17
17
  client.login username, password
@@ -48,6 +48,15 @@ module Bamboo
48
48
  client.results.should == %w[foo bar]
49
49
  end
50
50
 
51
+ it "should be able to fetch results for a specific key" do
52
+ document.should_receive(:auto_expand).with(Rest::Result, http).and_return %w[foo bar]
53
+
54
+ http.should_receive(:get).with("/rest/api/latest/result/SOME-KEY", nil, nil).
55
+ and_return(document)
56
+
57
+ client.results_for("SOME-KEY").should == %w[foo bar]
58
+ end
59
+
51
60
  describe Rest::Plan do
52
61
  let(:data) { json_fixture("plan") }
53
62
  let(:plan) { Rest::Plan.new data, http }
@@ -104,10 +113,18 @@ module Bamboo
104
113
  result.key.should == "IAD-DEFAULT-5388"
105
114
  end
106
115
 
116
+ it "has a plan key" do
117
+ result.plan_key.should == "IAD-DEFAULT"
118
+ end
119
+
107
120
  it "has a state" do
108
121
  result.state.should == :successful
109
122
  end
110
123
 
124
+ it "knows if the build was successful" do
125
+ result.should be_successful
126
+ end
127
+
111
128
  it "has an id" do
112
129
  result.id.should == 8487295
113
130
  end
@@ -124,10 +141,36 @@ module Bamboo
124
141
  result.url.should == "http://localhost:8085/rest/api/latest/result/IAD-DEFAULT-5388"
125
142
  end
126
143
 
127
- it "has a list of changes" do
128
- # TODO: arg expectation
129
- http.should_receive(:get).and_return Http::Json::Doc.new(json_fixture("result_with_changes"))
130
- result.changes.first.should be_kind_of(Rest::Change)
144
+ context "with details" do
145
+ before do
146
+ # TODO: arg/uri expectation?
147
+ http.should_receive(:get).and_return Http::Json::Doc.new(json_fixture("result_with_changes"))
148
+ end
149
+
150
+ it "has a list of changes" do
151
+ result.changes.first.should be_kind_of(Rest::Change)
152
+ end
153
+
154
+ it "has a build reason" do
155
+ result.reason.should == "Code has changed"
156
+ end
157
+
158
+ it "has a start time" do
159
+ result.start_time.should == Time.parse("2011-01-20T10:08:41.000+01:00")
160
+ end
161
+ it "has a relative date" do
162
+ result.relative_date.should == "4 weeks ago"
163
+ result.relative_time.should == "4 weeks ago"
164
+ end
165
+
166
+ it "has a failed test count" do
167
+ result.failed_test_count.should == 0
168
+ end
169
+
170
+ it "has a successful test count" do
171
+ result.successful_test_count.should == 13
172
+ end
173
+
131
174
  end
132
175
  end
133
176
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bamboo-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-17 00:00:00.000000000 Z
13
+ date: 2012-06-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec