tddium-preview 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tddium.rb CHANGED
@@ -7,6 +7,7 @@ require "thor"
7
7
  require "highline/import"
8
8
  require "json"
9
9
  require "tddium_client"
10
+ require "base64"
10
11
  require File.expand_path("../tddium/constant", __FILE__)
11
12
 
12
13
  # Usage:
@@ -99,18 +100,33 @@ class Tddium < Thor
99
100
 
100
101
  desc "spec", "Run the test suite"
101
102
  method_option :environment, :type => :string, :default => nil
103
+ method_option :user_data_file, :type => :string, :default => nil
102
104
  def spec
103
105
  set_default_environment(options[:environment])
104
106
  return unless git_repo? && tddium_settings && suite_for_current_branch?
105
107
 
106
- start_time = Time.now
108
+ test_execution_params = {}
109
+ if user_data_file_path = options[:user_data_file]
110
+ if File.exists?(user_data_file_path)
111
+ user_data = File.open(user_data_file_path) { |file| file.read }
112
+ test_execution_params[:user_data_text] = Base64.encode64(user_data)
113
+ test_execution_params[:user_data_filename] = File.basename(user_data_file_path)
114
+ else
115
+ say Text::Error::NO_USER_DATA_FILE % user_data_file_path
116
+ return
117
+ end
118
+ end
107
119
 
108
- # Push the latest code to git
109
- return unless git_push
120
+ start_time = Time.now
110
121
 
111
122
  # Call the API to get the suite and its tests
112
123
  begin
113
124
  suite_details = call_api(:get, current_suite_path)
125
+
126
+ # Push the latest code to git
127
+ return unless update_git_remote_and_push(suite_details)
128
+
129
+ # Get a list of files to be tested
114
130
  test_pattern = suite_details["suite"]["test_pattern"]
115
131
  test_files = Dir.glob(test_pattern).collect {|file_path| {:test_name => file_path}}
116
132
 
@@ -122,7 +138,7 @@ class Tddium < Thor
122
138
  call_api(:post, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::REGISTER_TEST_EXECUTIONS}", {:suite_id => current_suite_id, :tests => test_files})
123
139
 
124
140
  # Start the tests
125
- start_test_executions = call_api(:post, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::START_TEST_EXECUTIONS}")
141
+ start_test_executions = call_api(:post, "#{Api::Path::SESSIONS}/#{session_id}/#{Api::Path::START_TEST_EXECUTIONS}", test_execution_params)
126
142
  tests_not_finished_yet = true
127
143
  finished_tests = {}
128
144
  test_statuses = Hash.new(0)
@@ -162,7 +178,7 @@ class Tddium < Thor
162
178
  end
163
179
 
164
180
  # Print out the result
165
- say " "
181
+ say ""
166
182
  say Text::Process::FINISHED_TEST % (Time.now - start_time)
167
183
  say "#{finished_tests.size} examples, #{test_statuses["failed"]} failures, #{test_statuses["error"]} errors, #{test_statuses["pending"]} pending"
168
184
  rescue TddiumClient::Error::Base
@@ -269,9 +285,7 @@ class Tddium < Thor
269
285
  write_suite(new_suite["suite"]["id"])
270
286
 
271
287
  # 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
288
+ update_git_remote_and_push(new_suite)
275
289
  end
276
290
  rescue TddiumClient::Error::Base
277
291
  end
@@ -430,6 +444,15 @@ class Tddium < Thor
430
444
  @tddium_settings
431
445
  end
432
446
 
447
+ def update_git_remote_and_push(suite_details)
448
+ git_repo_uri = suite_details["suite"]["git_repo_uri"]
449
+ unless `git remote show -n #{Git::REMOTE_NAME}` =~ /#{git_repo_uri}/
450
+ `git remote rm #{Git::REMOTE_NAME}`
451
+ `git remote add #{Git::REMOTE_NAME} #{git_repo_uri}`
452
+ end
453
+ git_push
454
+ end
455
+
433
456
  def user_logged_in?(active = true)
434
457
  result = tddium_settings(:fail_with_message => false) && tddium_settings["api_key"]
