tddium-preview 0.7.2 → 0.7.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/Gemfile.lock +1 -1
- data/lib/tddium.rb +32 -5
- data/lib/tddium/constant.rb +18 -1
- data/lib/tddium/version.rb +1 -1
- data/spec/tddium_spec.rb +66 -21
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/tddium.rb
CHANGED
@@ -26,6 +26,14 @@ require File.expand_path("../tddium/heroku", __FILE__)
|
|
26
26
|
#
|
27
27
|
# tddium help # Print this usage message
|
28
28
|
|
29
|
+
class TddiumError < Exception
|
30
|
+
attr_reader :message
|
31
|
+
|
32
|
+
def initialize(message)
|
33
|
+
@message = message
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
29
37
|
class Tddium < Thor
|
30
38
|
include TddiumConstant
|
31
39
|
|
@@ -47,12 +55,15 @@ class Tddium < Thor
|
|
47
55
|
unless options[:password]
|
48
56
|
password_confirmation = HighLine.ask(Text::Prompt::PASSWORD_CONFIRMATION) { |q| q.echo = "*" }
|
49
57
|
unless password_confirmation == params[:password]
|
50
|
-
|
51
|
-
return
|
58
|
+
exit_failure Text::Process::PASSWORD_CONFIRMATION_INCORRECT
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
55
|
-
|
62
|
+
begin
|
63
|
+
params[:user_git_pubkey] = prompt_ssh_key(options[:ssh_key_file])
|
64
|
+
rescue TddiumError => e
|
65
|
+
exit_failure e.message
|
66
|
+
end
|
56
67
|
|
57
68
|
# Prompt for accepting license
|
58
69
|
content = File.open(File.join(File.dirname(__FILE__), "..", License::FILE_NAME)) do |file|
|
@@ -63,9 +74,15 @@ class Tddium < Thor
|
|
63
74
|
return unless license_accepted.downcase == Text::Prompt::Response::AGREE_TO_LICENSE.downcase
|
64
75
|
|
65
76
|
begin
|
77
|
+
say Text::Process::STARTING_ACCOUNT_CREATION
|
66
78
|
new_user = call_api(:post, Api::Path::USERS, {:user => params}, false, false)
|
67
79
|
write_api_key(new_user["user"]["api_key"])
|
68
|
-
|
80
|
+
role = new_user["user"]["account_role"]
|
81
|
+
if role.nil? || role == "owner"
|
82
|
+
say Text::Process::ACCOUNT_CREATED % [new_user["user"]["email"], new_user["user"]["recurly_url"]]
|
83
|
+
else
|
84
|
+
say Text::Process::ACCOUNT_ADDED % [new_user["user"]["email"], new_user["user"]["account_role"], new_user["user"]["account"]]
|
85
|
+
end
|
69
86
|
rescue TddiumClient::Error::API => e
|
70
87
|
say((e.status == Api::ErrorCode::INVALID_INVITATION) ? Text::Error::INVALID_INVITATION : e.message)
|
71
88
|
rescue TddiumClient::Error::Base => e
|
@@ -531,7 +548,11 @@ class Tddium < Thor
|
|
531
548
|
params = get_user_credentials(:email => heroku_config['TDDIUM_USER_NAME'])
|
532
549
|
params.delete(:email)
|
533
550
|
params[:password_confirmation] = HighLine.ask(Text::Prompt::PASSWORD_CONFIRMATION) { |q| q.echo = "*" }
|
534
|
-
|
551
|
+
begin
|
552
|
+
params[:user_git_pubkey] = prompt_ssh_key(options[:ssh_key])
|
553
|
+
rescue TddiumError => e
|
554
|
+
exit_failure e.message
|
555
|
+
end
|
535
556
|
|
536
557
|
begin
|
537
558
|
user_id = user["user"]["id"]
|
@@ -567,6 +588,12 @@ class Tddium < Thor
|
|
567
588
|
# Prompt for ssh-key file
|
568
589
|
ssh_file = prompt(Text::Prompt::SSH_KEY, options[:ssh_key_file], Default::SSH_FILE)
|
569
590
|
data = File.open(File.expand_path(ssh_file)) {|file| file.read}
|
591
|
+
if data =~ /^-+BEGIN [DR]SA PRIVATE KEY-+/ then
|
592
|
+
raise TddiumError.new(Text::Error::INVALID_SSH_PUBLIC_KEY % ssh_file)
|
593
|
+
end
|
594
|
+
if data !~ /^\s*ssh-(dss|rsa)/ then
|
595
|
+
raise TddiumError.new(Text::Error::INVALID_SSH_PUBLIC_KEY % ssh_file)
|
596
|
+
end
|
570
597
|
data
|
571
598
|
end
|
572
599
|
|
data/lib/tddium/constant.rb
CHANGED
@@ -100,6 +100,20 @@ tddium suite
|
|
100
100
|
tddium spec
|
101
101
|
|
102
102
|
"
|
103
|
+
ACCOUNT_ADDED = "
|
104
|
+
Congratulations %s, your tddium account has been activated.
|
105
|
+
|
106
|
+
You are a %s of the account: %s
|
107
|
+
|
108
|
+
Next, you should:
|
109
|
+
|
110
|
+
1. Register your test suite by running:
|
111
|
+
tddium suite
|
112
|
+
|
113
|
+
2. Start tests by running:
|
114
|
+
tddium spec
|
115
|
+
"
|
116
|
+
STARTING_ACCOUNT_CREATION = "Creating account. This may take a few seconds..."
|
103
117
|
ALREADY_LOGGED_IN = "You're already logged in"
|
104
118
|
LOGGED_IN_SUCCESSFULLY = "Logged in successfully"
|
105
119
|
LOGGED_OUT_SUCCESSFULLY = "Logged out successfully"
|
@@ -185,7 +199,9 @@ EOF
|
|
185
199
|
USER_DETAILS =<<EOF;
|
186
200
|
Username: <%=user["email"]%>
|
187
201
|
Account Created: <%=user["created_at"]%>
|
202
|
+
<% if user["recurly_url"] %>
|
188
203
|
Recurly Management URL: <%=user["recurly_url"]%>
|
204
|
+
<% end %>
|
189
205
|
<% if user["heroku"] %>
|
190
206
|
Heroku Account Linked: <%=user["heroku_activation_done"]%>
|
191
207
|
<% end %>
|
@@ -273,6 +289,7 @@ EOF
|
|
273
289
|
end
|
274
290
|
|
275
291
|
module Error
|
292
|
+
INVALID_SSH_PUBLIC_KEY = '%s does not appear to be a valid SSH public key'
|
276
293
|
GIT_CHANGES_NOT_COMMITTED =<<EOF
|
277
294
|
There are uncommitted changes in the local git repository.
|
278
295
|
|
@@ -304,8 +321,8 @@ EOF
|
|
304
321
|
INVALID_INVITATION = "
|
305
322
|
Your invitation token wasn't recognized. If you have a token, make sure you enter it correctly.
|
306
323
|
If you want an invite, visit this URL to sign up:
|
307
|
-
http://blog.tddium.com/home/
|
308
324
|
|
325
|
+
http://www.tddium.com/
|
309
326
|
"
|
310
327
|
NO_USER_DATA_FILE = "User data file '%s' does not exist"
|
311
328
|
NO_MATCHING_FILES = "No files match '%s'"
|
data/lib/tddium/version.rb
CHANGED
data/spec/tddium_spec.rb
CHANGED
@@ -32,6 +32,8 @@ describe Tddium do
|
|
32
32
|
SAMPLE_SESSION_ID = 1
|
33
33
|
SAMPLE_SUITE_ID = 1
|
34
34
|
SAMPLE_USER_ID = 1
|
35
|
+
SAMPLE_ROLE = "member"
|
36
|
+
SAMPLE_ACCOUNT_NAME = "owner@example.com"
|
35
37
|
DEFAULT_TEST_PATTERN = "**/*_spec.rb"
|
36
38
|
SAMPLE_SUITE_PATTERN = "features/*.feature, spec/**/*_spec.rb"
|
37
39
|
CUSTOM_TEST_PATTERN = "**/cat_spec.rb"
|
@@ -54,7 +56,15 @@ describe Tddium do
|
|
54
56
|
"api_key" => SAMPLE_API_KEY,
|
55
57
|
"email" => SAMPLE_EMAIL,
|
56
58
|
"created_at" => SAMPLE_DATE_TIME,
|
59
|
+
"account" => SAMPLE_EMAIL,
|
57
60
|
"recurly_url" => SAMPLE_RECURLY_URL}}
|
61
|
+
SAMPLE_ADDED_USER_RESPONSE = {"status"=>0, "user"=>
|
62
|
+
{ "id"=>SAMPLE_USER_ID,
|
63
|
+
"api_key" => SAMPLE_API_KEY,
|
64
|
+
"email" => SAMPLE_EMAIL,
|
65
|
+
"created_at" => SAMPLE_DATE_TIME,
|
66
|
+
"account" => SAMPLE_ACCOUNT_NAME,
|
67
|
+
"account_role" => SAMPLE_ROLE}}
|
58
68
|
SAMPLE_HEROKU_USER_RESPONSE = {"user"=>
|
59
69
|
{ "id"=>SAMPLE_USER_ID,
|
60
70
|
"api_key" => SAMPLE_API_KEY,
|
@@ -497,6 +507,28 @@ describe Tddium do
|
|
497
507
|
end
|
498
508
|
end
|
499
509
|
|
510
|
+
|
511
|
+
shared_examples_for "show account usage" do
|
512
|
+
it "should send a 'GET' request to '#{Tddium::Api::Path::ACCOUNT_USAGE}'" do
|
513
|
+
call_api_should_receive(:method => :get, :path => Tddium::Api::Path::ACCOUNT_USAGE)
|
514
|
+
run(tddium)
|
515
|
+
end
|
516
|
+
|
517
|
+
context "'GET #{Tddium::Api::Path::SUITES}' is successful" do
|
518
|
+
before { stub_call_api_response(:get, Tddium::Api::Path::ACCOUNT_USAGE, {"usage" => "something"}) }
|
519
|
+
|
520
|
+
it "should display the account usage" do
|
521
|
+
tddium.should_receive(:say).with("something")
|
522
|
+
run(tddium)
|
523
|
+
end
|
524
|
+
|
525
|
+
it "should show all suites" do
|
526
|
+
tddium.should_receive(:say).with(Tddium::Text::Status::ALL_SUITES % SAMPLE_APP_NAME)
|
527
|
+
run(tddium)
|
528
|
+
end
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
500
532
|
describe "#password" do
|
501
533
|
before do
|
502
534
|
stub_defaults
|
@@ -581,6 +613,23 @@ describe Tddium do
|
|
581
613
|
tddium.should_not_receive(:ask).with(Tddium::Text::Prompt::SSH_KEY % Tddium::Default::SSH_FILE, anything)
|
582
614
|
run(tddium, :ssh_key_file => Tddium::Default::SSH_FILE)
|
583
615
|
end
|
616
|
+
|
617
|
+
it "should fail if key file doesn't contain an SSH key" do
|
618
|
+
create_file(Tddium::Default::SSH_FILE, 'blah blah blah')
|
619
|
+
tddium.should_not_receive(:ask).with(Tddium::Text::Prompt::SSH_KEY % Tddium::Default::SSH_FILE, anything)
|
620
|
+
account_should_fail(tddium, :ssh_key_file => Tddium::Default::SSH_FILE) do
|
621
|
+
tddium.should_receive(:exit_failure).with(Tddium::Text::Error::INVALID_SSH_PUBLIC_KEY % Tddium::Default::SSH_FILE)
|
622
|
+
end
|
623
|
+
end
|
624
|
+
|
625
|
+
it "should fail if key file is an SSH private key" do
|
626
|
+
create_file(Tddium::Default::SSH_FILE, "-----BEGIN RSA PRIVATE KEY-----\n")
|
627
|
+
tddium.should_not_receive(:ask).with(Tddium::Text::Prompt::SSH_KEY % Tddium::Default::SSH_FILE, anything)
|
628
|
+
account_should_fail(tddium, :ssh_key_file => Tddium::Default::SSH_FILE) do
|
629
|
+
tddium.should_receive(:exit_failure).with(Tddium::Text::Error::INVALID_SSH_PUBLIC_KEY % Tddium::Default::SSH_FILE)
|
630
|
+
end
|
631
|
+
end
|
632
|
+
|
584
633
|
end
|
585
634
|
end
|
586
635
|
|
@@ -723,6 +772,7 @@ describe Tddium do
|
|
723
772
|
run_account(tddium)
|
724
773
|
end
|
725
774
|
|
775
|
+
# it_should_behave_like "show account usage"
|
726
776
|
end
|
727
777
|
|
728
778
|
context "the user is not already logged in" do
|
@@ -735,8 +785,9 @@ describe Tddium do
|
|
735
785
|
context "the user does not confirm their password correctly" do
|
736
786
|
before {HighLine.stub(:ask).with(Tddium::Text::Prompt::PASSWORD_CONFIRMATION).and_return("wrong confirmation")}
|
737
787
|
it "should tell the user '#{Tddium::Text::Process::PASSWORD_CONFIRMATION_INCORRECT}'" do
|
738
|
-
tddium
|
739
|
-
|
788
|
+
account_should_fail(tddium) do
|
789
|
+
tddium.should_receive(:exit_failure).with(Tddium::Text::Process::PASSWORD_CONFIRMATION_INCORRECT)
|
790
|
+
end
|
740
791
|
end
|
741
792
|
end
|
742
793
|
|
@@ -770,7 +821,7 @@ describe Tddium do
|
|
770
821
|
run_account(tddium)
|
771
822
|
end
|
772
823
|
|
773
|
-
context "'POST #{Tddium::Api::Path::USERS}'
|
824
|
+
context "'POST #{Tddium::Api::Path::USERS}' succeeds in creating a new account" do
|
774
825
|
before{stub_call_api_response(:post, Tddium::Api::Path::USERS, SAMPLE_USER_RESPONSE)}
|
775
826
|
|
776
827
|
it_should_behave_like "writing the api key to the .tddium file"
|
@@ -780,6 +831,17 @@ describe Tddium do
|
|
780
831
|
run_account(tddium)
|
781
832
|
end
|
782
833
|
end
|
834
|
+
|
835
|
+
context "'POST #{Tddium::Api::Path::USERS}' succeeds in adding a new account" do
|
836
|
+
before{stub_call_api_response(:post, Tddium::Api::Path::USERS, SAMPLE_ADDED_USER_RESPONSE)}
|
837
|
+
|
838
|
+
it_should_behave_like "writing the api key to the .tddium file"
|
839
|
+
|
840
|
+
it "should show the user '#{Tddium::Text::Process::ACCOUNT_ADDED % [SAMPLE_EMAIL, SAMPLE_ROLE, SAMPLE_ACCOUNT_NAME]}'" do
|
841
|
+
tddium.should_receive(:say).with(Tddium::Text::Process::ACCOUNT_ADDED % [SAMPLE_EMAIL, SAMPLE_ROLE, SAMPLE_ACCOUNT_NAME])
|
842
|
+
run_account(tddium)
|
843
|
+
end
|
844
|
+
end
|
783
845
|
context "'POST #{Tddium::Api::Path::USERS}' is unsuccessful" do
|
784
846
|
|
785
847
|
it_should_behave_like "an unsuccessful api call"
|
@@ -1260,6 +1322,7 @@ describe Tddium do
|
|
1260
1322
|
before do
|
1261
1323
|
stub_defaults
|
1262
1324
|
stub_config_file(:api_key => true, :branches => true)
|
1325
|
+
stub_call_api_response(:get, Tddium::Api::Path::SESSIONS, {"sessions"=>[]})
|
1263
1326
|
end
|
1264
1327
|
|
1265
1328
|
it_should_behave_like "set the default environment"
|
@@ -1288,11 +1351,6 @@ describe Tddium do
|
|
1288
1351
|
stub_call_api_response(:get, Tddium::Api::Path::SUITES, {"suites"=>[suite_attributes]})
|
1289
1352
|
end
|
1290
1353
|
|
1291
|
-
it "should show all suites" do
|
1292
|
-
tddium.should_receive(:say).with(Tddium::Text::Status::ALL_SUITES % SAMPLE_APP_NAME)
|
1293
|
-
run_status(tddium)
|
1294
|
-
end
|
1295
|
-
|
1296
1354
|
context "without current suite" do
|
1297
1355
|
before { stub_config_file(:branches => {SAMPLE_BRANCH_NAME => {"id" => 0}}) }
|
1298
1356
|
it "should show the user '#{Tddium::Text::Status::CURRENT_SUITE_UNAVAILABLE}'" do
|
@@ -1375,19 +1433,6 @@ describe Tddium do
|
|
1375
1433
|
end
|
1376
1434
|
end
|
1377
1435
|
|
1378
|
-
it "should send a 'GET' request to '#{Tddium::Api::Path::ACCOUNT_USAGE}'" do
|
1379
|
-
call_api_should_receive(:method => :get, :path => Tddium::Api::Path::ACCOUNT_USAGE)
|
1380
|
-
run_status(tddium)
|
1381
|
-
end
|
1382
|
-
|
1383
|
-
context "'GET #{Tddium::Api::Path::SUITES}' is successful" do
|
1384
|
-
before { stub_call_api_response(:get, Tddium::Api::Path::ACCOUNT_USAGE, {"usage" => "something"}) }
|
1385
|
-
|
1386
|
-
it "should display the account usage" do
|
1387
|
-
tddium.should_receive(:say).with("something")
|
1388
|
-
run_status(tddium)
|
1389
|
-
end
|
1390
|
-
end
|
1391
1436
|
end
|
1392
1437
|
end
|
1393
1438
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: tddium-preview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
5
|
+
version: 0.7.3
|
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-08-
|
13
|
+
date: 2011-08-10 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|