bamboo-client 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,7 @@ Feature: Bamboo Remote client
10
10
  Scenario: Fetch build names
11
11
  When I fetch all build names
12
12
  Then I should get a list of builds
13
+ And I should be able to get the latest result
13
14
 
14
15
  Scenario: Fetch a build result
15
16
  When I fetch a build result
@@ -15,7 +15,6 @@ Then /^I should get a list of builds$/ do
15
15
  @builds.each { |e| e.should be_kind_of(Bamboo::Client::Remote::Build) }
16
16
  end
17
17
 
18
-
19
18
  When /^I fetch a build result$/ do
20
19
  builds = client.builds
21
20
  build_key = builds.first.key
@@ -31,3 +30,6 @@ Then /^the build result should have a state$/ do
31
30
  @build_result.state.should be_kind_of(Symbol)
32
31
  end
33
32
 
33
+ Then /^I should be able to get the latest result$/ do
34
+ @builds.first.latest_results.should be_kind_of(Bamboo::Client::Remote::BuildResult)
35
+ end
@@ -18,15 +18,15 @@ module Bamboo
18
18
  @doc.css(css).text
19
19
  end
20
20
 
21
- def objects_for(selector, klass)
22
- @doc.css(selector).map { |e| klass.new(e) }
21
+ def objects_for(selector, klass, *extra_args)
22
+ @doc.css(selector).map { |e| klass.new(e, *extra_args) }
23
23
  end
24
24
 
25
- def object_for(selector, klass)
25
+ def object_for(selector, klass, *extra_args)
26
26
  node = @doc.css(selector).first
27
27
  node or raise Error, "no node matches selector #{selector.inspect}"
28
28
 
29
- klass.new node
29
+ klass.new node, *extra_args
30
30
  end
31
31
  end # Doc
32
32
 
@@ -20,7 +20,7 @@ module Bamboo
20
20
  :username => user,
21
21
  :password => pass
22
22
 
23
- @token = doc.text_for("response auth")
23
+ @token = doc.text_for "response auth"
24
24
  end
25
25
 
26
26
  def logout
@@ -45,7 +45,7 @@ module Bamboo
45
45
  def builds
46
46
  doc = post :listBuildNames, :auth => token
47
47
 
48
- doc.objects_for "build", Remote::Build
48
+ doc.objects_for "build", Remote::Build, self
49
49
  end
50
50
 
51
51
  def latest_builds_for(user)
@@ -53,7 +53,7 @@ module Bamboo
53
53
  :auth => token,
54
54
  :user => user
55
55
 
56
- doc.objects_for "build", Remote::Build
56
+ doc.objects_for "build", Remote::Build, self
57
57
  end
58
58
 
59
59
  def latest_build_results(build_key)
@@ -91,8 +91,9 @@ module Bamboo
91
91
  #
92
92
 
93
93
  class Build
94
- def initialize(doc)
94
+ def initialize(doc, client)
95
95
  @doc = doc
96
+ @client = client
96
97
  end
97
98
 
98
99
  def enabled?
@@ -106,6 +107,22 @@ module Bamboo
106
107
  def key
107
108
  @doc.css("key").text
108
109
  end
110
+
111
+ def latest_results
112
+ @client.latest_build_results key
113
+ end
114
+
115
+ def execute
116
+ @client.execute_build(key)
117
+ end
118
+
119
+ def update_and_build
120
+ @client.update_and_build(key)
121
+ end
122
+
123
+ def recently_completed_results
124
+ @client.recently_completed_results_for_build(key)
125
+ end
109
126
  end
110
127
 
111
128
  class BuildResult
@@ -1,5 +1,5 @@
1
1
  module Bamboo
2
2
  module Client
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -42,10 +42,28 @@ module Bamboo
42
42
 
43
43
  it "returns an instance of the given class for the first node matching the selector" do
44
44
  wrapped.should_receive(:css).with("selector").and_return(['node1', 'node2'])
45
+
45
46
  obj = doc.object_for("selector", SpecHelper::Wrapper)
47
+
46
48
  obj.should be_instance_of(SpecHelper::Wrapper)
47
49
  obj.obj.should == "node1"
48
50
  end
51
+
52
+ it "#object_for passes extra args to the given class' constructor" do
53
+ wrapped.should_receive(:css).with("selector").and_return(['node1', 'node2'])
54
+
55
+ SpecHelper::Wrapper.should_receive(:new).with('node1', "foo")
56
+ doc.object_for("selector", SpecHelper::Wrapper, "foo")
57
+ end
58
+
59
+ it "#objects_for passes extra args to the given class' constructor" do
60
+ wrapped.should_receive(:css).with("selector").and_return(['node1', 'node2'])
61
+
62
+ SpecHelper::Wrapper.should_receive(:new).with('node1', "foo")
63
+ SpecHelper::Wrapper.should_receive(:new).with('node2', "foo")
64
+
65
+ doc.objects_for("selector", SpecHelper::Wrapper, "foo")
66
+ end
49
67
  end
50
68
  end
51
69
  end
@@ -64,7 +64,7 @@ module Bamboo
64
64
  end
65
65
 
66
66
  it "fetches a list of builds" do
67
- document.should_receive(:objects_for).with("build", Remote::Build).
67
+ document.should_receive(:objects_for).with("build", Remote::Build, client).
68
68
  and_return(["some", "objects"])
69
69
 
70
70
  http.should_receive(:post).with(
@@ -76,7 +76,7 @@ module Bamboo
76
76
  end
77
77
 
78
78
  it "fetches a list of the latest builds for the given user" do
79
- document.should_receive(:objects_for).with("build", Remote::Build).
79
+ document.should_receive(:objects_for).with("build", Remote::Build, client).
80
80
  and_return(["some", "objects"])
81
81
 
82
82
  user = "fake-user"
@@ -131,7 +131,9 @@ module Bamboo
131
131
  end # API calls
132
132
 
133
133
  describe Remote::Build do
134
- let(:build) { Remote::Build.new(xml_fixture("build").css("build").first) }
134
+ let(:client) { mock(Remote) }
135
+ let(:doc) { xml_fixture("build").css("build").first }
136
+ let(:build) { Remote::Build.new(doc, client) }
135
137
 
136
138
  it "should know if the build is enabled" do
137
139
  build.should be_enabled
@@ -144,6 +146,26 @@ module Bamboo
144
146
  it "should know the key of the build" do
145
147
  build.key.should == "THRIFT-DEFAULT"
146
148
  end
149
+
150
+ it "should be able to fetch the latest results" do
151
+ client.should_receive(:latest_build_results).with build.key
152
+ build.latest_results
153
+ end
154
+
155
+ it "should be able to execute the build" do
156
+ client.should_receive(:execute_build).with build.key
157
+ build.execute
158
+ end
159
+
160
+ it "should be able to update and build" do
161
+ client.should_receive(:update_and_build).with build.key
162
+ build.update_and_build
163
+ end
164
+
165
+ it "should be able to fetch recentyl completed results" do
166
+ client.should_receive(:recently_completed_results_for_build).with build.key
167
+ build.recently_completed_results
168
+ end
147
169
  end # Remote::Build
148
170
 
149
171
  describe Remote::BuildResult do
data/spec/spec_helper.rb CHANGED
@@ -25,7 +25,7 @@ module Bamboo::Client::SpecHelper
25
25
  class Wrapper
26
26
  attr_reader :obj
27
27
 
28
- def initialize(obj)
28
+ def initialize(obj, *extra_args)
29
29
  @obj = obj
30
30
  end
31
31
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jari Bakken