435
458
  (result && active) ? get_user : result
@@ -112,6 +112,7 @@ If you want an invite, visit this URL to sign up:
112
112
  http://blog.tddium.com/home/
113
113
 
114
114
  "
115
+ NO_USER_DATA_FILE = "User data file '%s' does not exist"
115
116
  end
116
117
  end
117
118
 
@@ -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.5"
6
+ VERSION = "0.0.6"
7
7
  end
data/spec/tddium_spec.rb CHANGED
@@ -15,6 +15,7 @@ describe Tddium do
15
15
  SAMPLE_BUNDLER_VERSION = "1.10.10"
16
16
  SAMPLE_DATE_TIME = "2011-03-11T08:43:02Z"
17
17
  SAMPLE_EMAIL = "someone@example.com"
18
+ SAMPLE_FILE_PATH = "./my_user_file.png"
18
19
  SAMPLE_INVITATION_TOKEN = "TZce3NueiXp2lMTmaeRr"
19
20
  SAMPLE_GIT_REPO_URI = "ssh://git@api.tddium.com/home/git/repo/#{SAMPLE_APP_NAME}"
20
21
  SAMPLE_LICENSE_TEXT = "LICENSE"
@@ -25,10 +26,11 @@ describe Tddium do
25
26
  SAMPLE_RECURLY_URL = "https://tddium.recurly.com/account/1"
26
27
  SAMPLE_SESSION_ID = 1
27
28
  SAMPLE_SUITE_ID = 1
28
- SAMPLE_SUITES_RESPONSE = {"suites" => [{"repo_name" => SAMPLE_APP_NAME, "branch" => SAMPLE_BRANCH_NAME, "id" => SAMPLE_SUITE_ID}]}
29
+ SAMPLE_TEST_PATTERN = "**/*_spec.rb"
30
+ SAMPLE_SUITE_RESPONSE = {"repo_name" => SAMPLE_APP_NAME, "branch" => SAMPLE_BRANCH_NAME, "id" => SAMPLE_SUITE_ID, "test_pattern"=>SAMPLE_TEST_PATTERN, "ruby_version"=>SAMPLE_RUBY_VERSION, "git_repo_uri" => SAMPLE_GIT_REPO_URI}
31
+ SAMPLE_SUITES_RESPONSE = {"suites" => [SAMPLE_SUITE_RESPONSE]}
29
32
  SAMPLE_TDDIUM_CONFIG_FILE = ".tddium.test"
30
33
  SAMPLE_TEST_EXECUTION_STATS = "total 1, notstarted 0, started 1, passed 0, failed 0, pending 0, error 0", "start_time"
31
- SAMPLE_TEST_PATTERN = "**/*_spec.rb"
32
34
  SAMPLE_USER_RESPONSE = {"user"=> {"api_key" => SAMPLE_API_KEY, "email" => SAMPLE_EMAIL, "created_at" => SAMPLE_DATE_TIME, "recurly_url" => SAMPLE_RECURLY_URL}}
33
35
 
34
36
  def call_api_should_receive(options = {})
@@ -114,6 +116,11 @@ describe Tddium do
114
116
  tddium.stub(:system).with(/^git push/).and_return(success)
115
117
  end
116
118
 
119
+ def stub_git_remote(tddium, action = :show, success = true)
120
+ git_response = success ? "some text that contains #{SAMPLE_GIT_REPO_URI}" : "some text that does not contain the git repo uri" if action == :show
121
+ tddium.stub(:`).with(/^git remote #{action}/).and_return(git_response)
122
+ end
123
+
117
124
  def stub_ruby_version(tddium, version = SAMPLE_RUBY_VERSION)
118
125
  tddium.stub(:`).with("ruby -v").and_return("ruby #{version} (2010-08-16 patchlevel 302) [i686-darwin10.5.0]")
119
126
  end
@@ -253,6 +260,48 @@ describe Tddium do
253
260
  end
254
261
  end
255
262
 
