Module: MotionSpec::RubyMineOutput

Defined in:
lib/motion-spec/output/ruby_mine.rb

Constant Summary collapse

@@entered =
false
@@description =
nil
@@specification =
nil
@@started =
nil

Instance Method Summary collapse

Instance Method Details

#convert_time_to_java_simple_date(time) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/motion-spec/output/ruby_mine.rb', line 74

def convert_time_to_java_simple_date(time)
  gmt_offset = time.gmt_offset
  gmt_sign = gmt_offset < 0 ? '-' : '+'
  gmt_hours = gmt_offset.abs / 3600
  gmt_minutes = gmt_offset.abs % 3600

  millisec = time.usec == 0 ? 0 : time.usec / 1000

  # Time string in Java SimpleDateFormat
  sprintf("#{time.strftime('%Y-%m-%dT%H:%M:%S.')}%03d#{gmt_sign}%02d%02d", millisec, gmt_hours, gmt_minutes)
end

#escape_message(message) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/motion-spec/output/ruby_mine.rb', line 50

def escape_message(message)
  copy_of_text = String.new(message)

  copy_of_text.gsub!(/\|/, '||')

  copy_of_text.gsub!(/'/, "|'")
  copy_of_text.gsub!(/\n/, '|n')
  copy_of_text.gsub!(/\r/, '|r')
  copy_of_text.gsub!(/\]/, '|]')

  copy_of_text.gsub!(/\[/, '|[')

  begin
    copy_of_text.encode!('UTF-8') if copy_of_text.respond_to? :encode!
    copy_of_text.gsub!(/\u0085/, '|x') # next line
    copy_of_text.gsub!(/\u2028/, '|l') # line separator
    copy_of_text.gsub!(/\u2029/, '|p') # paragraph separator
  rescue
    # it is not an utf-8 compatible string :(
  end

  copy_of_text
end

#handle_requirement_begin(description) ⇒ Object



22
23
24
25
26
# File 'lib/motion-spec/output/ruby_mine.rb', line 22

def handle_requirement_begin(description)
  @@description = description
  @@started = Time.now
  puts "##teamcity[testStarted timestamp = '#{java_time}' captureStandardOutput = 'true' name = '#{escape_message(description)}']\n\n"
end

#handle_requirement_end(error) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/motion-spec/output/ruby_mine.rb', line 28

def handle_requirement_end(error)
  if !error.empty?
    puts "##teamcity[testFailed timestamp = '#{java_time}' message = '#{escape_message(error)}' name = '#{escape_message(@@description)}']\n\n"
  end
  duration = ((Time.now - @@started) * 1000).to_i
  puts "##teamcity[testFinished timestamp = '#{java_time}' duration = '#{duration}' name = '#{escape_message(@@description)}']\n\n"
end

#handle_specification_begin(name) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/motion-spec/output/ruby_mine.rb', line 9

def handle_specification_begin(name)
  unless @@entered
    puts "##teamcity[enteredTheMatrix timestamp = '#{java_time}']\n\n"
    @@entered = true
  end
  @@specification = name
  puts "##teamcity[testSuiteStarted timestamp = '#{java_time}' name = '#{escape_message(name)}']\n\n"
end

#handle_specification_endObject



18
19
20
# File 'lib/motion-spec/output/ruby_mine.rb', line 18

def handle_specification_end
  puts "##teamcity[testSuiteFinished timestamp = '#{java_time}' name = '#{escape_message(@@specification)}']\n\n" if Counter[:context_depth] == 1
end

#handle_summaryObject



36
37
38
39
40
# File 'lib/motion-spec/output/ruby_mine.rb', line 36

def handle_summary
  print ErrorLog if Backtraces
  puts '%d specifications (%d requirements), %d failures, %d errors' %
           Counter.values_at(:specifications, :requirements, :failed, :errors)
end

#java_timeObject



46
47
48
# File 'lib/motion-spec/output/ruby_mine.rb', line 46

def java_time
  convert_time_to_java_simple_date(Time.now)
end

#spacesObject



42
43
44
# File 'lib/motion-spec/output/ruby_mine.rb', line 42

def spaces
  '  ' * (Counter[:context_depth] - 1)
end