tddium_client 0.0.2 → 0.0.3
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.
- data/.gitignore +2 -0
- data/lib/tddium_client.rb +3 -12
- data/lib/tddium_client/version.rb +1 -1
- data/spec/fixtures/{post_suites_201_json_status_1.json → post_suites_269_json_status_1.json} +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/tddium_client_spec.rb +57 -26
- data/tddium_client.gemspec +1 -0
- metadata +20 -7
- data/.rvmrc +0 -2
data/.gitignore
CHANGED
data/lib/tddium_client.rb
CHANGED
@@ -36,16 +36,12 @@ class TddiumClient
|
|
36
36
|
response = JSON.parse(http.body) rescue {}
|
37
37
|
|
38
38
|
if http.success?
|
39
|
-
|
40
|
-
yield response
|
41
|
-
else
|
42
|
-
message = API_ERROR_TEXT + response["explanation"].to_s
|
43
|
-
end
|
39
|
+
(response["status"] == 0 && block_given?) ? yield(response) : message = API_ERROR_TEXT + response["explanation"].to_s
|
44
40
|
else
|
45
41
|
message = API_ERROR_TEXT + http.response.header.msg.to_s
|
46
42
|
message << " #{response["explanation"]}" if response["status"].to_i > 0
|
47
43
|
end
|
48
|
-
[response["status"]
|
44
|
+
[response["status"], http.code, message]
|
49
45
|
end
|
50
46
|
|
51
47
|
private
|
@@ -59,12 +55,7 @@ class TddiumClient
|
|
59
55
|
end
|
60
56
|
|
61
57
|
def tddium_config
|
62
|
-
unless @tddium_config
|
63
|
-
@tddium_config = YAML.load(
|
64
|
-
File.read(File.join(File.dirname(__FILE__), "..", "config", "environment.yml"))
|
65
|
-
)[environment.to_s]
|
66
|
-
end
|
58
|
+
@tddium_config = YAML.load(File.read(File.join(File.dirname(__FILE__), "..", "config", "environment.yml")))[environment.to_s] unless @tddium_config
|
67
59
|
@tddium_config
|
68
60
|
end
|
69
61
|
end
|
70
|
-
|
data/spec/fixtures/{post_suites_201_json_status_1.json → post_suites_269_json_status_1.json}
RENAMED
File without changes
|
data/spec/spec_helper.rb
CHANGED
data/spec/tddium_client_spec.rb
CHANGED
@@ -97,78 +97,109 @@ describe TddiumClient do
|
|
97
97
|
parse_request_params.should == {}
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
context "results in a successful response" do
|
102
|
-
let(:dummy_block) { Proc.new { |response| @parsed_http_response = response } }
|
103
102
|
before do
|
104
103
|
stub_http_response(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, :response => fixture_path("post_suites_201.json"))
|
105
104
|
end
|
106
105
|
|
107
|
-
|
108
|
-
|
109
|
-
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {}, nil, &dummy_block)
|
110
|
-
end
|
106
|
+
context "called with a block" do
|
107
|
+
let(:dummy_block) { Proc.new { |response| @parsed_http_response = response } }
|
111
108
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
109
|
+
it "should try to contact the api only once" do
|
110
|
+
HTTParty.should_receive(EXAMPLE_HTTP_METHOD).exactly(1).times.and_return(mock(HTTParty).as_null_object)
|
111
|
+
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {}, nil, &dummy_block)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should parse the JSON response" do
|
115
|
+
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {}, nil, &dummy_block)
|
116
|
+
@parsed_http_response.should be_a(Hash)
|
117
|
+
@parsed_http_response["status"].should == 0
|
118
|
+
@parsed_http_response["suite"]["id"].should == 19
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should return a triple with element[0]==json_status, element[1]==http_status, element[2]==error_message" do
|
122
|
+
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {}, nil, &dummy_block).should == [0, 201, nil]
|
123
|
+
end
|
117
124
|
end
|
118
125
|
|
119
|
-
|
120
|
-
|
126
|
+
context "called without a block" do
|
127
|
+
it "should not yield" do
|
128
|
+
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)
|
129
|
+
end
|
121
130
|
end
|
122
131
|
end
|
123
132
|
|
124
|
-
context "results
|
133
|
+
context "results for an unsuccessful response" do
|
125
134
|
before { stub_http_response(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, :status => ["404", "Not Found"]) }
|
126
135
|
|
127
136
|
shared_examples_for "returning that an error occured" do
|
128
|
-
it "should return that an error occured in the
|
129
|
-
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[
|
137
|
+
it "should return that an error occured in the third element" do
|
138
|
+
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[2].should =~ /^#{TddiumClient::API_ERROR_TEXT}/
|
130
139
|
end
|
131
140
|
end
|
132
141
|
|
133
142
|
shared_examples_for("returning the API error") do
|
134
|
-
it "should return the API error in the
|
135
|
-
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[
|
143
|
+
it "should return the API error message in the third element" do
|
144
|
+
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[2].should =~ /\{\:suite_name\=\>\[\"has already been taken\"\]\}$/
|
136
145
|
end
|
137
146
|
end
|
138
147
|
|
139
|
-
|
140
|
-
|
148
|
+
shared_examples_for("returning the HTTP status code") do
|
149
|
+
it "should return the HTTP status code in the second element" do
|
150
|
+
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[1].should == http_status_code
|
151
|
+
end
|
141
152
|
end
|
142
153
|
|
154
|
+
it "should return an array with three elements" do
|
155
|
+
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE).size.should == 3
|
156
|
+
end
|
157
|
+
|
143
158
|
context "where the http request was successful but API status is not 0" do
|
144
|
-
before { stub_http_response(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, :response => fixture_path("
|
159
|
+
before { stub_http_response(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, :response => fixture_path("post_suites_269_json_status_1.json")) }
|
145
160
|
it_should_behave_like("returning that an error occured")
|
146
161
|
it_should_behave_like("returning the API error")
|
147
162
|
|
148
163
|
it "should return the API error code in the first element" do
|
149
164
|
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[0].should == 1
|
150
165
|
end
|
166
|
+
|
167
|
+
it_should_behave_like("returning the HTTP status code") do
|
168
|
+
let(:http_status_code) {269}
|
169
|
+
end
|
151
170
|
end
|
152
171
|
|
153
172
|
context "where the http request was unsuccessful" do
|
154
173
|
before { stub_http_response(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, :status => ["501", "Internal Server Error"]) }
|
155
174
|
it_should_behave_like("returning that an error occured")
|
156
175
|
|
157
|
-
|
158
|
-
|
176
|
+
it_should_behave_like("returning the HTTP status code") do
|
177
|
+
let(:http_status_code) {501}
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should return the HTTP error message in the third element" do
|
181
|
+
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[2].should =~ /Internal Server Error/
|
159
182
|
end
|
160
183
|
|
161
184
|
context "and an API error is returned" do
|
162
185
|
before { stub_http_response(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, :response => fixture_path("post_suites_409.json")) }
|
163
186
|
it_should_behave_like("returning the API error")
|
164
|
-
it "should return the
|
187
|
+
it "should return the API error code in the first element" do
|
165
188
|
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[0].should == 1
|
166
189
|
end
|
190
|
+
|
191
|
+
it_should_behave_like("returning the HTTP status code") do
|
192
|
+
let(:http_status_code) {409}
|
193
|
+
end
|
167
194
|
end
|
168
195
|
|
169
196
|
context "and no API error is returned" do
|
170
|
-
it "should return
|
171
|
-
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[0].should
|
197
|
+
it "should return a nil API error code in the first element" do
|
198
|
+
tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[0].should be_nil
|
199
|
+
end
|
200
|
+
|
201
|
+
it_should_behave_like("returning the HTTP status code") do
|
202
|
+
let(:http_status_code) {501}
|
172
203
|
end
|
173
204
|
end
|
174
205
|
end
|
data/tddium_client.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tddium_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jay Moorthi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-18 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -102,6 +102,20 @@ dependencies:
|
|
102
102
|
version: "0"
|
103
103
|
type: :development
|
104
104
|
version_requirements: *id006
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: simplecov
|
107
|
+
prerelease: false
|
108
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
type: :development
|
118
|
+
version_requirements: *id007
|
105
119
|
description: Internal Gem used to call the Tddium API
|
106
120
|
email:
|
107
121
|
- info@tddium.com
|
@@ -113,7 +127,6 @@ extra_rdoc_files: []
|
|
113
127
|
|
114
128
|
files:
|
115
129
|
- .gitignore
|
116
|
-
- .rvmrc
|
117
130
|
- Gemfile
|
118
131
|
- README
|
119
132
|
- Rakefile
|
@@ -122,7 +135,7 @@ files:
|
|
122
135
|
- lib/tddium_client/tddium_spec_helpers.rb
|
123
136
|
- lib/tddium_client/version.rb
|
124
137
|
- spec/fixtures/post_suites_201.json
|
125
|
-
- spec/fixtures/
|
138
|
+
- spec/fixtures/post_suites_269_json_status_1.json
|
126
139
|
- spec/fixtures/post_suites_409.json
|
127
140
|
- spec/spec_helper.rb
|
128
141
|
- spec/tddium_client_spec.rb
|
@@ -163,7 +176,7 @@ specification_version: 3
|
|
163
176
|
summary: tddium Client Gem
|
164
177
|
test_files:
|
165
178
|
- spec/fixtures/post_suites_201.json
|
166
|
-
- spec/fixtures/
|
179
|
+
- spec/fixtures/post_suites_269_json_status_1.json
|
167
180
|
- spec/fixtures/post_suites_409.json
|
168
181
|
- spec/spec_helper.rb
|
169
182
|
- spec/tddium_client_spec.rb
|
data/.rvmrc
DELETED