263
+ shared_examples_for "update the git remote and push" do
264
+ context "git remote has changed" do
265
+ before do
266
+ stub_git_remote(tddium, :show, false)
267
+ stub_git_remote(tddium, :add)
268
+ stub_git_remote(tddium, :rm)
269
+ end
270
+
271
+ it "should remove all existing remotes called '#{Tddium::Git::REMOTE_NAME}'" do
272
+ tddium.should_receive(:`).with("git remote rm #{Tddium::Git::REMOTE_NAME}")
273
+ run(tddium)
274
+ end
275
+
276
+ it "should add a new remote called '#{Tddium::Git::REMOTE_NAME}' to '#{SAMPLE_GIT_REPO_URI}'" do
277
+ tddium.should_receive(:`).with("git remote add #{Tddium::Git::REMOTE_NAME} #{SAMPLE_GIT_REPO_URI}")
278
+ run(tddium)
279
+ end
280
+
281
+ end
282
+
283
+ context "git remote has not changed" do
284
+ before do
285
+ stub_git_remote(tddium)
286
+ end
287
+
288
+ it "should not remove any existing remotes" do
289
+ tddium.should_not_receive(:`).with(/git remote rm/)
290
+ run(tddium)
291
+ end
292
+
293
+ it "should not add any new remotes" do
294
+ tddium.should_not_receive(:`).with(/git remote add/)
295
+ run(tddium)
296
+ end
297
+ end
298
+
299
+ it "should push the latest code to '#{Tddium::Git::REMOTE_NAME}'" do
300
+ tddium.should_receive(:system).with("git push #{Tddium::Git::REMOTE_NAME} #{SAMPLE_BRANCH_NAME}")
301
+ run(tddium)
302
+ end
303
+ end
304
+
256
305
  shared_examples_for "with the correct environment extension" do
257
306
  it "should write the api key to the .tddium file with the relevent environment extension" do
258
307
  run(tddium)
@@ -505,7 +554,6 @@ describe Tddium do
505
554
  before do
506
555
  stub_defaults
507
556
  stub_config_file(:api_key => true, :branches => true)
508
- stub_git_push(tddium)
509
557
  end
510
558
 
511
559
  it_should_behave_like "set the default environment"
@@ -513,16 +561,22 @@ describe Tddium do
513
561
  it_should_behave_like ".tddium file is missing or corrupt"
514
562
  it_should_behave_like "suite has not been initialized"
515
563
 
516
- it "should push the latest code to tddium" do
517
- tddium.should_receive(:system).with("git push #{Tddium::Git::REMOTE_NAME} #{SAMPLE_BRANCH_NAME}")
518
- run_spec(tddium)
519
- end
564
+ context "--user-data-file=#{SAMPLE_FILE_PATH}" do
565
+ context "does not exist" do
566
+ it "should show the user: #{Tddium::Text::Error::NO_USER_DATA_FILE % SAMPLE_FILE_PATH}" do
567
+ tddium.should_receive(:say).with(Tddium::Text::Error::NO_USER_DATA_FILE % SAMPLE_FILE_PATH)
568
+ run_spec(tddium, :user_data_file => SAMPLE_FILE_PATH)
569
+ end
520
570
 
521
- context "git push was unsuccessful" do
522
- before { stub_git_push(tddium, false) }
523
- it "should not try to contact the api" do
524
- tddium_client.should_not_receive(:call_api)
525
- run_spec(tddium)
571
+ it "should not try to git push" do
572
+ tddium.should_not_receive(:system).with(/^git push/)
573
+ run_spec(tddium, :user_data_file => SAMPLE_FILE_PATH)
574
+ end
575
+
576
+ it "should not call the api" do
577
+ tddium_client.should_not_receive(:call_api)
578
+ run_spec(tddium, :user_data_file => SAMPLE_FILE_PATH)
579
+ end
526
580
  end
527
581
  end
528
582
 
@@ -531,13 +585,24 @@ describe Tddium do
531
585
 
532
586
  context "'GET #{Tddium::Api::Path::SUITES}/#{SAMPLE_SUITE_ID}' is successful" do
533
587
  before do
