rspec-teamcity 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ # Copyright 2000-2014 JetBrains s.r.o.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # @author Roman.Chernyatchik
16
+
17
+ module Spec
18
+ module Runner
19
+ module Formatter
20
+ # Let's determine current RSpec gem version
21
+ # Formatter is required from some other RSpec code, so let's check some
22
+ # marker classed in object space
23
+
24
+ if defined? ::RSpec::Core::Version::STRING
25
+ if ::RSpec::Core::Version::STRING.split('.')[0] == '2'
26
+ # rspec >= 2.x
27
+ require 'rspec/core/formatters/base_formatter'
28
+ RSPEC_VERSION_2 = true
29
+ RSPEC_VERSION_3 = false
30
+ else
31
+ # rspec >= 3.x
32
+ require 'rspec/core/formatters/base_formatter'
33
+ RSPEC_VERSION_2 = false
34
+ RSPEC_VERSION_3 = true
35
+ end
36
+ elsif defined? ::Spec::VERSION::STRING
37
+ # rspec 1.x
38
+ require 'spec/runner/formatter/base_formatter'
39
+ RSPEC_VERSION_2 = false
40
+ RSPEC_VERSION_3 = false
41
+ else
42
+ # some unsupported version. Let's assume that it is something like rspec 2.x
43
+ # such require may force gem activation
44
+ require 'rspec/core/formatters/base_formatter'
45
+ RSPEC_VERSION_2 = true
46
+ RSPEC_VERSION_3 = false
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ # Copyright 2000-2012 JetBrains s.r.o.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Created by IntelliJ IDEA.
16
+ #
17
+ # @author: Roman.Chernyatchik
18
+ # @date: 21:40:05
19
+
20
+ module Rake
21
+ module TeamCity
22
+ class InnerException < Exception
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,131 @@
1
+ # Copyright 2000-2012 JetBrains s.r.o.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Created by IntelliJ IDEA.
16
+ #
17
+ # @author: Roman.Chernyatchik
18
+ # @date: 29.01.2008
19
+
20
+ #TODO move all to TeamCity module
21
+
22
+ # Behaviour properties
23
+ # Debug
24
+ TEAMCITY_RAKERUNNER_LOG_RSPEC_XML_MSFS_KEY = 'TEAMCITY_RAKE_RUNNER_DEBUG_LOG_RSPEC_XML_MSGS'
25
+ TEAMCITY_RAKERUNNER_LOG_PATH_KEY = 'TEAMCITY_RAKE_RUNNER_DEBUG_LOG_PATH'
26
+ TEAMCITY_RAKERUNNER_LOG_OUTPUT_HACK_DISABLED_KEY = 'TEAMCITY_RAKE_RUNNER_DEBUG_OUTPUT_HACK_DISABLED'
27
+ TEAMCITY_RAKERUNNER_LOG_OUTPUT_CAPTURER_ENABLED_KEY = 'TEAMCITY_RAKE_RUNNER_DEBUG_OUTPUT_CAPTURER_ENABLED'
28
+ # Log files
29
+ TEAMCITY_RAKERUNNER_LOG_FILENAME_SUFFIX = '/rakeRunner_rake.log'
30
+ TEAMCITY_RAKERUNNER_RPC_LOG_FILENAME_SUFFIX = '/rakeRunner_xmlrpc.log'
31
+ TEAMCITY_RAKERUNNER_SPEC_LOG_FILENAME_SUFFIX = '/rakeRunner_rspec.log'
32
+ TEAMCITY_RAKERUNNER_TESTUNIT_LOG_FILENAME_SUFFIX = '/rakeRunner_testUnit.log'
33
+ TEAMCITY_RAKERUNNER_TESTUNIT_EVENTS_LOG_FILENAME_SUFFIX = '/rakeRunner_testUnit_events.log'
34
+
35
+ # Teamcity connection properties
36
+ #TODO it seems this section is deprecated!
37
+ IDEA_BUILDSERVER_BUILD_ID_KEY = 'IDEA_BUILD_SERVER_BUILD_ID'
38
+ IDEA_BUILDSERVER_AGENT_PORT_KEY = 'IDEA_BUILD_AGENT_PORT'
39
+ IDEA_BUILDSERVER_HOST_ID_KEY = 'IDEA_BUILD_SERVER_HOST'
40
+
41
+ # Name of Teamcity RPC logger method
42
+ TEAMCITY_LOGGER_RPC_NAME = "testRunnerLogger.log"
43
+ #TEAMCITY_LOGGER_RPC_NAME = "buildAgent.log"
44
+
45
+ # Rake runner dispatcher settings
46
+ TEAMCITY_RAKERUNNER_DISPATCHER_MAX_ATTEMPTS = 100
47
+ TEAMCITY_RAKERUNNER_DISPATCHER_RETRY_DELAY = 0.25
48
+
49
+ # Rakerunner system properties
50
+ ORIGINAL_SDK_AUTORUNNER_PATH_KEY = 'TEAMCIY_RAKE_TU_AUTORUNNER_PATH'
51
+ ORIGINAL_SDK_TESTRUNNERMEDIATOR_PATH_KEY = 'TEAMCITY_RAKE_TU_TESTRUNNERMADIATOR_PATH'
52
+ TEAMCITY_RAKERUNNER_RAKE_TRACE_INVOKE_EXEC_STAGES_ENABLED = 'TEAMCITY_RAKE_TRACE'
53
+
54
+ module Rake
55
+ module TeamCity
56
+ # Mode
57
+ TEAMCITY_VERSION_KEY ='TEAMCITY_VERSION'
58
+
59
+
60
+ # Test::Unit
61
+ RUBY19_SDK_MINITEST_RUNNER_PATH_KEY = "TC_RUBY19_SDK_MINITEST_RUNNER_PATH_KEY"
62
+
63
+ # TODO: remove TEAMCITY_* prefix
64
+ TEAMCITY_RAKERUNNER_USED_FRAMEWORKS_KEY ='TEAMCITY_RAKE_RUNNER_USED_FRAMEWORKS'
65
+ TEAMCITY_RAKERUNNER_DEBUG_OPTIONS_KEY ='TEAMCITY_RAKERUNNER_DEBUG_OPTIONS'
66
+
67
+ TEAMCITY_RAKERUNNER_SUPPORTED_FRAMEWORKS =[:rspec, :test_spec, :test_unit, :cucumber, :shoulda]
68
+
69
+ TC_EXCLUDED_DEFAULT_TEST_CASES = [
70
+ "ActionController::IntegrationTest",
71
+ "ActionController::TestCase",
72
+ "ActionView::TestCase",
73
+ "ActionMailer::TestCase",
74
+ "ActiveRecord::TestCase",
75
+ "ActiveSupport::TestCase",
76
+ # Rails 3.0
77
+ "ActionDispatch::IntegrationTest",
78
+ "ActionDispatch::PerformanceTest"
79
+ ]
80
+
81
+ def self.is_in_idea_mode
82
+ !is_in_buildserver_mode
83
+ end
84
+
85
+ def self.is_in_buildserver_mode
86
+ version = ENV[TEAMCITY_VERSION_KEY]
87
+ # version must be set and not empty
88
+ if !version.nil? && !version.empty?
89
+ return true
90
+ end
91
+ end
92
+
93
+ # Supported frameworks
94
+ # :rspec
95
+ # :test_spec
96
+ # :test_unit
97
+ def self.is_framework_used(symbol)
98
+ value = ENV[TEAMCITY_RAKERUNNER_USED_FRAMEWORKS_KEY]
99
+ # check that symbol is name of supported framework
100
+ # and that supported frameworks env variable is set
101
+ return false if value.nil?
102
+ if TEAMCITY_RAKERUNNER_SUPPORTED_FRAMEWORKS.index(symbol).nil?
103
+ raise ArgumentError, "Unsupported framework: #{symbol}", caller
104
+ end
105
+
106
+ return !value.index(":#{symbol.to_s}").nil?
107
+ end
108
+
109
+ def self.is_fake_time_enabled?
110
+ self.is_enabled_in_debug_options(:fake_time)
111
+ end
112
+
113
+ def self.is_fake_stacktrace_enabled?
114
+ self.is_enabled_in_debug_options(:fake_stacktrace)
115
+ end
116
+
117
+ def self.is_fake_error_msg_enabled?
118
+ self.is_enabled_in_debug_options(:fake_error_msg)
119
+ end
120
+
121
+ def self.is_fake_location_url_enabled?
122
+ self.is_enabled_in_debug_options(:fake_location_url)
123
+ end
124
+
125
+ private
126
+ def self.is_enabled_in_debug_options(symbol)
127
+ debug_options = ENV[TEAMCITY_RAKERUNNER_DEBUG_OPTIONS_KEY]
128
+ !debug_options.nil? && !debug_options[symbol.to_s].nil?
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright 2000-2012 JetBrains s.r.o.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # @author: Roman Chernyatchik
16
+
17
+ module Rake
18
+ module TeamCity
19
+ module RunnerCommon
20
+ # Let's keep STDOUT, our users likes to capture it and block our events
21
+ @@original_stdout = STDOUT
22
+
23
+ # Current time in ms
24
+ def get_current_time_in_ms
25
+ get_time_in_ms(Time.now)
26
+ end
27
+
28
+ def get_time_in_ms(time)
29
+ ((time.to_f) * 1000 ).to_i
30
+ end
31
+
32
+ # Sends msg to runner
33
+ def send_msg(msg)
34
+ @@original_stdout.flush
35
+ @@original_stdout.puts("\n#{msg}")
36
+ @@original_stdout.flush
37
+ end
38
+
39
+ # Sets factory for creating messages
40
+ def set_message_factory(factory)
41
+ @message_factory = factory
42
+ end
43
+
44
+ def log_test_reporter_attached
45
+ if ::Rake::TeamCity.is_in_idea_mode
46
+ # log method is be defined in target class
47
+ log(@message_factory.create_test_reported_attached)
48
+ end
49
+ end
50
+
51
+ # Is from base_text_formatter.rb of rspec 1.1.4
52
+ def self.backtrace_line(line)
53
+ line.sub(/\A([^:]+:\d+)$/, '\\1:')
54
+ end
55
+
56
+ def self.format_backtrace(backtrace)
57
+ return "" if backtrace.nil?
58
+ backtrace.map { |line| backtrace_line(line) }.join("\n")
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,90 @@
1
+ # Copyright 2000-2012 JetBrains s.r.o.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Created by IntelliJ IDEA.
16
+ #
17
+ # @author: Roman.Chernyatchik
18
+ # @date: 18:04:35
19
+
20
+ require_relative '../rakerunner_consts'
21
+
22
+ module Rake
23
+ module TeamCity
24
+ module Utils
25
+ class FileLogger
26
+ def initialize(logs_dir, file_suffix)
27
+ @enabled = ENV[logs_dir]
28
+
29
+ @log_file = @enabled ? File.new(ENV[logs_dir] + file_suffix, "a+") : nil
30
+ end
31
+
32
+ def current_proc_thread_info
33
+ "[pid:#{Process.pid}x#{Thread.current}]"
34
+ end
35
+
36
+ def log_msg(msg, add_proc_thread_info=false)
37
+ if @enabled
38
+ @log_file << "[#{Time.now}] : #{(add_proc_thread_info ? current_proc_thread_info : "") + " " + msg}\n"
39
+ @log_file.flush
40
+ end
41
+ end
42
+
43
+ def log_block(id, data = nil, add_proc_thread_info=false)
44
+ log_msg("Start [#{id}]" + (data ? " data=[#{data}]" : ""), add_proc_thread_info);
45
+ begin
46
+ yield
47
+ rescue Exception => e
48
+ log_msg("Exception [#{id}], type=#{e.class.name}, msg=#{e.message}", add_proc_thread_info)
49
+ raise
50
+ end
51
+ log_msg("End [#{id}]", add_proc_thread_info)
52
+ end
53
+
54
+ def close
55
+ @log_file.close if @enabled
56
+ end
57
+ end
58
+
59
+ class RakeFileLogger < FileLogger
60
+ def initialize
61
+ super(TEAMCITY_RAKERUNNER_LOG_PATH_KEY, TEAMCITY_RAKERUNNER_LOG_FILENAME_SUFFIX)
62
+ end
63
+ end
64
+
65
+ class RPCMessagesLogger < FileLogger
66
+ def initialize
67
+ super(TEAMCITY_RAKERUNNER_LOG_PATH_KEY, TEAMCITY_RAKERUNNER_RPC_LOG_FILENAME_SUFFIX)
68
+ end
69
+ end
70
+
71
+ class RSpecFileLogger < FileLogger
72
+ def initialize
73
+ super(TEAMCITY_RAKERUNNER_LOG_PATH_KEY, TEAMCITY_RAKERUNNER_SPEC_LOG_FILENAME_SUFFIX)
74
+ end
75
+ end
76
+
77
+ class TestUnitFileLogger < FileLogger
78
+ def initialize
79
+ super(TEAMCITY_RAKERUNNER_LOG_PATH_KEY, TEAMCITY_RAKERUNNER_TESTUNIT_LOG_FILENAME_SUFFIX)
80
+ end
81
+ end
82
+
83
+ class TestUnitEventsFileLogger < FileLogger
84
+ def initialize
85
+ super(TEAMCITY_RAKERUNNER_LOG_PATH_KEY, TEAMCITY_RAKERUNNER_TESTUNIT_EVENTS_LOG_FILENAME_SUFFIX)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,182 @@
1
+ # Copyright 2000-2012 JetBrains s.r.o.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Created by IntelliJ IDEA.
16
+ #
17
+ # @author: Roman.Chernyatchik
18
+ # @date: 02.06.2007
19
+
20
+ require_relative '../rakerunner_consts'
21
+
22
+ module Rake
23
+ module TeamCity
24
+ module RunnerUtils
25
+
26
+ ###########################################################################
27
+ #### Test::Unit
28
+ ###########################################################################
29
+
30
+ # Converts Ruby Test Names : $TEST_METHOD_NAME($TEST_CASE_QUALIFIED_NAME)
31
+ # to Qualified name format : $TEST_CASE_QUALIFIED_NAME.$TEST_METHOD_NAME
32
+ def convert_ruby_test_name_to_qualified(ruby_name)
33
+ if ruby_name && (ruby_name.strip =~ /(\S+)\(([\w:]*)\)/)
34
+ # p [$1, $2]
35
+ method_name = $1
36
+ qualified_name = $2
37
+ return convert_test_unit_to_qualified(qualified_name, method_name)
38
+ end
39
+ ruby_name
40
+ end
41
+
42
+ def convert_test_unit_to_qualified(class_qualified_name, method_name)
43
+ if class_qualified_name.empty?
44
+ "#{method_name}"
45
+ else
46
+ "#{class_qualified_name}.#{method_name}"
47
+ end
48
+ end
49
+
50
+ def self.use_minitest?
51
+ defined? ::MiniTest::Unit::TestCase
52
+ end
53
+
54
+ ###########################################################################
55
+ #### RSpec
56
+ ###########################################################################
57
+
58
+ #@Nullable
59
+ #@returns pair of two strings: [source file path, line in source file] or [nil, nil]
60
+ def extract_source_location_from_example(example)
61
+ #example.instance_variable_hash['@_implementation'].to_s.gsub(/#<Proc:.+@/, "")
62
+
63
+ #TODO - replace with example full name!!!!!
64
+
65
+ if example.respond_to?(:location)
66
+ # rspec 1.2.1 API
67
+ return extract_rspec_proxy_location(example)
68
+ elsif (example.respond_to?(:metadata))
69
+ # rspec 2.0 beta API
70
+ return parse_rspec_proxy_location(example.metadata[:location])
71
+ end
72
+
73
+ proc = (example.respond_to?(:instance_variable_hash)) ? example.instance_variable_hash['@_implementation'] : nil
74
+
75
+ if !proc.nil? && proc.is_a?(Proc)
76
+ return extract_source_location_from_closure(proc.to_s)
77
+ end
78
+
79
+ return nil, nil
80
+ end
81
+
82
+ #[@Nullable, @Nullable]
83
+ def get_pair_by(src_file_path_str, src_file_line_str)
84
+ if src_file_path_str && src_file_line_str
85
+ return File.expand_path(src_file_path_str), src_file_line_str
86
+ end
87
+
88
+ return nil, nil
89
+ end
90
+
91
+ #@Nullable
92
+ #@returns pair of two strings: [source file path, line in source file] or [nil, nil]
93
+ def extract_source_location_from_path_info(spec_path_info)
94
+ # E.g.: "/Users/romeo/IdeaProjects/dianaplugin/rails/spec/my_example_spec.rb:4"
95
+ if spec_path_info =~ /(^)([^:]+)(:)(\d+)(\D*)($)/
96
+ src_file_path_str = $2
97
+ src_file_line_str = $4
98
+ if src_file_path_str && src_file_line_str
99
+ return src_file_path_str, src_file_line_str
100
+ end
101
+ elsif spec_path_info =~ /(^)([^:]+)($)/
102
+ return spec_path_info, "0"
103
+ end
104
+
105
+ return nil, nil
106
+ end
107
+
108
+ @@ignore_root_test_case = true
109
+
110
+ # usually we should ignore root test case that is test file
111
+ # but in run_all_in_folder case we shouldn't ignore it!
112
+ def self.ignore_root_test_case?
113
+ @@ignore_root_test_case
114
+ end
115
+
116
+ def self.ignore_root_test_case=(value)
117
+ @@ignore_root_test_case = value
118
+ end
119
+
120
+
121
+ def self.excluded_default_testcase_name?(suite_or_test_name)
122
+ ::Rake::TeamCity::TC_EXCLUDED_DEFAULT_TEST_CASES.index(suite_or_test_name) != nil
123
+ end
124
+
125
+ def self.excluded_default_testcase?(suite_or_test)
126
+ excluded_default_testcase_name?(suite_or_test.name) && (suite_or_test.size == 1)
127
+ end
128
+
129
+ def self.fake_default_test_for_empty_suite?(suite_or_test)
130
+ !(defined? suite_or_test.tests) && ("default_test" == suite_or_test.method_name)
131
+ end
132
+
133
+ ############################################################
134
+ ############################################################
135
+
136
+ private
137
+
138
+ #[@Nullable, @Nullable]
139
+ #Exctracting location using new RSpec 1.2.1 API
140
+ #@returns pair of two stings [source file path, line in source file] or [nil, nil]
141
+ def extract_rspec_proxy_location(proxy_object)
142
+ parse_rspec_proxy_location proxy_object.location
143
+ end
144
+
145
+ def parse_rspec_proxy_location(location)
146
+ #TODO Add test for it!!!!!
147
+ if location =~ /(.+):(\d+)/
148
+ return get_pair_by($1, $2)
149
+ end
150
+ return nil, nil
151
+ end
152
+
153
+ #@Nullable
154
+ #@returns pair of two strings: [source file path, line in source file] or [nil, nil]
155
+ def extract_source_location_from_group(example_group)
156
+ if example_group
157
+ if example_group.respond_to?(:location)
158
+ # rspec 1.2.1 API
159
+ return extract_rspec_proxy_location(example_group)
160
+ elsif (example_group.respond_to?(:metadata))
161
+ # rspec 2.0 beta API
162
+ return parse_rspec_proxy_location(example_group.metadata[:example_group][:location])
163
+ elsif (example_group.respond_to?(:spec_path))
164
+ return extract_source_location_from_path_info(example_group.spec_path)
165
+ end
166
+ end
167
+ return nil, nil
168
+ end
169
+
170
+ #[@Nullable, @Nullable]
171
+ #@returns pair of two strings: [source file path, line in source file] or [nil, nil]
172
+ def extract_source_location_from_closure(closure_id)
173
+ # E.g.: "#<Proc:0xaa3e9a@/Users/romeo/IdeaProjects/dianaplugin/rails/spec/my_example_spec.rb:16>"
174
+ if closure_id =~ /(#<[^:]+:[^@]+@)([^:]+)(:)(\d+)(>)/
175
+ return get_pair_by($2, $4)
176
+ end
177
+
178
+ return nil, nil
179
+ end
180
+ end
181
+ end
182
+ end