tddium-preview 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tddium-preview (0.0.3)
4
+ tddium-preview (0.0.5)
5
5
  highline
6
6
  json
7
- tddium_client (= 0.0.3)
7
+ tddium_client (>= 0.0.6)
8
8
  thor
9
9
 
10
10
  GEM
@@ -29,7 +29,7 @@ GEM
29
29
  simplecov (0.4.1)
30
30
  simplecov-html (~> 0.4.3)
31
31
  simplecov-html (0.4.3)
32
- tddium_client (0.0.3)
32
+ tddium_client (0.0.6)
33
33
  httparty
34
34
  json
35
35
  thor (0.14.6)
data/lib/tddium.rb CHANGED
@@ -37,10 +37,9 @@ class Tddium < Thor
37
37
  method_option :ssh_key_file, :type => :string, :default => nil
38
38
  def account
39
39
  set_default_environment(options[:environment])
40
- if user_logged_in? do |api_response|
41
- # User is already logged in, so just display the info
42
- show_user_details(api_response)
43
- end
40
+ if user_details = user_logged_in?
41
+ # User is already logged in, so just display the info
42
+ show_user_details(user_details)
44
43
  else
45
44
  params = get_user_credentials(options.merge(:invited => true))
46
45
 
@@ -65,11 +64,15 @@ class Tddium < Thor
65
64
  license_accepted = ask(Text::Prompt::LICENSE_AGREEMENT)
66
65
  return unless license_accepted.downcase == Text::Prompt::Response::AGREE_TO_LICENSE.downcase
67
66
 
68
- api_result = call_api(:post, Api::Path::USERS, {:user => params}, false, false) do |api_response|
69
- write_api_key(api_response["user"]["api_key"])
70
- say Text::Process::ACCOUNT_CREATED % [api_response["user"]["email"], api_response["user"]["recurly_url"]]
67
+ begin
68
+ new_user = call_api(:post, Api::Path::USERS, {:user => params}, false, false)
69
+ write_api_key(new_user["user"]["api_key"])
70
+ say Text::Process::ACCOUNT_CREATED % [new_user["user"]["email"], new_user["user"]["recurly_url"]]
71
+ rescue TddiumClient::Error::API => e
72
+ say((e.status == Api::ErrorCode::INVALID_INVITATION) ? Text::Error::INVALID_INVITATION : e.message)
73
+ rescue TddiumClient::Error::Base => e
74
+ say e.message
71
75
  end
72
- say((api_result.api_status == Api::ErrorCode::INVALID_INVITATION) ? Text::Error::INVALID_INVITATION : api_result.message) unless api_result.success?
73
76
  end
74
77
  end
75
78
 
@@ -82,9 +85,7 @@ class Tddium < Thor
82
85
  if user_logged_in?
83
86
  say Text::Process::ALREADY_LOGGED_IN
84
87
  else
85
- login_user(:params => get_user_credentials(options), :show_error => true) do
86
- say Text::Process::LOGGED_IN_SUCCESSFULLY
87
- end
88
+ say Text::Process::LOGGED_IN_SUCCESSFULLY if login_user(:params => get_user_credentials(options), :show_error => true)
88
89
  end
89
90
  end
90
91
 
@@ -108,72 +109,63 @@ class Tddium < Thor
108
109
  return unless git_push
109
110
 
110
111
  # Call the API to get the suite and its tests
111
- call_api(:get, current_suite_path) do |api_response|
112
- test_pattern = api_response["suite"]["test_pattern"]
112
+ begin
113
+ suite_details = call_api(:get, current_suite_path)
114
+ test_pattern = suite_details["suite"]["test_pattern"]
113
115
  test_files = Dir.glob(test_pattern).collect {|file_path| {:test_name => file_path}}
114
116
 
115
117
  # Create a session
116
- call_api(:post, Api::Path::SESSIONS) do |api_response|
117
- session_id = api_response["session"]["id"]
118
-
119
- # Call the API to register the tests
120
- call_api(:post, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::REGISTER_TEST_EXECUTIONS}", {:suite_id => current_suite_id, :tests => test_files}) do |api_response|
121
- # Start the tests
122
- call_api(:post, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::START_TEST_EXECUTIONS}") do |api_response|
123
- tests_not_finished_yet = true
124
- finished_tests = {}
125
- test_statuses = Hash.new(0)
126
- api_call_successful = true
127
- get_test_executions_response = {}
128
-
129
- say Text::Process::STARTING_TEST % test_files.size
130
- say Text::Process::TERMINATE_INSTRUCTION
131
- while tests_not_finished_yet && api_call_successful do
132
- # Poll the API to check the status
133
- call_api_result = call_api(:get, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::TEST_EXECUTIONS}") do |api_response|
134
- # Catch Ctrl-C to interrupt the test
135
- Signal.trap(:INT) do
136
- say Text::Process::INTERRUPT
137
- say Text::Process::CHECK_TEST_STATUS
138
- tests_not_finished_yet = false
139
- end
140
-
141
- # Print out the progress of running tests
142
- api_response["tests"].each do |test_name, result_params|
143
- test_status = result_params["status"]
144
- if result_params["end_time"] && !finished_tests[test_name]
145
- message = case test_status
146
- when "passed" then [".", :green, false]
147
- when "failed" then ["F", :red, false]
148
- when "error" then ["E", nil, false]
149
- when "pending" then ["*", :yellow, false]
150
- end
151
- finished_tests[test_name] = test_status
152
- test_statuses[test_status] += 1
153
- say *message
154
- end
155
- end
156
-
157
- # save response for later use
158
- get_test_executions_response = api_response
159
-
160
- # If all tests finished, exit the loop else sleep
161
- if finished_tests.size == api_response["tests"].size
162
- tests_not_finished_yet = false
163
- else
164
- sleep(Default::SLEEP_TIME_BETWEEN_POLLS)
165
- end
166
- end
167
- api_call_successful = call_api_result.success?
168
- end
118
+ new_session = call_api(:post, Api::Path::SESSIONS)
119
+ session_id = new_session["session"]["id"]
120
+
121
+ # Register the tests
122
+ call_api(:post, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::REGISTER_TEST_EXECUTIONS}", {:suite_id => current_suite_id, :tests => test_files})
123
+
124
+ # Start the tests
125
+ start_test_executions = call_api(:post, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::START_TEST_EXECUTIONS}")
126
+ tests_not_finished_yet = true
127
+ finished_tests = {}
128
+ test_statuses = Hash.new(0)
129
+
130
+ say Text::Process::STARTING_TEST % test_files.size
131
+ say Text::Process::CHECK_TEST_REPORT % start_test_executions["report"]
132
+ say Text::Process::TERMINATE_INSTRUCTION
133
+ while tests_not_finished_yet do
134
+ # Poll the API to check the status
135
+ current_test_executions = call_api(:get, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::TEST_EXECUTIONS}")
136
+
137
+ # Catch Ctrl-C to interrupt the test
138
+ Signal.trap(:INT) do
139
+ say Text::Process::INTERRUPT
140
+ say Text::Process::CHECK_TEST_STATUS
141
+ tests_not_finished_yet = false
142
+ end
169
143
 