534
- response = {"suite"=>{"test_pattern"=>SAMPLE_TEST_PATTERN, "id"=>SAMPLE_SUITE_ID, "suite_name"=>"tddium/demo", "ruby_version"=>SAMPLE_RUBY_VERSION}}
535
- stub_call_api_response(:get, "#{Tddium::Api::Path::SUITES}/#{SAMPLE_SUITE_ID}", response)
588
+ stub_call_api_response(:get, "#{Tddium::Api::Path::SUITES}/#{SAMPLE_SUITE_ID}", {"suite"=>SAMPLE_SUITE_RESPONSE})
589
+ stub_git_push(tddium)
590
+ stub_git_remote(tddium)
536
591
  create_file("spec/mouse_spec.rb")
537
592
  create_file("spec/cat_spec.rb")
538
593
  create_file("spec/dog_spec.rb")
539
594
  end
540
595
 
596
+ it_should_behave_like "update the git remote and push"
597
+
598
+ context "git push was unsuccessful" do
599
+ before { stub_git_push(tddium, false) }
600
+ it "should not try to create a new session" do
601
+ tddium_client.should_not_receive(:call_api).with(:post, Tddium::Api::Path::SESSIONS)
602
+ run_spec(tddium)
603
+ end
604
+ end
605
+
541
606
  it "should send a 'POST' request to '#{Tddium::Api::Path::SESSIONS}'" do
542
607
  call_api_should_receive(:method => :post, :path => Tddium::Api::Path::SESSIONS)
543
608
  run_spec(tddium)
@@ -578,6 +643,19 @@ describe Tddium do
578
643
  run_spec(tddium)
579
644
  end
580
645
 
