tddium-preview 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tddium-preview (0.5.3)
4
+ tddium-preview (0.5.4)
5
5
  bundler
6
6
  highline
7
7
  json
data/lib/tddium/heroku.rb CHANGED
@@ -2,15 +2,23 @@
2
2
  Copyright (c) 2011 Solano Labs All Rights Reserved
3
3
  =end
4
4
 
5
+ require 'timeout'
6
+
5
7
  class HerokuConfig
6
8
  REQUIRED_KEYS = %w{TDDIUM_API_KEY TDDIUM_USER_NAME}
7
9
  def self.read_config(app=nil)
8
10
  result = nil
9
11
  begin
10
12
  config = {}
13
+
11
14
  command = "heroku config -s"
12
15
  command += " --app #{app}" if app
13
- output = `#{command}`
16
+
17
+ output = ''
18
+ Timeout::timeout(5) {
19
+ output = `#{command} 2>&1`
20
+ }
21
+
14
22
  output.lines.each do |line|
15
23
  line.chomp!
16
24
  k, v = line.split('=')
@@ -18,7 +26,7 @@ class HerokuConfig
18
26
  config[k] = v
19
27
  end
20
28
  end
21
- return nil if REQUIRED_KEYS.inject(false) {|missing, x| !config[x]}
29
+ return nil if REQUIRED_KEYS.inject(false) {|missing, x| missing || !config[x]}
22
30
  result = config if config.keys.length > 0
23
31
  rescue
24
32
  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.5.4"
6
+ VERSION = "0.5.5"
7
7
  end
data/lib/tddium.rb CHANGED
@@ -227,8 +227,11 @@ class Tddium < Thor
227
227
  "max_parallelism" => max_parallelism,
228
228
  "test_pattern" => test_pattern})
229
229
 
230
- exit_failure if test_statuses["failed"] > 0 || test_statuses["errors"] > 0
230
+ exit_failure if test_statuses["failed"] > 0 || test_statuses["error"] > 0
231
231
  rescue TddiumClient::Error::Base
232
+ exit_failure "Failed due to error communicating with Tddium"
233
+ rescue RuntimeError => e
234
+ exit_failure "Failed due to internal error: #{e.inspect} #{e.backtrace}"
232
235
  end
233
236
  end
234
237
 
@@ -518,9 +521,14 @@ class Tddium < Thor
518
521
  # Given the user is logged in, she should be able to use "tddium account" to display information about her account:
519
522
  # Email address
520
523
  # Account creation date
521
- say api_response["user"]["email"]
522
- say api_response["user"]["created_at"]
523
- say api_response["user"]["recurly_url"]
524
+ say "Username: "+api_response["user"]["email"]
525
+ say "Account Created: " + api_response["user"]["created_at"]
526
+ say "Recurly Management URL: " + api_response["user"]["recurly_url"]
527
+ say "CI Public Key: " + api_response["user"]["ci_ssh_pubkey"] if api_response["user"]["ci_ssh_pubkey"]
528
+ say "Suites: " + api_response["user"]["suites"] if api_response["user"]["suites"]
529
+ end
530
+
531
+ def show_ci_info(api_response)
524
532
  end
525
533
 
526
534
  def suite_for_current_branch?
data/spec/heroku_spec.rb CHANGED
@@ -21,7 +21,7 @@ DB_URL=postgres://foo/bar
21
21
  describe ".read_config" do
22
22
  context "addon installed" do
23
23
  before do
24
- HerokuConfig.stub(:`).with("heroku config -s").and_return(SAMPLE_HEROKU_CONFIG_TDDIUM)
24
+ HerokuConfig.stub(:`).with("heroku config -s 2>&1").and_return(SAMPLE_HEROKU_CONFIG_TDDIUM)
25
25
  end
26
26
 
27
27
  it "should return a hash of the TDDIUM config vars" do
@@ -38,8 +38,8 @@ DB_URL=postgres://foo/bar
38
38
 
39
39
  context "with app specified" do
40
40
  before do
41
- HerokuConfig.stub(:`).with("heroku config -s --app #{SAMPLE_APP}").and_return(SAMPLE_HEROKU_CONFIG_TDDIUM)
42
- HerokuConfig.should_receive(:`).with("heroku config -s --app #{SAMPLE_APP}")
41
+ HerokuConfig.stub(:`).with("heroku config -s --app #{SAMPLE_APP} 2>&1").and_return(SAMPLE_HEROKU_CONFIG_TDDIUM)
42
+ HerokuConfig.should_receive(:`).with("heroku config -s --app #{SAMPLE_APP} 2>&1")
43
43
  end
44
44
 
45
45
  it "should pass the app to heroku config" do
@@ -50,7 +50,7 @@ DB_URL=postgres://foo/bar
50
50
 
51
51
  context "missing config" do
52
52
  before do
53
- HerokuConfig.stub(:`).with("heroku config -s").and_return(SAMPLE_HEROKU_CONFIG_PARTIAL)
53
+ HerokuConfig.stub(:`).with("heroku config -s 2>&1").and_return(SAMPLE_HEROKU_CONFIG_PARTIAL)
54
54
  end
55
55
 
56
56
  it "should return nil" do
@@ -60,7 +60,7 @@ DB_URL=postgres://foo/bar
60
60
 
61
61
  context "addon not installed" do
62
62
  before do