170
- # Print out the result
171
- say Text::Process::FINISHED_TEST % (Time.now - start_time)
172
- say "#{finished_tests.size} examples, #{test_statuses["failed"]} failures, #{test_statuses["error"]} errors, #{test_statuses["pending"]} pending"
173
- say Text::Process::CHECK_TEST_REPORT % get_test_executions_response["report"]
144
+ # Print out the progress of running tests
145
+ current_test_executions["tests"].each do |test_name, result_params|
146
+ test_status = result_params["status"]
147
+ if result_params["end_time"] && !finished_tests[test_name]
148
+ message = case test_status
149
+ when "passed" then [".", :green, false]
150
+ when "failed" then ["F", :red, false]
151
+ when "error" then ["E", nil, false]
152
+ when "pending" then ["*", :yellow, false]
153
+ end
154
+ finished_tests[test_name] = test_status
155
+ test_statuses[test_status] += 1
156
+ say *message
174
157
  end
175
158
  end
159
+
160
+ # If all tests finished, exit the loop else sleep
161
+ finished_tests.size == current_test_executions["tests"].size ? tests_not_finished_yet = false : sleep(Default::SLEEP_TIME_BETWEEN_POLLS)
176
162
  end
163
+
164
+ # Print out the result
165
+ say " "
166
+ say Text::Process::FINISHED_TEST % (Time.now - start_time)
167
+ say "#{finished_tests.size} examples, #{test_statuses["failed"]} failures, #{test_statuses["error"]} errors, #{test_statuses["pending"]} pending"
168
+ rescue TddiumClient::Error::Base
177
169
  end
178
170
  end
179
171
 
@@ -183,13 +175,14 @@ class Tddium < Thor
183
175
  set_default_environment(options[:environment])
184
176
  return unless git_repo? && tddium_settings && suite_for_current_branch?
185
177
 
186
- call_api(:get, Api::Path::SUITES) do |api_response|
187
- if api_response["suites"].size == 0
178
+ begin
179
+ current_suites = call_api(:get, Api::Path::SUITES)
180
+ if current_suites["suites"].size == 0
188
181
  say Text::Status::NO_SUITE
189
182
  else
190
- say Text::Status::ALL_SUITES % api_response["suites"].collect {|suite| suite["repo_name"]}.join(", ")
183
+ say Text::Status::ALL_SUITES % current_suites["suites"].collect {|suite| suite["repo_name"]}.join(", ")
191
184
 
192
- if current_suite = api_response["suites"].detect {|suite| suite["id"] == current_suite_id}
185
+ if current_suite = current_suites["suites"].detect {|suite| suite["id"] == current_suite_id}
193
186
  say Text::Status::SEPARATOR
194
187
  say Text::Status::CURRENT_SUITE % current_suite["repo_name"]
195
188
 
@@ -201,6 +194,7 @@ class Tddium < Thor
201
194
  say Text::Status::CURRENT_SUITE_UNAVAILABLE
202
195
  end
203
196
  end
197
+ rescue TddiumClient::Error::Base
204
198
  end
205
199
  end
206
200
 
@@ -213,29 +207,27 @@ class Tddium < Thor
213
207
  return unless git_repo? && tddium_settings
214
208
 
215
209
  params = {}
216
- if current_suite_id
217
- call_api(:get, current_suite_path) do |api_response|
210
+ begin
211
+ if current_suite_id
212
+ current_suite = call_api(:get, current_suite_path)
218
213
  # Get the current test pattern and prompt for updates
219
- params[:test_pattern] = prompt(Text::Prompt::TEST_PATTERN, options[:test_pattern], api_response["suite"]["test_pattern"])
214
+ params[:test_pattern] = prompt(Text::Prompt::TEST_PATTERN, options[:test_pattern], current_suite["suite"]["test_pattern"])
220
215
 
221
216
  # Update the current suite if it exists already
222
- call_api(:put, current_suite_path, {:suite => params}) do |api_response|
223
- say Text::Process::UPDATE_SUITE
224
- end
225
- end
226
- else
227
- params[:branch] = current_git_branch
228
- default_suite_name = File.basename(Dir.pwd)
229
- params[:repo_name] = options[:name] || default_suite_name
230
-
231
- existing_suite = nil
232
- use_existing_suite = false
233
- suite_name_resolved = false
234
- api_call_successful = true
235
- while !suite_name_resolved && api_call_successful
236
- # Check to see if there is an existing suite
237
- api_call_successful = call_api(:get, Api::Path::SUITES, params) do |api_response|
238
- existing_suite = api_response["suites"].first
217
+ call_api(:put, current_suite_path, {:suite => params})
218
+ say Text::Process::UPDATE_SUITE
219
+ else
220
+ params[:branch] = current_git_branch
221
+ default_suite_name = File.basename(Dir.pwd)
222
+ params[:repo_name] = options[:name] || default_suite_name
223
+
224
+ existing_suite = nil
225
+ use_existing_suite = false
226
+ suite_name_resolved = false
227
+ while !suite_name_resolved
228
+ # Check to see if there is an existing suite
229
+ current_suites = call_api(:get, Api::Path::SUITES, params)
230
+ existing_suite = current_suites["suites"].first
239
231
 