646
+ context "--user-data-file=#{SAMPLE_FILE_PATH}" do
647
+ before { create_file(SAMPLE_FILE_PATH, SAMPLE_PASSWORD) }
648
+ it "should send 'user_data_filename=#{File.basename(SAMPLE_FILE_PATH)}' to '#{Tddium::Api::Path::START_TEST_EXECUTIONS}'" do
649
+ call_api_should_receive(:method => :post, :path => /#{Tddium::Api::Path::START_TEST_EXECUTIONS}$/, :params => hash_including(:user_data_filename => File.basename(SAMPLE_FILE_PATH)))
650
+ run_spec(tddium, :user_data_file => SAMPLE_FILE_PATH)
651
+ end
652
+
653
+ it "should send 'user_data-text=#{Base64.encode64(SAMPLE_PASSWORD)}' (Base64 encoded file content)" do
654
+ call_api_should_receive(:method => :post, :path => /#{Tddium::Api::Path::START_TEST_EXECUTIONS}$/, :params => hash_including(:user_data_text => Base64.encode64(SAMPLE_PASSWORD)))
655
+ run_spec(tddium, :user_data_file => SAMPLE_FILE_PATH)
656
+ end
657
+ end
658
+
581
659
  it_should_behave_like "sending the api key"
582
660
 
583
661
  context "'POST #{Tddium::Api::Path::START_TEST_EXECUTIONS}' is successful" do
@@ -608,7 +686,7 @@ describe Tddium do
608
686
 
609
687
  shared_examples_for("test output summary") do
610
688
  it "should put a new line before displaying the summary" do
611
- tddium.should_receive(:say).with(" ")
689
+ tddium.should_receive(:say).with("")
612
690
  run_spec(tddium)
613
691
  end
614
692
 
@@ -1005,34 +1083,13 @@ describe Tddium do
1005
1083
 
1006
1084
  context "API response successful" do
1007
1085
  before do
1008
- stub_call_api_response(:post, Tddium::Api::Path::SUITES, {"suite"=>{"id"=>SAMPLE_SUITE_ID, "git_repo_uri" => SAMPLE_GIT_REPO_URI}})
1009
- tddium.stub(:`).with(/^git remote/)
1086
+ stub_call_api_response(:post, Tddium::Api::Path::SUITES, {"suite"=>SAMPLE_SUITE_RESPONSE})
1087
+ stub_git_remote(tddium)
1010
1088
  stub_git_push(tddium)
1011
1089
  end
1012
1090
 
1013
1091
  it_should_behave_like("writing the suite to file")
1014
-
1015
- it "should remove any existing remotes named 'tddium'" do
1016
- tddium.should_receive(:`).with("git remote rm tddium")
1017
- run_suite(tddium)
1018
- end
1019
-
1020
- it "should add a new remote called '#{Tddium::Git::REMOTE_NAME}'" do
1021
- stub_default_suite_name
1022
- tddium.should_receive(:`).with("git remote add #{Tddium::Git::REMOTE_NAME} #{SAMPLE_GIT_REPO_URI}")
1023
- run_suite(tddium)
1024
- end
1025
-
1026
- context "in the branch 'oaktree'" do
1027
- before do
1028
- tddium.stub(:current_git_branch).and_return("oaktree")
1029
- end
1030
-
1031
- it "should push the current git branch to tddium oaktree" do
1032
- tddium.should_receive(:system).with("git push tddium oaktree")
1033
- run_suite(tddium)
1034
- end
1035
- end
1092
+ it_should_behave_like("update the git remote and push")
1036
1093
  end
1037
1094
  it_should_behave_like "an unsuccessful api call"
1038
1095
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tddium-preview
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 5
9
- version: 0.0.5
4
+ prerelease:
5
+ version: 0.0.6
10
6
  platform: ruby
11
7
  authors:
12
8
  - Jay Moorthi
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-04-04 00:00:00 -07:00
13
+ date: 2011-04-12 00:00:00 -07:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,8 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
24
  version: "0"
31
25
  type: :runtime
32
26
  version_requirements: *id001
@@ -38,8 +32,6 @@ dependencies:
38
32
  requirements:
39
33
  - - ">="
40
34
  - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
35
  version: "0"
44
36
  type: :runtime
45
37
  version_requirements: *id002
@@ -51,8 +43,6 @@ dependencies:
51
43
  requirements:
52
44
  - - ">="
53
45
  - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
46
  version: "0"
57
47
  type: :runtime
58
48
  version_requirements: *id003
@@ -64,10 +54,6 @@ dependencies:
64
54
  requirements:
65
55
  - - ">="
66
56
  - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
- - 0
70
- - 6
71
57
  version: 0.0.6
72
58
  type: :runtime
73
59
  version_requirements: *id004
@@ -79,8 +65,6 @@ dependencies:
79
65
  requirements:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
- segments:
83
- - 0
84
68
  version: "0"
85
69
  type: :development
86
70
  version_requirements: *id005
@@ -92,8 +76,6 @@ dependencies:
92
76
  requirements:
93
77
  - - ">="
94
78
  - !ruby/object:Gem::Version
95
- segments:
96
- - 0
97
79
  version: "0"
98
80
  type: :development
99
81
  version_requirements: *id006
@@ -105,8 +87,6 @@ dependencies:
105
87
  requirements:
106
88
  - - ">="
107
89
  - !ruby/object:Gem::Version
108
- segments:
109
- - 0
110
90
  version: "0"
111
91
  type: :development
112
92
  version_requirements: *id007
@@ -118,8 +98,6 @@ dependencies:
118
98
  requirements:
119
99
  - - ">="
120
100
  - !ruby/object:Gem::Version
121
- segments:
122
- - 0
123
101
  version: "0"
124
102
  type: :development
125
103
  version_requirements: *id008
@@ -162,21 +140,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
140
  requirements:
163
141
  - - ">="
164
142
  - !ruby/object:Gem::Version
165
- segments:
166
- - 0
167
143
  version: "0"
168
144
  required_rubygems_version: !ruby/object:Gem::Requirement
169
145
  none: false
170
146
  requirements:
171
147
  - - ">="
172
148
  - !ruby/object:Gem::Version
173
- segments:
174
- - 0
175
149
  version: "0"
176
150
  requirements: []
177
151
 
178
152
  rubyforge_project: tddium
179
- rubygems_version: 1.3.7
153
+ rubygems_version: 1.5.2
180
154
  signing_key:
181
155
  specification_version: 3
182
156
  summary: tddium Hosted Testing