tddium_client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,3 +5,5 @@ nbproject
5
5
  .DS_Store
6
6
  *.swp
7
7
  Gemfile.lock
8
+ coverage/
9
+ .rvmrc
@@ -36,16 +36,12 @@ class TddiumClient
36
36
  response = JSON.parse(http.body) rescue {}
37
37
 
38
38
  if http.success?
39
- if response["status"] == 0
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"] || http.code, message]
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
-
@@ -3,5 +3,5 @@ Copyright (c) 2011 Solano Labs All Rights Reserved
3
3
  =end
4
4
 
5
5
  module TddiumClientVersion
6
- VERSION = "0.0.2"
6
+ VERSION = "0.0.3"
7
7
  end
@@ -2,7 +2,10 @@
2
2
  Copyright (c) 2011 Solano Labs All Rights Reserved
3
3
  =end
4
4
 
5
+ require "simplecov"
6
+ SimpleCov.start
5
7
  require "tddium_client"
8
+ require "rspec"
6
9
  require "fakeweb"
7
10
  require "rack/test"
8
11
  require "fakefs/spec_helpers"
@@ -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
- it "should try to contact the api only once" do
108
- HTTParty.should_receive(EXAMPLE_HTTP_METHOD).exactly(1).times.and_return(mock(HTTParty).as_null_object)
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
- it "should parse the JSON response" do
113
- tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {}, nil, &dummy_block)
114
- @parsed_http_response.should be_a(Hash)
115
- @parsed_http_response["status"].should == 0
116
- @parsed_http_response["suite"]["id"].should == 19
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
- it "should return a tuple with element[0]==status and element[1]==nil" do
120
- tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE, {}, nil, &dummy_block).should == [0, nil]
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 in an unsuccessful response" do
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 second element" do
129
- tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[1].should =~ /^#{TddiumClient::API_ERROR_TEXT}/
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 second element" do
135
- tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[1].should =~ /\{\:suite_name\=\>\[\"has already been taken\"\]\}$/
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
- it "should return an array with two elements" do
140
- tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE).size.should == 2
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("post_suites_201_json_status_1.json")) }
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
- it "should return the HTTP error message in the second element" do
158
- tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[1].should =~ /Internal Server Error/
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 HTTP error code in the first element" do
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 the HTTP error code in the first element" do
171
- tddium_client.call_api(EXAMPLE_HTTP_METHOD, EXAMPLE_TDDIUM_RESOURCE)[0].should == 501
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
@@ -30,4 +30,5 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency("fakeweb")
31
31
  s.add_development_dependency("fakefs")
32
32
  s.add_development_dependency("rack-test")
33
+ s.add_development_dependency("simplecov")
33
34
  end
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
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-16 00:00:00 -07:00
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/post_suites_201_json_status_1.json
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/post_suites_201_json_status_1.json
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
@@ -1,2 +0,0 @@
1
- rvm use ruby-1.8.7-p302@tddium_client
2
-