63
- HerokuConfig.stub(:`).with("heroku config -s").and_return(SAMPLE_HEROKU_CONFIG_NO_TDDIUM)
63
+ HerokuConfig.stub(:`).with("heroku config -s 2>&1").and_return(SAMPLE_HEROKU_CONFIG_NO_TDDIUM)
64
64
  end
65
65
 
66
66
  it "should return nil" do
@@ -70,7 +70,7 @@ DB_URL=postgres://foo/bar
70
70
 
71
71
  context "heroku not installed" do
72
72
  before do
73
- HerokuConfig.stub(:`).with("heroku config -s").and_raise(Errno::ENOENT)
73
+ HerokuConfig.stub(:`).with("heroku config -s 2>&1").and_raise(Errno::ENOENT)
74
74
  end
75
75
  it "should return nil" do
76
76
  HerokuConfig.read_config.should be_nil
data/spec/tddium_spec.rb CHANGED
@@ -118,6 +118,15 @@ describe Tddium do
118
118
  result.and_return(*response_mocks) unless response_mocks.empty?
119
119
  end
120
120
 
121
+ def stub_call_api_error(method, path, code=500, response="Server Error")
122
+ result = tddium_client.stub(:call_api).with(method, path, anything, anything)
123
+ http_response = mock(TddiumClient::Error::Server)
124
+ http_response.stub(:body => nil,
125
+ :code => code,
126
+ :response => mock(:header => mock(:msg => response)))
127
+ result.and_raise(TddiumClient::Error::Server.new(http_response))
128
+ end
129
+
121
130
  def stub_cli_options(tddium, options = {})
122
131
  tddium.stub(:options).and_return(options)
123
132
  end
@@ -460,6 +469,7 @@ describe Tddium do
460
469
  HighLine.stub(:ask).and_return("")
461
470
  create_file(File.join(File.dirname(__FILE__), "..", Tddium::License::FILE_NAME), SAMPLE_LICENSE_TEXT)
462
471
  create_file(Tddium::Default::SSH_FILE, SAMPLE_SSH_PUBKEY)
472
+ HerokuConfig.stub(:read_config).and_return(nil)
463
473
  end
464
474
 
465
475
  it_should_behave_like "set the default environment"
@@ -471,17 +481,17 @@ describe Tddium do
471
481
  end
472
482
 
473
483
  it "should show the user's email address" do
474
- tddium.should_receive(:say).with(SAMPLE_EMAIL)
484
+ tddium.should_receive(:say).with(/#{SAMPLE_EMAIL}/)
475
485
  run_account(tddium)
476
486
  end
477
487
 
478
488
  it "should show the user's account creation date" do
479
- tddium.should_receive(:say).with(SAMPLE_DATE_TIME)
489
+ tddium.should_receive(:say).with(/#{SAMPLE_DATE_TIME}/)
480
490
  run_account(tddium)
481
491
  end
482
492
 
483
493
  it "should show the user's recurly account url" do
484
- tddium.should_receive(:say).with(SAMPLE_RECURLY_URL)
494
+ tddium.should_receive(:say).with(/#{SAMPLE_RECURLY_URL}/)
485
495
  run_account(tddium)
486
496
  end
487
497
 
@@ -868,6 +878,16 @@ describe Tddium do
868
878
 
869
879
  it_should_behave_like "sending the api key"
870
880
 
881
+ it "should fail on an API error" do
882
+ stub_call_api_error(:post, Tddium::Api::Path::SESSIONS, 403, "Access Denied")
883
+ spec_should_fail
884
+ end
885
+
886
+ it "should fail on any other error" do
887
+ tddium_client.stub(:call_api).with(anything, anything, anything, anything).and_raise("generic runtime error")
888
+ spec_should_fail
889
+ end
890
+
871
891
  context "'POST #{Tddium::Api::Path::SESSIONS}' is successful" do
872
892
  before do
873
893
  response = {"session"=>{"id"=>SAMPLE_SESSION_ID}}
@@ -1067,6 +1087,21 @@ describe Tddium do
1067
1087
 
1068
1088
  it_should_behave_like("test output summary")
1069
1089
  end
1090
+
1091
+ context "with only errors" do
1092
+ before do
1093
+ get_test_executions_response_errors = {"report"=>SAMPLE_REPORT_URL, "tests"=>{"spec/mouse_spec.rb"=>{"finished" => true, "status"=>"error"}, "spec/pig_spec.rb"=>{"finished" => true, "status"=>"error"}, "spec/dog_spec.rb"=>{"finished" => true, "status"=>"error"}, "spec/cat_spec.rb"=>{"finished" => true, "status"=>"error"}}}
1094
+ stub_call_api_response(:get, "#{Tddium::Api::Path::SESSIONS}/#{SAMPLE_SESSION_ID}/#{Tddium::Api::Path::TEST_EXECUTIONS}", get_test_executions_response_errors)
1095
+ stub_sleep(tddium)
1096
+ end
1097
+ it "should display a summary of all the tests and exit failure" do
1098
+ tddium.should_receive(:say).with("4 tests, 0 failures, 4 errors, 0 pending")
1099
+ spec_should_fail do
1100
+ tddium.should_receive(:exit_failure).once
1101
+ end
1102
+ end
1103
+ end
1104
+
1070
1105
  context "with no errors" do
1071
1106
  before do
1072
1107
  get_test_executions_response_all_passed = {
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tddium-preview
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.4
5
+ version: 0.5.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Solano Labs
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-02 00:00:00 -07:00
13
+ date: 2011-06-14 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency