Module: CaptureWarnings

Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/spec/capture_warnings.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/spec/capture_warnings.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-ci-environment-9.1.0/spec/capture_warnings.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-html-formatter-19.2.0/spec/capture_warnings.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-tag-expressions-4.1.0/spec/capture_warnings.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-cucumber-expressions-15.2.0/spec/capture_warnings.rb

Overview

Instance Method Summary collapse

Instance Method Details

#capture_error(&block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/spec/capture_warnings.rb', line 34

def capture_error(&block)
  old_stderr = STDERR.clone
  pipe_r, pipe_w = IO.pipe
  pipe_r.sync    = true
  error          = String.new
  reader = Thread.new do
    begin
      loop do
        error << pipe_r.readpartial(1024)
      end
    rescue EOFError
    end
  end
  STDERR.reopen(pipe_w)
  block.call
ensure
  capture_system_exit
  STDERR.reopen(old_stderr)
  pipe_w.close
  reader.join
  return error.split("\n")
end

#capture_system_exitObject



71
72
73
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/spec/capture_warnings.rb', line 71

def capture_system_exit
  @system_exit = $!
end

#ensure_system_exit_if_requiredObject

Raises:

  • (@system_exit)


67
68
69
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/spec/capture_warnings.rb', line 67

def ensure_system_exit_if_required
  raise @system_exit if @system_exit
end


57
58
59
60
61
62
63
64
65
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/spec/capture_warnings.rb', line 57

def print_warnings(type, warnings)
  puts
  puts "-" * 30 + " #{type} warnings: " + "-" * 30
  puts
  puts warnings.join("\n")
  puts
  puts "-" * 75
  puts
end

#report_warnings(&block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/spec/capture_warnings.rb', line 6

def report_warnings(&block)
  current_dir = Dir.pwd
  warnings, errors = capture_error(&block).partition { |line| line.include?('warning') }
  project_warnings, other_warnings = warnings.uniq.partition { |line| line.include?(current_dir) }

  if errors.any?
    puts errors.join("\n")
  end

  if other_warnings.any?
    puts "#{ other_warnings.count } warnings detected, set VIEW_OTHER_WARNINGS=true to see them."
    print_warnings('other', other_warnings) if ENV['VIEW_OTHER_WARNINGS']
  end

  # Until they fix https://bugs.ruby-lang.org/issues/10661
  if RUBY_VERSION == "2.2.0"
    project_warnings = project_warnings.reject { |w| w =~ /warning: possible reference to past scope/ }
  end

  if project_warnings.any?
    puts "#{ project_warnings.count } warnings detected"
    print_warnings('cucumber-expressions', project_warnings)
    fail "Please remove all cucumber-expressions warnings."
  end

  ensure_system_exit_if_required
end