240
232
  # Get the suite name
241
233
  current_suite_name = params[:repo_name]
@@ -256,10 +248,8 @@ class Tddium < Thor
256
248
  # Suite name does not exist yet and already prompted
257
249
  suite_name_resolved = true
258
250
  end
259
- end.success?
260
- end
251
+ end
261
252
 
262
- if api_call_successful
263
253
  if use_existing_suite
264
254
  # Write to file and exit when using the existing suite
265
255
  write_suite(existing_suite["id"])
@@ -274,31 +264,30 @@ class Tddium < Thor
274
264
  params[:test_pattern] = prompt(Text::Prompt::TEST_PATTERN, options[:test_pattern], Default::TEST_PATTERN)
275
265
 
276
266
  # Create new suite if it does not exist yet
277
- call_api(:post, Api::Path::SUITES, {:suite => params}) do |api_response|
278
- # Save the created suite
279
- write_suite(api_response["suite"]["id"])
280
-
281
- # Manage git
282
- `git remote rm #{Git::REMOTE_NAME}`
283
- `git remote add #{Git::REMOTE_NAME} #{api_response["suite"]["git_repo_uri"]}`
284
- git_push
285
- end
267
+ new_suite = call_api(:post, Api::Path::SUITES, {:suite => params})
268
+ # Save the created suite
269
+ write_suite(new_suite["suite"]["id"])
270
+
271
+ # Manage git
272
+ `git remote rm #{Git::REMOTE_NAME}`
273
+ `git remote add #{Git::REMOTE_NAME} #{new_suite["suite"]["git_repo_uri"]}`
274
+ git_push
286
275
  end
276
+ rescue TddiumClient::Error::Base
287
277
  end
288
278
  end
289
279
 
290
280
  private
291
281
 
292
- def call_api(method, api_path, params = {}, api_key = nil, show_error = true, &block)
282
+ def call_api(method, api_path, params = {}, api_key = nil, show_error = true)
293
283
  api_key = tddium_settings(:fail_with_message => false)["api_key"] if tddium_settings(:fail_with_message => false) && api_key != false
294
- api_status, http_status, error_message = tddium_client.call_api(method, api_path, params, api_key, &block)
295
- say error_message if error_message && show_error
296
- response = Struct.new(:api_status, :http_status, :message) do
297
- def success?
298
- self.api_status.to_i.zero?
299
- end
284
+ begin
285
+ result = tddium_client.call_api(method, api_path, params, api_key)
286
+ rescue TddiumClient::Error::Base => e
287
+ say e.message if show_error
288
+ raise e
300
289
  end
301
- response.new(api_status, http_status, error_message)
290
+ result
302
291
  end
303
292
 
304
293
  def current_git_branch
@@ -324,11 +313,11 @@ class Tddium < Thor
324
313
  end
325
314
 
326
315
  def environment
327
- tddium_client.environment
316
+ tddium_client.environment.to_sym
328
317
  end
329
318
 
330
- def get_user(&block)
331
- call_api(:get, Api::Path::USERS, {}, nil, false, &block)
319
+ def get_user
320
+ call_api(:get, Api::Path::USERS, {}, nil, false) rescue nil
332
321
  end
333
322
 
334
323
  def get_user_credentials(options = {})
@@ -355,12 +344,13 @@ class Tddium < Thor
355
344
  message.nil?
356
345
  end
357
346
 
358
- def login_user(options = {}, &block)
347
+ def login_user(options = {})
359
348
  # POST (email, password) to /users/sign_in to retrieve an API key
360
- login_result = call_api(:post, Api::Path::SIGN_IN, {:user => options[:params]}, false, options[:show_error]) do |api_response|
349
+ begin
350
+ login_result = call_api(:post, Api::Path::SIGN_IN, {:user => options[:params]}, false, options[:show_error])
361
351
  # On success, write the API key to "~/.tddium.<environment>"
362
- write_api_key(api_response["api_key"])
363
- yield api_response if block_given?
352
+ write_api_key(login_result["api_key"])
353
+ rescue TddiumClient::Error::Base
364
354
  end
365
355
  login_result
366
356
  end
@@ -380,20 +370,21 @@ class Tddium < Thor
380
370
  end
381
371
 
382
372
  def show_session_details(params, no_session_prompt, all_session_prompt)
383
- call_api(:get, Api::Path::SESSIONS, params) do |api_response|
373
+ begin
374
+ current_sessions = call_api(:get, Api::Path::SESSIONS, params)
384
375
  say Text::Status::SEPARATOR
385
- if api_response["sessions"].size == 0
376
+ if current_sessions["sessions"].size == 0
386
377
  say no_session_prompt
387
378
  else
388
379
  say all_session_prompt
389
- api_response["sessions"].each do |session|
380
+ current_sessions["sessions"].each do |session|
390
381
  session_id = session["id"]
391
382
  say Text::Status::SESSION_TITLE % session_id
392
- call_api(:get, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::TEST_EXECUTIONS}") do |api_response|
393
- display_attributes(DisplayedAttributes::TEST_EXECUTION, api_response)
394
- end
383
+ current_test_executions = call_api(:get, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::TEST_EXECUTIONS}")
384
+ display_attributes(DisplayedAttributes::TEST_EXECUTION, current_test_executions)
395
385
  end
