Remove Warning.warn override in MSpec and --warnings option · ruby/mspec@1d8cf64 (original) (raw)
5 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -38,11 +38,6 @@ def options(argv = ARGV) | ||
38 | 38 | |
39 | 39 | options.targets |
40 | 40 | |
41 | -options.on("--warnings", "Don't suppress warnings") do | |
42 | -config[:flags] << '-w' | |
43 | -ENV['OUTPUT_WARNINGS'] = '1' | |
44 | -end | |
45 | - | |
46 | 41 | options.on("-j", "--multi", "Run multiple (possibly parallel) subprocesses") do |
47 | 42 | config[:multi] = true |
48 | 43 | end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -7,7 +7,7 @@ def initialize | ||
7 | 7 | end |
8 | 8 | |
9 | 9 | def write(*str) |
10 | -self << str.join | |
10 | +self << str.join('') | |
11 | 11 | end |
12 | 12 | |
13 | 13 | def << str |
@@ -16,7 +16,7 @@ def << str | ||
16 | 16 | end |
17 | 17 | |
18 | 18 | def print(*str) |
19 | -write(str.join + $\.to_s) | |
19 | +write(str.join('') + $\.to_s) | |
20 | 20 | end |
21 | 21 | |
22 | 22 | def method_missing(name, *args, &block) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -19,15 +19,13 @@ def matches?(proc) | ||
19 | 19 | @verbose = $VERBOSE |
20 | 20 | err = IOStub.new |
21 | 21 | |
22 | -Thread.current[:in_mspec_complain_matcher] = true | |
23 | 22 | $stderr = err |
24 | 23 | $VERBOSE = @options.key?(:verbose) ? @options[:verbose] : false |
25 | 24 | begin |
26 | 25 | proc.call |
27 | 26 | ensure |
28 | 27 | $VERBOSE = @verbose |
29 | 28 | $stderr = @saved_err |
30 | -Thread.current[:in_mspec_complain_matcher] = false | |
31 | 29 | end |
32 | 30 | |
33 | 31 | @warning = err.to_s |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8,46 +8,3 @@ | ||
8 | 8 | Warning[:deprecated] = true |
9 | 9 | Warning[:experimental] = false |
10 | 10 | end |
11 | - | |
12 | -if Object.const_defined?(:Warning) and Warning.respond_to?(:warn) | |
13 | -def Warning.warn(message, category: nil) | |
14 | -# Suppress any warning inside the method to prevent recursion | |
15 | -verbose = $VERBOSE | |
16 | - $VERBOSE = nil | |
17 | - | |
18 | -if Thread.current[:in_mspec_complain_matcher] | |
19 | -return $stderr.write(message) | |
20 | -end | |
21 | - | |
22 | -case message | |
23 | -# $VERBOSE = true warnings | |
24 | -when /(.+\.rb):(\d+):.+possibly useless use of (<|<= | |
25 | -# Make sure there is a .should otherwise it is missing | |
26 | -line_nb = Integer($2) | |
27 | -unless File.exist?($1) and /\.should(_not)? (<|<= | |
28 | - $stderr.write message | |
29 | -end | |
30 | -when /possibly useless use of (\+|-) in void context/ | |
31 | -when /assigned but unused variable/ | |
32 | -when /method redefined/ | |
33 | -when /previous definition of/ | |
34 | -when /instance variable @.+ not initialized/ | |
35 | -when /statement not reached/ | |
36 | -when /shadowing outer local variable/ | |
37 | -when /setting Encoding.default_(in|ex)ternal/ | |
38 | -when /unknown (un)?pack directive/ | |
39 | -when /(un)?trust(ed\?)? is deprecated/ | |
40 | -when /\.exists\? is a deprecated name/ | |
41 | -when /Float .+ out of range/ | |
42 | -when /passing a block to String#(bytes|chars | |
43 | -when /core\/string\/modulo_spec\.rb:\d+: warning: too many arguments for format string/ | |
44 | -when /regexp\/shared\/new_ascii(_8bit)?\.rb:\d+: warning: Unknown escape .+ is ignored/ | |
45 | -else | |
46 | - $stderr.write message | |
47 | -end | |
48 | -ensure | |
49 | - $VERBOSE = verbose | |
50 | -end | |
51 | -else | |
52 | - $VERBOSE = nil unless ENV['OUTPUT_WARNINGS'] | |
53 | -end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -92,33 +92,6 @@ | ||
92 | 92 | end |
93 | 93 | end |
94 | 94 | |
95 | -RSpec.describe "The --warnings option" do | |
96 | -before :each do | |
97 | -@options, @config = new_option | |
98 | -allow(MSpecOptions).to receive(:new).and_return(@options) | |
99 | -@script = MSpecMain.new | |
100 | -allow(@script).to receive(:config).and_return(@config) | |
101 | -end | |
102 | - | |
103 | -it "is enabled by #options" do | |
104 | -allow(@options).to receive(:on) | |
105 | -expect(@options).to receive(:on).with("--warnings", an_instance_of(String)) | |
106 | -@script.options | |
107 | -end | |
108 | - | |
109 | -it "sets flags to -w" do | |
110 | -@config[:flags] = [] | |
111 | -@script.options ["--warnings"] | |
112 | -expect(@config[:flags]).to include("-w") | |
113 | -end | |
114 | - | |
115 | -it "set OUTPUT_WARNINGS = '1' in the environment" do | |
116 | -ENV['OUTPUT_WARNINGS'] = '0' | |
117 | -@script.options ["--warnings"] | |
118 | -expect(ENV['OUTPUT_WARNINGS']).to eq('1') | |
119 | -end | |
120 | -end | |
121 | - | |
122 | 95 | RSpec.describe "The -j, --multi option" do |
123 | 96 | before :each do |
124 | 97 | @options, @config = new_option |