tddium-preview 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/tddium.rb +15 -12
- data/lib/tddium/version.rb +1 -1
- data/spec/tddium_spec.rb +127 -43
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/lib/tddium.rb
CHANGED
@@ -22,11 +22,6 @@ require File.expand_path("../tddium/constant", __FILE__)
|
|
22
22
|
# tddium account # View/Manage account information
|
23
23
|
# tddium account:password # Change password
|
24
24
|
#
|
25
|
-
# tddium dev # Enter "dev" mode, for single-test quick-turnaround debugging.
|
26
|
-
# tddium stopdev # Leave "dev" mode.
|
27
|
-
#
|
28
|
-
# tddium clean # Clean up test results, especially large objects like videos
|
29
|
-
#
|
30
25
|
# tddium help # Print this usage message
|
31
26
|
|
32
27
|
class Tddium < Thor
|
@@ -131,7 +126,7 @@ class Tddium < Thor
|
|
131
126
|
method_option :test_pattern, :type => :string, :default => Default::TEST_PATTERN
|
132
127
|
def spec
|
133
128
|
set_default_environment(options[:environment])
|
134
|
-
|
129
|
+
exit_failure unless git_repo? && tddium_settings && suite_for_current_branch?
|
135
130
|
|
136
131
|
test_execution_params = {}
|
137
132
|
|
@@ -144,8 +139,7 @@ class Tddium < Thor
|
|
144
139
|
test_execution_params[:user_data_text] = Base64.encode64(user_data)
|
145
140
|
test_execution_params[:user_data_filename] = File.basename(user_data_file_path)
|
146
141
|
else
|
147
|
-
|
148
|
-
return
|
142
|
+
exit_failure Text::Error::NO_USER_DATA_FILE % user_data_file_path
|
149
143
|
end
|
150
144
|
end
|
151
145
|
|
@@ -170,14 +164,13 @@ class Tddium < Thor
|
|
170
164
|
suite_details = call_api(:get, current_suite_path)
|
171
165
|
|
172
166
|
# Push the latest code to git
|
173
|
-
|
167
|
+
exit_failure unless update_git_remote_and_push(suite_details)
|
174
168
|
|
175
169
|
# Get a list of files to be tested
|
176
170
|
test_files = Dir.glob(test_pattern).collect {|file_path| {:test_name => file_path}}
|
177
171
|
|
178
172
|
if test_files.empty?
|
179
|
-
|
180
|
-
return
|
173
|
+
exit_failure Text::Error::NO_MATCHING_FILES % test_pattern
|
181
174
|
end
|
182
175
|
|
183
176
|
# Create a session
|
@@ -224,7 +217,11 @@ class Tddium < Thor
|
|
224
217
|
end
|
225
218
|
|
226
219
|
# If all tests finished, exit the loop else sleep
|
227
|
-
finished_tests.size == current_test_executions["tests"].size
|
220
|
+
if finished_tests.size == current_test_executions["tests"].size
|
221
|
+
tests_not_finished_yet = false
|
222
|
+
else
|
223
|
+
sleep(Default::SLEEP_TIME_BETWEEN_POLLS)
|
224
|
+
end
|
228
225
|
end
|
229
226
|
|
230
227
|
# Print out the result
|
@@ -236,6 +233,8 @@ class Tddium < Thor
|
|
236
233
|
write_suite(current_suite_id, {"user_data_file" => user_data_file_path,
|
237
234
|
"max_parallelism" => max_parallelism,
|
238
235
|
"test_pattern" => test_pattern})
|
236
|
+
|
237
|
+
exit_failure if test_statuses["failed"] > 0 || test_statuses["errors"] > 0
|
239
238
|
rescue TddiumClient::Error::Base
|
240
239
|
end
|
241
240
|
end
|
@@ -389,6 +388,10 @@ class Tddium < Thor
|
|
389
388
|
tddium_client.environment.to_sym
|
390
389
|
end
|
391
390
|
|
391
|
+
def exit_failure(msg='')
|
392
|
+
abort msg
|
393
|
+
end
|
394
|
+
|
392
395
|
def get_user
|
393
396
|
call_api(:get, Api::Path::USERS, {}, nil, false) rescue nil
|
394
397
|
end
|
data/lib/tddium/version.rb
CHANGED
data/spec/tddium_spec.rb
CHANGED
@@ -5,6 +5,8 @@ Copyright (c) 2011 Solano Labs All Rights Reserved
|
|
5
5
|
|
6
6
|
require 'spec_helper'
|
7
7
|
|
8
|
+
class EXIT_FAILURE_EXCEPTION < RuntimeError; end
|
9
|
+
|
8
10
|
describe Tddium do
|
9
11
|
include FakeFS::SpecHelpers
|
10
12
|
include TddiumSpecHelpers
|
@@ -54,7 +56,8 @@ describe Tddium do
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def run(tddium, options = {:test_pattern => DEFAULT_TEST_PATTERN, :environment => "test"})
|
57
|
-
|
59
|
+
method = example.example_group.ancestors.map(&:description)[-2][1..-1]
|
60
|
+
send("run_#{method}", tddium, options)
|
58
61
|
end
|
59
62
|
|
60
63
|
[:suite, :spec, :status, :account, :login, :logout, :password].each do |method|
|
@@ -62,10 +65,14 @@ describe Tddium do
|
|
62
65
|
options = params.first || {}
|
63
66
|
if method == :spec
|
64
67
|
options[:test_pattern] = DEFAULT_TEST_PATTERN unless options.has_key?(:test_pattern)
|
68
|
+
stub_exit_failure
|
65
69
|
end
|
66
70
|
options[:environment] = "test" unless options.has_key?(:environment)
|
67
71
|
stub_cli_options(tddium, options)
|
68
|
-
|
72
|
+
begin
|
73
|
+
tddium.send(method)
|
74
|
+
rescue EXIT_FAILURE_EXCEPTION
|
75
|
+
end
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
@@ -143,6 +150,10 @@ describe Tddium do
|
|
143
150
|
tddium.stub(:sleep).with(Tddium::Default::SLEEP_TIME_BETWEEN_POLLS)
|
144
151
|
end
|
145
152
|
|
153
|
+
def stub_exit_failure
|
154
|
+
tddium.stub(:exit_failure).and_raise(EXIT_FAILURE_EXCEPTION)
|
155
|
+
end
|
156
|
+
|
146
157
|
def stub_tddium_client
|
147
158
|
TddiumClient::Client.stub(:new).and_return(tddium_client)
|
148
159
|
tddium_client.stub(:environment).and_return("test")
|
@@ -646,17 +657,38 @@ describe Tddium do
|
|
646
657
|
stub_config_file(:api_key => true, :branches => true)
|
647
658
|
end
|
648
659
|
|
649
|
-
it_should_behave_like "set the default environment"
|
660
|
+
it_should_behave_like "set the default environment" do
|
661
|
+
let(:run_function) {spec_should_fail}
|
662
|
+
end
|
650
663
|
it_should_behave_like "git repo has not been initialized"
|
651
664
|
it_should_behave_like ".tddium file is missing or corrupt"
|
652
665
|
it_should_behave_like "suite has not been initialized"
|
653
666
|
|
667
|
+
def spec_should_fail(options={})
|
668
|
+
options[:test_pattern] = DEFAULT_TEST_PATTERN unless options.has_key?(:test_pattern)
|
669
|
+
options[:environment] = "test" unless options.has_key?(:environment)
|
670
|
+
stub_cli_options(tddium, options)
|
671
|
+
tddium.stub(:exit_failure).and_raise(SystemExit)
|
672
|
+
yield if block_given?
|
673
|
+
expect { tddium.spec }.to raise_error(SystemExit)
|
674
|
+
end
|
675
|
+
|
676
|
+
def spec_should_pass(options={})
|
677
|
+
options[:test_pattern] = DEFAULT_TEST_PATTERN unless options.has_key?(:test_pattern)
|
678
|
+
options[:environment] = "test" unless options.has_key?(:environment)
|
679
|
+
stub_cli_options(tddium, options)
|
680
|
+
tddium.stub(:exit_failure).and_raise(SystemExit)
|
681
|
+
yield if block_given?
|
682
|
+
expect { tddium.spec }.not_to raise_error
|
683
|
+
end
|
684
|
+
|
654
685
|
context "user-data-file" do
|
655
686
|
context "does not exist" do
|
656
687
|
context "from command line option" do
|
657
688
|
it "should be picked first" do
|
658
|
-
|
659
|
-
|
689
|
+
spec_should_fail(:user_data_file => SAMPLE_FILE_PATH) do
|
690
|
+
tddium.should_receive(:exit_failure).with(Tddium::Text::Error::NO_USER_DATA_FILE % SAMPLE_FILE_PATH)
|
691
|
+
end
|
660
692
|
end
|
661
693
|
end
|
662
694
|
|
@@ -664,19 +696,20 @@ describe Tddium do
|
|
664
696
|
before { stub_config_file(:branches => {SAMPLE_BRANCH_NAME => {"id" => SAMPLE_SUITE_ID, "options" => {"user_data_file" => SAMPLE_FILE_PATH2}}}) }
|
665
697
|
|
666
698
|
it "should be picked if no command line option" do
|
667
|
-
|
668
|
-
|
699
|
+
spec_should_fail do
|
700
|
+
tddium.should_receive(:exit_failure).with(Tddium::Text::Error::NO_USER_DATA_FILE % SAMPLE_FILE_PATH2)
|
701
|
+
end
|
669
702
|
end
|
670
703
|
end
|
671
704
|
|
672
705
|
it "should not try to git push" do
|
673
706
|
tddium.should_not_receive(:system).with(/^git push/)
|
674
|
-
|
707
|
+
spec_should_fail(:user_data_file => SAMPLE_FILE_PATH)
|
675
708
|
end
|
676
709
|
|
677
710
|
it "should not call the api" do
|
678
711
|
tddium_client.should_not_receive(:call_api)
|
679
|
-
|
712
|
+
spec_should_fail(:user_data_file => SAMPLE_FILE_PATH)
|
680
713
|
end
|
681
714
|
end
|
682
715
|
end
|
@@ -699,6 +732,7 @@ describe Tddium do
|
|
699
732
|
context "git push was unsuccessful" do
|
700
733
|
before { stub_git_push(tddium, false) }
|
701
734
|
it "should not try to create a new session" do
|
735
|
+
tddium.should_receive(:exit_failure)
|
702
736
|
tddium_client.should_not_receive(:call_api).with(:post, Tddium::Api::Path::SESSIONS)
|
703
737
|
run_spec(tddium)
|
704
738
|
end
|
@@ -856,7 +890,7 @@ describe Tddium do
|
|
856
890
|
end
|
857
891
|
|
858
892
|
it "should show the user a summary of all the tests" do
|
859
|
-
tddium.should_receive(:say).with("3
|
893
|
+
tddium.should_receive(:say).with("3 tests, 1 failures, 0 errors, 1 pending")
|
860
894
|
run_spec(tddium)
|
861
895
|
end
|
862
896
|
|
@@ -864,48 +898,98 @@ describe Tddium do
|
|
864
898
|
end
|
865
899
|
|
866
900
|
context "'GET #{Tddium::Api::Path::TEST_EXECUTIONS}' is successful" do
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
901
|
+
context "with mixed results" do
|
902
|
+
before do
|
903
|
+
get_test_executions_response_all_finished = {"report"=>SAMPLE_REPORT_URL, "tests"=>{"spec/mouse_spec.rb"=>{"finished" => true, "status"=>"pending"}, "spec/pig_spec.rb"=>{"finished" => true, "status"=>"error"}, "spec/dog_spec.rb"=>{"finished" => true, "status"=>"failed"}, "spec/cat_spec.rb"=>{"finished" => true, "status"=>"passed"}}}
|
904
|
+
stub_call_api_response(:get, "#{Tddium::Api::Path::SESSIONS}/#{SAMPLE_SESSION_ID}/#{Tddium::Api::Path::TEST_EXECUTIONS}", get_test_executions_response, get_test_executions_response_all_finished)
|
905
|
+
stub_sleep(tddium)
|
906
|
+
end
|
872
907
|
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
908
|
+
it "should sleep for #{Tddium::Default::SLEEP_TIME_BETWEEN_POLLS} seconds" do
|
909
|
+
tddium.should_receive(:sleep).exactly(1).times.with(Tddium::Default::SLEEP_TIME_BETWEEN_POLLS)
|
910
|
+
run_spec(tddium)
|
911
|
+
end
|
877
912
|
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
913
|
+
it "should display a green '.'" do
|
914
|
+
tddium.should_receive(:say).with(".", :green, false)
|
915
|
+
run_spec(tddium)
|
916
|
+
end
|
882
917
|
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
918
|
+
it "should display a red 'F'" do
|
919
|
+
tddium.should_receive(:say).with("F", :red, false)
|
920
|
+
run_spec(tddium)
|
921
|
+
end
|
887
922
|
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
923
|
+
it "should display a yellow '*'" do
|
924
|
+
tddium.should_receive(:say).with("*", :yellow, false)
|
925
|
+
run_spec(tddium)
|
926
|
+
end
|
892
927
|
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
928
|
+
it "should display 'E' with no color" do
|
929
|
+
tddium.should_receive(:say).with("E", nil, false)
|
930
|
+
run_spec(tddium)
|
931
|
+
end
|
897
932
|
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
933
|
+
it "should display a summary of all the tests" do
|
934
|
+
tddium.should_receive(:say).with("4 tests, 1 failures, 1 errors, 1 pending")
|
935
|
+
spec_should_fail do
|
936
|
+
tddium.should_receive(:exit_failure).once
|
937
|
+
end
|
938
|
+
end
|
902
939
|
|
903
|
-
|
904
|
-
|
905
|
-
|
940
|
+
it "should save the spec options" do
|
941
|
+
tddium.should_receive(:write_suite).with(SAMPLE_SUITE_ID, {"user_data_file" => nil, "max_parallelism" => 3, "test_pattern" => DEFAULT_TEST_PATTERN})
|
942
|
+
run_spec(tddium, {:max_parallelism => 3})
|
943
|
+
end
|
944
|
+
|
945
|
+
it_should_behave_like("test output summary")
|
906
946
|
end
|
947
|
+
context "with no errors" do
|
948
|
+
before do
|
949
|
+
get_test_executions_response_all_passed = {
|
950
|
+
"report"=>SAMPLE_REPORT_URL,
|
951
|
+
"tests"=>{"spec/mouse_spec.rb"=>{"finished" => true, "status"=>"passed"},
|
952
|
+
"spec/pig_spec.rb"=>{"finished" => true, "status"=>"passed"},
|
953
|
+
"spec/dog_spec.rb"=>{"finished" => true, "status"=>"passed"},
|
954
|
+
"spec/cat_spec.rb"=>{"finished" => true, "status"=>"passed"}}}
|
955
|
+
stub_call_api_response(:get, "#{Tddium::Api::Path::SESSIONS}/#{SAMPLE_SESSION_ID}/#{Tddium::Api::Path::TEST_EXECUTIONS}", get_test_executions_response_all_passed)
|
956
|
+
stub_sleep(tddium)
|
957
|
+
end
|
907
958
|
|
908
|
-
|
959
|
+
it "should display a green '.'" do
|
960
|
+
tddium.should_receive(:say).with(".", :green, false)
|
961
|
+
run_spec(tddium)
|
962
|
+
end
|
963
|
+
|
964
|
+
it "should not display a red 'F'" do
|
965
|
+
tddium.should_not_receive(:say).with("F", :red, false)
|
966
|
+
run_spec(tddium)
|
967
|
+
end
|
968
|
+
|
969
|
+
it "should not display a yellow '*'" do
|
970
|
+
tddium.should_not_receive(:say).with("*", :yellow, false)
|
971
|
+
run_spec(tddium)
|
972
|
+
end
|
973
|
+
|
974
|
+
it "should not display 'E' with no color" do
|
975
|
+
tddium.should_not_receive(:say).with("E", nil, false)
|
976
|
+
run_spec(tddium)
|
977
|
+
end
|
978
|
+
|
979
|
+
it "should display a summary of all the tests" do
|
980
|
+
tddium.should_receive(:say).with("4 tests, 0 failures, 0 errors, 0 pending")
|
981
|
+
spec_should_pass do
|
982
|
+
tddium.should_not_receive(:exit_failure)
|
983
|
+
end
|
984
|
+
end
|
985
|
+
|
986
|
+
it "should save the spec options" do
|
987
|
+
tddium.should_receive(:write_suite).with(SAMPLE_SUITE_ID, {"user_data_file" => nil, "max_parallelism" => 3, "test_pattern" => DEFAULT_TEST_PATTERN})
|
988
|
+
run_spec(tddium, {:max_parallelism => 3})
|
989
|
+
end
|
990
|
+
|
991
|
+
it_should_behave_like("test output summary")
|
992
|
+
end
|
909
993
|
end
|
910
994
|
|
911
995
|
it_should_behave_like "an unsuccessful api call"
|