396
386
  end
387
+ rescue TddiumClient::Error::Base
397
388
  end
398
389
  end
399
390
 
@@ -415,7 +406,7 @@ class Tddium < Thor
415
406
  end
416
407
 
417
408
  def tddium_client
418
- @tddium_client ||= TddiumClient.new
409
+ @tddium_client ||= TddiumClient::Client.new
419
410
  end
420
411
 
421
412
  def tddium_file_name
@@ -439,9 +430,9 @@ class Tddium < Thor
439
430
  @tddium_settings
440
431
  end
441
432
 
442
- def user_logged_in?(active = true, &block)
433
+ def user_logged_in?(active = true)
443
434
  result = tddium_settings(:fail_with_message => false) && tddium_settings["api_key"]
444
- (result && active) ? get_user(&block).success? : result
435
+ (result && active) ? get_user : result
445
436
  end
446
437
 
447
438
  def write_api_key(api_key)
@@ -458,5 +449,4 @@ class Tddium < Thor
458
449
  file.write(tddium_settings.merge({"branches" => branches}).to_json)
459
450
  end
460
451
  end
461
-
462
452
  end
@@ -3,5 +3,5 @@ Copyright (c) 2011 Solano Labs All Rights Reserved
3
3
  =end
4
4
 
5
5
  module TddiumVersion
6
- VERSION = "0.0.4"
6
+ VERSION = "0.0.5"
7
7
  end
data/spec/tddium_spec.rb CHANGED
@@ -13,8 +13,6 @@ describe Tddium do
13
13
  SAMPLE_APP_NAME = "tddelicious"
14
14
  SAMPLE_BRANCH_NAME = "test"
15
15
  SAMPLE_BUNDLER_VERSION = "1.10.10"
16
- SAMPLE_CALL_API_RESPONSE = [0, 200, nil]
17
- SAMPLE_CALL_API_ERROR = [1, 501, "an error"]
18
16
  SAMPLE_DATE_TIME = "2011-03-11T08:43:02Z"
19
17
  SAMPLE_EMAIL = "someone@example.com"
20
18
  SAMPLE_INVITATION_TOKEN = "TZce3NueiXp2lMTmaeRr"
@@ -29,13 +27,14 @@ describe Tddium do
29
27
  SAMPLE_SUITE_ID = 1
30
28
  SAMPLE_SUITES_RESPONSE = {"suites" => [{"repo_name" => SAMPLE_APP_NAME, "branch" => SAMPLE_BRANCH_NAME, "id" => SAMPLE_SUITE_ID}]}
31
29
  SAMPLE_TDDIUM_CONFIG_FILE = ".tddium.test"
30
+ SAMPLE_TEST_EXECUTION_STATS = "total 1, notstarted 0, started 1, passed 0, failed 0, pending 0, error 0", "start_time"
32
31
  SAMPLE_TEST_PATTERN = "**/*_spec.rb"
33
32
  SAMPLE_USER_RESPONSE = {"user"=> {"api_key" => SAMPLE_API_KEY, "email" => SAMPLE_EMAIL, "created_at" => SAMPLE_DATE_TIME, "recurly_url" => SAMPLE_RECURLY_URL}}
34
33
 
35
34
  def call_api_should_receive(options = {})
36
35
  params = [options[:method] || anything, options[:path] || anything, options[:params] || anything, (options[:api_key] || options[:api_key] == false) ? options[:api_key] : anything]
37
- tddium_client.stub(:call_api).with(*params) # To prevent the yield
38
- tddium_client.should_receive(:call_api).with(*params).and_return(SAMPLE_CALL_API_ERROR)
36
+ tddium_client.stub(:call_api).with(*params).and_raise(TddiumClient::Error::Base)
37
+ tddium_client.should_receive(:call_api).with(*params)
39
38
  end
40
39
 
41
40
  def extract_options!(array, *option_keys)
@@ -64,14 +63,24 @@ describe Tddium do
64
63
  end
65
64
 
66
65
  def stub_call_api_response(method, path, *response)
67
- options = extract_options!(response, :and_return, :and_yield)
68
- options[:and_yield] = true unless options[:and_yield] == false
69
66
  result = tddium_client.stub(:call_api).with(method, path, anything, anything)
70
- result = result.and_yield(response.first) if options[:and_yield]
71
- result.and_return(options[:and_return] || SAMPLE_CALL_API_ERROR)
72
- response.each_with_index do |current_response, index|
73
- result = result.and_yield(current_response) unless index.zero? || !options[:and_yield]
67
+ response = [{}] if response.empty?
68
+ response_mocks = []
69
+ response.each do |current_response|
70
+ current_response["status"] ||= 0
71
+ status = current_response["status"]
72
+ if status == 0
73
+ tddium_client_result = mock(TddiumClient::Result::API)
74
+ response_mocks << tddium_client_result
75
+ else
76
+ tddium_client_result = mock(TddiumClient::Error::API, :body => current_response.to_json)
77
+ result.and_raise(TddiumClient::Error::API.new(tddium_client_result))
78
+ end
79
+ current_response.each do |k, v|
80
+ tddium_client_result.stub(:[]).with(k).and_return(v)
81
+ end
74
82
  end
83
+ result.and_return(*response_mocks) unless response_mocks.empty?
75
84
  end
76
85
 
77
86
  def stub_cli_options(tddium, options = {})
@@ -118,15 +127,14 @@ describe Tddium do
118
127
  end
119
128
 
120
129
  def stub_tddium_client
121
- TddiumClient.stub(:new).and_return(tddium_client)
122
- tddium_client.stub(:environment).and_return(:test)
123
- tddium_client.stub(:call_api).and_return(SAMPLE_CALL_API_ERROR)
130
+ TddiumClient::Client.stub(:new).and_return(tddium_client)
131
+ tddium_client.stub(:environment).and_return("test")
132
+ tddium_client.stub(:call_api).and_raise(TddiumClient::Error::Base)
124
133
  end
