Class: RubyCI::RspecDryrunFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_ci/rspec_dryrun_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ RspecDryrunFormatter

Returns a new instance of RspecDryrunFormatter.



16
17
18
19
20
21
22
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 16

def initialize(output)
  @output = output
  @current_group_path = []
  @current_file = nil
  @current_file_count = 0
  @events = []
end

Instance Method Details

#close(*args) ⇒ Object



37
38
39
40
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 37

def close(*args)
  msg(:close, { "timestamp" => time_now })
  send_events
end

#dump_summary(summary_notification) ⇒ Object



42
43
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 42

def dump_summary(summary_notification)
end

#example_failed(example_notification) ⇒ Object



59
60
61
62
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 59

def example_failed(example_notification)
  example_finished(example_notification)
  @output.print RSpec::Core::Formatters::ConsoleCodes.wrap('F', :failure)
end

#example_group_finished(_group_notification) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 73

def example_group_finished(_group_notification)
  @current_group_path.pop
  if @current_group_path.empty? # its a file
    msg(:file_examples_count, [@current_file, @current_file_count])
    @current_file_count = 0
    @current_file = nil
  end
end

#example_group_started(group_notification) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 82

def example_group_started(group_notification)
  if @current_group_path.size == 0
    @current_file = group_notification.group.[:file_path].gsub("./".freeze, "".freeze)
    @current_file_count = 0
  end
  @current_group_path << 1
end

#example_passed(example_notification) ⇒ Object



54
55
56
57
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 54

def example_passed(example_notification)
  example_finished(example_notification)
  @output.print RSpec::Core::Formatters::ConsoleCodes.wrap('.', :success)
end

#example_pending(example_notification) ⇒ Object



64
65
66
67
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 64

def example_pending(example_notification)
  example_finished(example_notification)
  @output.print RSpec::Core::Formatters::ConsoleCodes.wrap('*', :pending)
end

#message(message_notification) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 24

def message(message_notification)
  if message_notification.message.include?('An error occurred')
    msg(:message, Base64.strict_encode64("\nAn error occurred#{message_notification.message}"))
    send_events
  end
  @output.print message_notification.message
  @output.print "\n"
end

#start(example_count) ⇒ Object



33
34
35
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 33

def start(example_count)
  msg(:start, { "example_count" => example_count.count, "timestamp" => time_now })
end

#start_dump(_notification) ⇒ Object



69
70
71
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 69

def start_dump(_notification)
  @output.print "\n"
end

#time_frozen?Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 49

def time_frozen?
  return unless defined?(Timecop)
  Timecop.frozen?
end

#time_nowObject



45
46
47
# File 'lib/ruby_ci/rspec_dryrun_formatter.rb', line 45

def time_now
  time_frozen? ? Timecop.return { Time.now } : Time.now
end