module Rake::TeamCity::RunnerUtils

Public Class Methods

excluded_default_testcase?(suite_or_test) click to toggle source
# File lib/rspec/teamcity/utils/runner_utils.rb, line 125
def self.excluded_default_testcase?(suite_or_test)
  excluded_default_testcase_name?(suite_or_test.name) && (suite_or_test.size == 1)
end
excluded_default_testcase_name?(suite_or_test_name) click to toggle source
# File lib/rspec/teamcity/utils/runner_utils.rb, line 121
def self.excluded_default_testcase_name?(suite_or_test_name)
  ::Rake::TeamCity::TC_EXCLUDED_DEFAULT_TEST_CASES.index(suite_or_test_name) != nil
end
fake_default_test_for_empty_suite?(suite_or_test) click to toggle source
# File lib/rspec/teamcity/utils/runner_utils.rb, line 129
def self.fake_default_test_for_empty_suite?(suite_or_test)
  !(defined? suite_or_test.tests) && ("default_test" == suite_or_test.method_name)
end
ignore_root_test_case=(value) click to toggle source
# File lib/rspec/teamcity/utils/runner_utils.rb, line 116
def self.ignore_root_test_case=(value)
  @@ignore_root_test_case = value
end
ignore_root_test_case?() click to toggle source

usually we should ignore root test case that is test file but in run_all_in_folder case we shouldn't ignore it!

# File lib/rspec/teamcity/utils/runner_utils.rb, line 112
def self.ignore_root_test_case?
  @@ignore_root_test_case
end
use_minitest?() click to toggle source
# File lib/rspec/teamcity/utils/runner_utils.rb, line 50
def self.use_minitest?
  defined? ::MiniTest::Unit::TestCase
end

Public Instance Methods

convert_ruby_test_name_to_qualified(ruby_name) click to toggle source

Converts Ruby Test Names : $TEST_METHOD_NAME($TEST_CASE_QUALIFIED_NAME) to Qualified name format : $TEST_CASE_QUALIFIED_NAME.$TEST_METHOD_NAME

# File lib/rspec/teamcity/utils/runner_utils.rb, line 32
def convert_ruby_test_name_to_qualified(ruby_name)
  if ruby_name && (ruby_name.strip =~ /(\S+)\(([\w:]*)\)/)
    # p [$1, $2]
    method_name = $1
    qualified_name = $2
    return convert_test_unit_to_qualified(qualified_name, method_name)
  end
  ruby_name
end
convert_test_unit_to_qualified(class_qualified_name, method_name) click to toggle source
# File lib/rspec/teamcity/utils/runner_utils.rb, line 42
def convert_test_unit_to_qualified(class_qualified_name, method_name)
  if class_qualified_name.empty?
    "#{method_name}"
  else
    "#{class_qualified_name}.#{method_name}"
  end
end
extract_source_location_from_example(example) click to toggle source

@Nullable @returns pair of two strings: [source file path, line in source file] or [nil, nil]

# File lib/rspec/teamcity/utils/runner_utils.rb, line 60
def extract_source_location_from_example(example)
  #example.instance_variable_hash['@_implementation'].to_s.gsub(/#<Proc:.+@/, "")

  #TODO - replace with example full name!!!!!

  if example.respond_to?(:location)
    # rspec 1.2.1 API
    return extract_rspec_proxy_location(example)
  elsif (example.respond_to?(:metadata))
    # rspec 2.0 beta API
    return parse_rspec_proxy_location(example.metadata[:location])
  end

  proc = (example.respond_to?(:instance_variable_hash)) ? example.instance_variable_hash['@_implementation'] : nil

  if !proc.nil? && proc.is_a?(Proc)
    return extract_source_location_from_closure(proc.to_s)
  end

  return nil, nil
end
extract_source_location_from_path_info(spec_path_info) click to toggle source

@Nullable @returns pair of two strings: [source file path, line in source file] or [nil, nil]

# File lib/rspec/teamcity/utils/runner_utils.rb, line 93
def extract_source_location_from_path_info(spec_path_info)
  # E.g.: "/Users/romeo/IdeaProjects/dianaplugin/rails/spec/my_example_spec.rb:4"
  if spec_path_info =~ /(^)([^:]+)(:)(\d+)(\D*)($)/
    src_file_path_str = $2
    src_file_line_str = $4
    if src_file_path_str && src_file_line_str
      return src_file_path_str, src_file_line_str
    end
  elsif spec_path_info =~ /(^)([^:]+)($)/
    return spec_path_info, "0"
  end

  return nil, nil
end
get_pair_by(src_file_path_str, src_file_line_str) click to toggle source
@Nullable, @Nullable
# File lib/rspec/teamcity/utils/runner_utils.rb, line 83
def get_pair_by(src_file_path_str, src_file_line_str)
  if src_file_path_str && src_file_line_str
    return File.expand_path(src_file_path_str), src_file_line_str
  end

  return nil, nil
end

Private Instance Methods

extract_rspec_proxy_location(proxy_object) click to toggle source
@Nullable, @Nullable

Exctracting location using new RSpec 1.2.1 API @returns pair of two stings [source file path, line in source file] or [nil, nil]

# File lib/rspec/teamcity/utils/runner_utils.rb, line 141
def extract_rspec_proxy_location(proxy_object)
  parse_rspec_proxy_location proxy_object.location
end
extract_source_location_from_closure(closure_id) click to toggle source
@Nullable, @Nullable

@returns pair of two strings: [source file path, line in source file] or [nil, nil]

# File lib/rspec/teamcity/utils/runner_utils.rb, line 172
def extract_source_location_from_closure(closure_id)
  # E.g.: "#<Proc:0xaa3e9a@/Users/romeo/IdeaProjects/dianaplugin/rails/spec/my_example_spec.rb:16>"
  if closure_id =~ /(#<[^:]+:[^@]+@)([^:]+)(:)(\d+)(>)/
    return get_pair_by($2, $4)
  end

  return nil, nil
end
extract_source_location_from_group(example_group) click to toggle source

@Nullable @returns pair of two strings: [source file path, line in source file] or [nil, nil]

# File lib/rspec/teamcity/utils/runner_utils.rb, line 155
def extract_source_location_from_group(example_group)
  if example_group
    if example_group.respond_to?(:location)
      # rspec 1.2.1 API
      return extract_rspec_proxy_location(example_group)
    elsif (example_group.respond_to?(:metadata))
      # rspec 2.0 beta API
      return parse_rspec_proxy_location(example_group.metadata[:example_group][:location])
    elsif (example_group.respond_to?(:spec_path))
      return extract_source_location_from_path_info(example_group.spec_path)
    end
  end
  return nil, nil
end
parse_rspec_proxy_location(location) click to toggle source
# File lib/rspec/teamcity/utils/runner_utils.rb, line 145
def parse_rspec_proxy_location(location)
  #TODO Add test for it!!!!!
  if location =~ /(.+):(\d+)/
    return get_pair_by($1, $2)
  end
  return nil, nil
end