125
134
 
126
135
  let(:tddium) { Tddium.new }
127
136
  let(:tddium_client) { mock(TddiumClient).as_null_object }
128
137
 
129
-
130
138
  shared_examples_for "a password prompt" do
131
139
  context "--password was not passed in" do
132
140
  it "should prompt for a password or confirmation" do
@@ -146,8 +154,8 @@ describe Tddium do
146
154
 
147
155
  shared_examples_for "an unsuccessful api call" do
148
156
  it "should show the error" do
149
- tddium_client.stub(:call_api).and_return(SAMPLE_CALL_API_ERROR)
150
- tddium.should_receive(:say).with(SAMPLE_CALL_API_ERROR[2])
157
+ tddium_client.stub(:call_api).and_raise(TddiumClient::Error::Base)
158
+ tddium.should_receive(:say).with(TddiumClient::Error::Base.new.message)
151
159
  run(tddium)
152
160
  end
153
161
  end
@@ -172,49 +180,6 @@ describe Tddium do
172
180
  end
173
181
  end
174
182
 
175
- shared_examples_for "logging in a user" do
176
- context "there is a tddium config file with an api key" do
177
- before {stub_config_file(:api_key => "some api key")}
178
-
179
- it "should send a 'GET' request to '#{Tddium::Api::Path::USERS}'" do
180
- call_api_should_receive(:method => :get, :path => /#{Tddium::Api::Path::USERS}$/)
181
- run(tddium)
182
- end
183
- end
184
-
185
- context "the tddium config file is missing or corrupt or the api key is invalid" do
186
- context "--email was not passed in" do
187
- it "should prompt for the user's email address" do
188
- tddium.should_receive(:ask).with(Tddium::Text::Prompt::EMAIL)
189
- run(tddium)
190
- end
191
- end
192
-
193
- context "--email was passed in" do
194
- it "should not prompt for the user's email address" do
195
- tddium.should_not_receive(:ask).with(Tddium::Text::Prompt::EMAIL)
196
- run(tddium, :email => SAMPLE_EMAIL)
197
- end
198
- end
199
-
200
- it_should_behave_like "a password prompt" do
201
- let(:password_prompt) {Tddium::Text::Prompt::PASSWORD}
202
- end
203
-
204
- it "should try to sign in the user with their email & password" do
205
- tddium.stub(:ask).with(Tddium::Text::Prompt::EMAIL).and_return(SAMPLE_EMAIL)
206
- HighLine.stub(:ask).with(Tddium::Text::Prompt::PASSWORD).and_return(SAMPLE_PASSWORD)
207
- call_api_should_receive(:method => :post, :path => /#{Tddium::Api::Path::SIGN_IN}$/, :params => {:user => {:email => SAMPLE_EMAIL, :password => SAMPLE_PASSWORD}}, :api_key => false)
208
- run(tddium)
209
- end
210
- end
211
-
212
- context "the user logs in successfully with their email and password" do
213
- before{stub_call_api_response(:post, Tddium::Api::Path::SIGN_IN, {"api_key" => SAMPLE_API_KEY})}
214
- it_should_behave_like "writing the api key to the .tddium file"
215
- end
216
- end
217
-
218
183
  shared_examples_for "sending the api key" do
219
184
  it "should call the api with the api key" do
220
185
  call_api_should_receive(:api_key => SAMPLE_API_KEY)
@@ -288,14 +253,37 @@ describe Tddium do
288
253
  end
289
254
  end
290
255
 
291
- shared_examples_for "writing the api key to the .tddium file" do
292
- it "should write the api key to the .tddium file" do
256
+ shared_examples_for "with the correct environment extension" do
257
+ it "should write the api key to the .tddium file with the relevent environment extension" do
293
258
  run(tddium)
294
- tddium_file = File.open(SAMPLE_TDDIUM_CONFIG_FILE) { |file| file.read }
259
+ tddium_file = File.open(".tddium#{environment_extension}") { |file| file.read }
295
260
  JSON.parse(tddium_file)["api_key"].should == SAMPLE_API_KEY
296
261
  end
297
262
  end
298
263
 
264
+ shared_examples_for "writing the api key to the .tddium file" do
265
+ context "production environment" do
266
+ before { tddium_client.stub(:environment).and_return("production") }
267
+ it_should_behave_like "with the correct environment extension" do
268
+ let(:environment_extension) {""}
269
+ end
270
+ end
271
+
272
+ context "development environment" do
273
+ before { tddium_client.stub(:environment).and_return("development") }
274
+ it_should_behave_like "with the correct environment extension" do
275
+ let(:environment_extension) {".development"}
276
+ end
277
+ end
278
+
279
+ context "test environment" do
280
+ before { tddium_client.stub(:environment).and_return("test") }
281
+ it_should_behave_like "with the correct environment extension" do
282
+ let(:environment_extension) {".test"}
283
+ end
284
+ end
285
+ end
286
+
299
287
  describe "#account" do
300
288
  before do
301
289
  stub_defaults
@@ -402,7 +390,7 @@ describe Tddium do
402
390
  it_should_behave_like "an unsuccessful api call"
403
391
 
404
392
  context "because the invitation is invalid" do
405
- before { stub_call_api_response(:post, Tddium::Api::Path::USERS, :and_yield => false, :and_return => [Tddium::Api::ErrorCode::INVALID_INVITATION, 409, "Invitation is invalid"]) }
393
+ before { stub_call_api_response(:post, Tddium::Api::Path::USERS, {"status" => Tddium::Api::ErrorCode::INVALID_INVITATION}) }
406
394
  it "should show the user: '#{Tddium::Text::Error::INVALID_INVITATION}'" do
407
395
  tddium.should_receive(:say).with(Tddium::Text::Error::INVALID_INVITATION)
408
396
  run_account(tddium)
@@ -422,12 +410,52 @@ describe Tddium do
422
410
  end
423
411
 
424
412
  it_should_behave_like "set the default environment"
425
- it_should_behave_like "logging in a user"
413
+
414
+ context "there is a tddium config file with an api key" do
415
+ before {stub_config_file(:api_key => "some api key")}
416
+
417
+ it "should send a 'GET' request to '#{Tddium::Api::Path::USERS}'" do
418
+ call_api_should_receive(:method => :get, :path => /#{Tddium::Api::Path::USERS}$/)
419
+ run(tddium)
420
+ end
421
+ end
422
+
423
+ context "the tddium config file is missing or corrupt or the api key is invalid" do
424
+ context "--email was not passed in" do
425
+ it "should prompt for the user's email address" do
426
+ tddium.should_receive(:ask).with(Tddium::Text::Prompt::EMAIL)
427
+ run(tddium)
428
+ end
429
+ end
430
+
431
+ context "--email was passed in" do
432
+ it "should not prompt for the user's email address" do
433
+ tddium.should_not_receive(:ask).with(Tddium::Text::Prompt::EMAIL)
434
+ run(tddium, :email => SAMPLE_EMAIL)
435
+ end
436
+ end
437
+
438
+ it_should_behave_like "a password prompt" do
439
+ let(:password_prompt) {Tddium::Text::Prompt::PASSWORD}
440
+ end
441
+
442
+ it "should try to sign in the user with their email & password" do
443
+ tddium.stub(:ask).with(Tddium::Text::Prompt::EMAIL).and_return(SAMPLE_EMAIL)
444
+ HighLine.stub(:ask).with(Tddium::Text::Prompt::PASSWORD).and_return(SAMPLE_PASSWORD)
445
+ call_api_should_receive(:method => :post, :path => /#{Tddium::Api::Path::SIGN_IN}$/, :params => {:user => {:email => SAMPLE_EMAIL, :password => SAMPLE_PASSWORD}}, :api_key => false)
446
+ run(tddium)
447
+ end
448
+
449
+ context "the user logs in successfully with their email and password" do
450
+ before{stub_call_api_response(:post, Tddium::Api::Path::SIGN_IN, {"api_key" => SAMPLE_API_KEY})}
451
+ it_should_behave_like "writing the api key to the .tddium file"
452
+ end
453
+ end
426
454
 
427
455
  context "user is already logged in" do
428
456
  before do
429
457
  stub_config_file(:api_key => SAMPLE_API_KEY)
430
- stub_call_api_response(:get, Tddium::Api::Path::USERS, :and_yield => false, :and_return => SAMPLE_CALL_API_RESPONSE)
458
+ stub_call_api_response(:get, Tddium::Api::Path::USERS)
431
459
  end
432
460
 
433
461
  it "should show the user: '#{Tddium::Text::Process::ALREADY_LOGGED_IN}'" do
@@ -437,7 +465,7 @@ describe Tddium do
437
465
  end
438
466
 
439
467
  context "the user logs in successfully" do
440
- before{stub_call_api_response(:post, Tddium::Api::Path::SIGN_IN, {})}
468
+ before{ stub_call_api_response(:post, Tddium::Api::Path::SIGN_IN, {"api_key" => SAMPLE_API_KEY})}
441
469
  it "should show the user: '#{Tddium::Text::Process::LOGGED_IN_SUCCESSFULLY}'" do
442
470
  tddium.should_receive(:say).with(Tddium::Text::Process::LOGGED_IN_SUCCESSFULLY)
443
471
  run_login(tddium)
@@ -450,7 +478,7 @@ describe Tddium do
450
478
  end
451
479
 
452
480
  describe "#logout" do
453
- before { tddium.stub(:say) }
481
+ before { stub_defaults }
454
482
 
455
483
  context ".tddium file exists" do
456
484
  before { stub_config_file }
@@ -554,9 +582,11 @@ describe Tddium do
554
582
 
555
583
  context "'POST #{Tddium::Api::Path::START_TEST_EXECUTIONS}' is successful" do
556
584
  let(:get_test_executions_response) { {"report"=>SAMPLE_REPORT_URL, "tests"=>{"spec/mouse_spec.rb"=>{"end_time"=>SAMPLE_DATE_TIME, "status"=>"pending"}, "spec/pig_spec.rb"=>{"end_time"=>nil, "status"=>"started"}, "spec/dog_spec.rb"=>{"end_time"=>SAMPLE_DATE_TIME, "status"=>"failed"}, "spec/cat_spec.rb"=>{"end_time"=>SAMPLE_DATE_TIME, "status"=>"passed"}}} }
557
- before do
558
- response = {"started"=>1, "status"=>0}
559
- stub_call_api_response(:post, "#{Tddium::Api::Path::SESSIONS}/#{SAMPLE_SESSION_ID}/#{Tddium::Api::Path::START_TEST_EXECUTIONS}", response)
585
+ before {stub_call_api_response(:post, "#{Tddium::Api::Path::SESSIONS}/#{SAMPLE_SESSION_ID}/#{Tddium::Api::Path::START_TEST_EXECUTIONS}", {"started"=>1, "status"=>0, "report" => SAMPLE_REPORT_URL})}
586
+
587
+ it "should show the user: '#{Tddium::Text::Process::CHECK_TEST_REPORT % SAMPLE_REPORT_URL}'" do
588
+ tddium.should_receive(:say).with(Tddium::Text::Process::CHECK_TEST_REPORT % SAMPLE_REPORT_URL)
589
+ run_spec(tddium)
560
590
  end
561
591
 
562
592
  it "should tell the user to '#{Tddium::Text::Process::TERMINATE_INSTRUCTION}'" do
@@ -577,8 +607,8 @@ describe Tddium do
577
607
  it_should_behave_like "sending the api key"
578
608
 
579
609
  shared_examples_for("test output summary") do
580
- it "should show the user a link to the report" do
581
- tddium.should_receive(:say).with(Tddium::Text::Process::CHECK_TEST_REPORT % SAMPLE_REPORT_URL)
610
+ it "should put a new line before displaying the summary" do
611
+ tddium.should_receive(:say).with(" ")
582
612
  run_spec(tddium)
583
613
  end
584
614
 
@@ -679,8 +709,13 @@ describe Tddium do
679
709
  it_should_behave_like ".tddium file is missing or corrupt"
680
710
  it_should_behave_like "suite has not been initialized"
681
711
 
712
+ it "should send a 'GET' request to '#{Tddium::Api::Path::SUITES}'" do
713
+ call_api_should_receive(:method => :get, :path => Tddium::Api::Path::SUITES)
714
+ run_status(tddium)
715
+ end
716
+
682
717
  context "'GET #{Tddium::Api::Path::SUITES}' is successful" do
683
- context "returns no suites" do
718
+ context "but returns no suites" do
684
719
  before { stub_call_api_response(:get, Tddium::Api::Path::SUITES, {"suites" => []}) }
685
720
 
686
721
  it "should show the user '#{Tddium::Text::Status::NO_SUITE}'" do
@@ -689,11 +724,10 @@ describe Tddium do
689
724
  end
690
725
  end
691
726
 
692
- context "returns some suites" do
727
+ context "and returns some suites" do
693
728
  let(:suite_attributes) { {"id"=>SAMPLE_SUITE_ID, "repo_name"=>SAMPLE_APP_NAME, "ruby_version"=>SAMPLE_RUBY_VERSION, "branch" => SAMPLE_BRANCH_NAME, "test_pattern" => SAMPLE_TEST_PATTERN, "bundler_version" => SAMPLE_BUNDLER_VERSION, "rubygems_version" => SAMPLE_RUBYGEMS_VERSION}}
694
729
  before do
695
- suites_response = {"suites"=>[suite_attributes], "status"=>0}
696
- stub_call_api_response(:get, Tddium::Api::Path::SUITES, suites_response)
730
+ stub_call_api_response(:get, Tddium::Api::Path::SUITES, {"suites"=>[suite_attributes]})
697
731
  end
698
732
 
699
733
  it "should show all suites" do
@@ -749,8 +783,7 @@ describe Tddium do
749
783
  context "show active sessions" do
750
784
  context "without any session" do
751
785
  before do
752
- sessions_response = {"status"=>0, "sessions"=>[]}
753
- stub_call_api_response(:get, Tddium::Api::Path::SESSIONS, sessions_response)
786
+ stub_call_api_response(:get, Tddium::Api::Path::SESSIONS, {"sessions"=>[]})
754
787
  end
755
788
 
756
789
  it "should display no active session message" do
@@ -762,26 +795,33 @@ describe Tddium do
762
795
  context "with some sessions" do
763
796
  let(:session_attributes) { {"id"=>SAMPLE_SESSION_ID, "user_id"=>3} }
764
797
  before do
765
- sessions_response = {"status"=>0, "sessions"=>[session_attributes]}
766
- stub_call_api_response(:get, Tddium::Api::Path::SESSIONS, sessions_response)
798
+ stub_call_api_response(:get, Tddium::Api::Path::SESSIONS, {"sessions"=>[session_attributes]})
767
799
  end
768
800
 
769
- it "should display the active sessions prompt" do
801
+ it "should show the user: '#{Tddium::Text::Status::ACTIVE_SESSIONS}'" do
770
802
  tddium.should_receive(:say).with(Tddium::Text::Status::ACTIVE_SESSIONS)
771
803
  run_status(tddium)
772
804
  end
773
805
 
774
- it_should_behave_like "attribute details" do
775
- let(:attributes_to_display) {Tddium::DisplayedAttributes::TEST_EXECUTION}
776
- let(:attributes_to_hide) { [/id/] }
777
- let(:attributes) { session_attributes }
806
+ it "should send a 'GET' request to '#{Tddium::Api::Path::TEST_EXECUTIONS}'" do
807
+ call_api_should_receive(:method => :get, :path => /#{Tddium::Api::Path::TEST_EXECUTIONS}$/)
808
+ run_status(tddium)
809
+ end
810
+
811
+ context "'GET #{Tddium::Api::Path::TEST_EXECUTIONS}' is successful" do
812
+ let(:test_execution_attributes) { {"report" => SAMPLE_REPORT_URL, "test_execution_stats" => SAMPLE_TEST_EXECUTION_STATS, "start_time" => SAMPLE_DATE_TIME, "end_time" => SAMPLE_DATE_TIME} }
813
+ before { stub_call_api_response(:get, /#{Tddium::Api::Path::TEST_EXECUTIONS}$/, test_execution_attributes) }
814
+ it_should_behave_like "attribute details" do
815
+ let(:attributes_to_display) {Tddium::DisplayedAttributes::TEST_EXECUTION}
816
+ let(:attributes_to_hide) { [] }
817
+ let(:attributes) { test_execution_attributes }
818
+ end
778
819
  end
779
820
  end
780
821
  end
781
822
  end
782
823
  end
783
824
  end
784
-
785
825
  it_should_behave_like "an unsuccessful api call"
786
826
  end
787
827
 
@@ -803,7 +843,7 @@ describe Tddium do
803
843
  context ".tddium file contains no suites" do
804
844
  before do
805
845
  stub_default_suite_name
806
- stub_call_api_response(:get, Tddium::Api::Path::SUITES, {"suites" => []}, :and_return => SAMPLE_CALL_API_RESPONSE)
846
+ stub_call_api_response(:get, Tddium::Api::Path::SUITES, {"suites" => []})
807
847
  end
808
848
 
809
849
  context "using defaults" do
@@ -850,7 +890,7 @@ describe Tddium do
850
890
 
851
891
  context "but this user has already registered some suites" do
852
892
  before do
853
- stub_call_api_response(:get, Tddium::Api::Path::SUITES, SAMPLE_SUITES_RESPONSE, {"suites" => []}, :and_return => SAMPLE_CALL_API_RESPONSE)
893
+ stub_call_api_response(:get, Tddium::Api::Path::SUITES, SAMPLE_SUITES_RESPONSE, {"suites" => []})
854
894
  tddium.stub(:ask).with(Tddium::Text::Prompt::USE_EXISTING_SUITE % SAMPLE_APP_NAME).and_return(Tddium::Text::Prompt::Response::YES)
855
895
  end
856
896
 
@@ -871,7 +911,7 @@ describe Tddium do
871
911
 
872
912
  context "passing --name=my_suite" do
873
913
  before do
874
- stub_call_api_response(:get, Tddium::Api::Path::SUITES, SAMPLE_SUITES_RESPONSE, :and_return => SAMPLE_CALL_API_RESPONSE)
914
+ stub_call_api_response(:get, Tddium::Api::Path::SUITES, SAMPLE_SUITES_RESPONSE)
875
915
  end
876
916
 
877
917
  it "should not ask the user if they want to use the existing suite" do
@@ -890,7 +930,7 @@ describe Tddium do
890
930
 
891
931
  context "the user wants to use the existing suite" do
892
932
  before do
893
- stub_call_api_response(:get, Tddium::Api::Path::SUITES, SAMPLE_SUITES_RESPONSE, :and_return => SAMPLE_CALL_API_RESPONSE)
933
+ stub_call_api_response(:get, Tddium::Api::Path::SUITES, SAMPLE_SUITES_RESPONSE)
894
934
  end
895
935
 
896
936
  it "should not send a 'POST' request to '#{Tddium::Api::Path::SUITES}'" do
data/tddium.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  s.authors = ["Jay Moorthi"]
14
14
  s.email = ["info@tddium.com"]
15
15
  s.homepage = "http://www.tddium.com/"
16
- s.summary = %q{tddium Cloud Test Runner}
17
- s.description = %q{tddium gets your rspec+selenium tests into the cloud by running them on your VMs}
16
+ s.summary = %q{tddium Hosted Testing}
17
+ s.description = %q{tddium runs your rspec (and Selenium) tests in the cloud, in parallel!}
18
18
 
19
19
  s.rubyforge_project = "tddium"
20
20
 
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.add_runtime_dependency("thor")
27
27
  s.add_runtime_dependency("highline")
28
28
  s.add_runtime_dependency("json")
29
- s.add_runtime_dependency("tddium_client", "=0.0.3")
29
+ s.add_runtime_dependency("tddium_client", ">=0.0.6")
30
30
 
31
31
  s.add_development_dependency("rspec")
32
32
  s.add_development_dependency("fakefs")
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tddium-preview
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 4
10
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jay Moorthi
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-03-31 00:00:00 -07:00
17
+ date: 2011-04-04 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -54,7 +51,6 @@ dependencies:
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- hash: 3
58
54
  segments:
59
55
  - 0
60
56
  version: "0"
@@ -66,14 +62,13 @@ dependencies:
66
62
  requirement: &id004 !ruby/object:Gem::Requirement
67
63
  none: false
68
64
  requirements:
69
- - - "="
65
+ - - ">="
70
66
  - !ruby/object:Gem::Version
71
- hash: 25
72
67
  segments:
73
68
  - 0
74
69
  - 0
75
- - 3
76
- version: 0.0.3
70
+ - 6
71
+ version: 0.0.6
77
72
  type: :runtime
78
73
  version_requirements: *id004
79
74
  - !ruby/object:Gem::Dependency
@@ -84,7 +79,6 @@ dependencies:
84
79
  requirements:
85
80
  - - ">="
86
81
  - !ruby/object:Gem::Version
87
- hash: 3
88
82
  segments:
89
83
  - 0
90
84
  version: "0"
@@ -98,7 +92,6 @@ dependencies:
98
92
  requirements:
99
93
  - - ">="
100
94
  - !ruby/object:Gem::Version
101
- hash: 3
102
95
  segments:
103
96
  - 0
104
97
  version: "0"
@@ -112,7 +105,6 @@ dependencies:
112
105
  requirements:
113
106
  - - ">="
114
107
  - !ruby/object:Gem::Version
115
- hash: 3
116
108
  segments:
117
109
  - 0
118
110
  version: "0"
@@ -126,13 +118,12 @@ dependencies:
126
118
  requirements:
127
119
  - - ">="
128
120
  - !ruby/object:Gem::Version
129
- hash: 3
130
121
  segments:
131
122
  - 0
132
123
  version: "0"
133
124
  type: :development
134
125
  version_requirements: *id008
135
- description: tddium gets your rspec+selenium tests into the cloud by running them on your VMs
126
+ description: tddium runs your rspec (and Selenium) tests in the cloud, in parallel!
136
127
  email:
137
128
  - info@tddium.com
138
129
  executables:
@@ -171,7 +162,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
162
  requirements:
172
163
  - - ">="
173
164
  - !ruby/object:Gem::Version
174
- hash: 3
175
165
  segments:
176
166
  - 0
177
167
  version: "0"
@@ -180,17 +170,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
170
  requirements:
181
171
  - - ">="
182
172
  - !ruby/object:Gem::Version
183
- hash: 3
184
173
  segments:
185
174
  - 0
186
175
  version: "0"
187
176
  requirements: []
188
177
 
189
178
  rubyforge_project: tddium
190
- rubygems_version: 1.5.2
179
+ rubygems_version: 1.3.7
191
180
  signing_key:
192
181
  specification_version: 3
193
- summary: tddium Cloud Test Runner
182
+ summary: tddium Hosted Testing
194
183
  test_files:
195
184
  - spec/spec_helper.rb
196
185
  - spec/tddium_spec.rb