Skip to content

Commit 4ce9f41

Browse files
committed
Suppress warnings in specs rather than global filtering in MSpec
1 parent 3a0654e commit 4ce9f41

18 files changed

+187
-22
lines changed

core/argf/bytes_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
ruby_version_is ''...'3.0' do
55
describe "ARGF.bytes" do
6+
before :each do
7+
@verbose, $VERBOSE = $VERBOSE, nil
8+
end
9+
10+
after :each do
11+
$VERBOSE = @verbose
12+
end
13+
614
it_behaves_like :argf_each_byte, :bytes
715
end
816
end

core/argf/chars_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
ruby_version_is ''...'3.0' do
55
describe "ARGF.chars" do
6+
before :each do
7+
@verbose, $VERBOSE = $VERBOSE, nil
8+
end
9+
10+
after :each do
11+
$VERBOSE = @verbose
12+
end
13+
614
it_behaves_like :argf_each_char, :chars
715
end
816
end

core/argf/codepoints_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
ruby_version_is ''...'3.0' do
55
describe "ARGF.codepoints" do
6+
before :each do
7+
@verbose, $VERBOSE = $VERBOSE, nil
8+
end
9+
10+
after :each do
11+
$VERBOSE = @verbose
12+
end
13+
614
it_behaves_like :argf_each_codepoint, :codepoints
715
end
816
end

core/argf/lines_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
ruby_version_is ''...'3.0' do
55
describe "ARGF.lines" do
6+
before :each do
7+
@verbose, $VERBOSE = $VERBOSE, nil
8+
end
9+
10+
after :each do
11+
$VERBOSE = @verbose
12+
end
13+
614
it_behaves_like :argf_each_line, :lines
715
end
816
end

core/enumerator/initialize_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
ruby_version_is ''...'3.0' do
1515
it "returns self when given an object" do
16-
@uninitialized.send(:initialize, Object.new).should equal(@uninitialized)
16+
suppress_warning do
17+
@uninitialized.send(:initialize, Object.new).should equal(@uninitialized)
18+
end
1719
end
1820
end
1921

core/enumerator/new_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@
1010

1111
ruby_version_is ''...'3.0' do
1212
it "creates a new custom enumerator with the given object, iterator and arguments" do
13-
enum = Enumerator.new(1, :upto, 3)
13+
enum = suppress_warning { Enumerator.new(1, :upto, 3) }
1414
enum.should be_an_instance_of(Enumerator)
1515
end
1616

1717
it "creates a new custom enumerator that responds to #each" do
18-
enum = Enumerator.new(1, :upto, 3)
18+
enum = suppress_warning { Enumerator.new(1, :upto, 3) }
1919
enum.respond_to?(:each).should == true
2020
end
2121

2222
it "creates a new custom enumerator that runs correctly" do
23-
Enumerator.new(1, :upto, 3).map{|x|x}.should == [1,2,3]
23+
suppress_warning { Enumerator.new(1, :upto, 3) }.map{ |x| x }.should == [1,2,3]
2424
end
2525

2626
it "aliases the second argument to :each" do
27-
Enumerator.new(1..2).to_a.should == Enumerator.new(1..2, :each).to_a
27+
suppress_warning { Enumerator.new(1..2) }.to_a.should ==
28+
suppress_warning { Enumerator.new(1..2, :each) }.to_a
2829
end
2930

3031
it "doesn't check for the presence of the iterator method" do
31-
Enumerator.new(nil).should be_an_instance_of(Enumerator)
32+
suppress_warning { Enumerator.new(nil) }.should be_an_instance_of(Enumerator)
3233
end
3334

3435
it "uses the latest define iterator method" do
@@ -37,7 +38,7 @@ def each
3738
yield :foo
3839
end
3940
end
40-
enum = Enumerator.new(StrangeEach.new)
41+
enum = suppress_warning { Enumerator.new(StrangeEach.new) }
4142
enum.to_a.should == [:foo]
4243
class StrangeEach
4344
def each

core/hash/shared/index.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,35 @@
33

44
describe :hash_index, shared: true do
55
it "returns the corresponding key for value" do
6-
{ 2 => 'a', 1 => 'b' }.send(@method, 'b').should == 1
6+
suppress_warning do # for Hash#index
7+
{ 2 => 'a', 1 => 'b' }.send(@method, 'b').should == 1
8+
end
79
end
810

911
it "returns nil if the value is not found" do
10-
{ a: -1, b: 3.14, c: 2.718 }.send(@method, 1).should be_nil
12+
suppress_warning do # for Hash#index
13+
{ a: -1, b: 3.14, c: 2.718 }.send(@method, 1).should be_nil
14+
end
1115
end
1216

1317
it "doesn't return default value if the value is not found" do
14-
Hash.new(5).send(@method, 5).should be_nil
18+
suppress_warning do # for Hash#index
19+
Hash.new(5).send(@method, 5).should be_nil
20+
end
1521
end
1622

1723
it "compares values using ==" do
18-
{ 1 => 0 }.send(@method, 0.0).should == 1
19-
{ 1 => 0.0 }.send(@method, 0).should == 1
24+
suppress_warning do # for Hash#index
25+
{ 1 => 0 }.send(@method, 0.0).should == 1
26+
{ 1 => 0.0 }.send(@method, 0).should == 1
27+
end
2028

2129
needle = mock('needle')
2230
inhash = mock('inhash')
2331
inhash.should_receive(:==).with(needle).and_return(true)
2432

25-
{ 1 => inhash }.send(@method, needle).should == 1
33+
suppress_warning do # for Hash#index
34+
{ 1 => inhash }.send(@method, needle).should == 1
35+
end
2636
end
2737
end

core/integer/shared/exponent.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
end
4848

4949
it "returns Float::INFINITY when the number is too big" do
50-
2.send(@method, 427387904).should == Float::INFINITY
50+
-> {
51+
2.send(@method, 427387904).should == Float::INFINITY
52+
}.should complain(/warning: in a\*\*b, b may be too big/)
5153
end
5254

5355
it "raises a ZeroDivisionError for 0 ** -1" do
@@ -105,7 +107,10 @@
105107
end
106108

107109
it "switch to a Float when the values is too big" do
108-
flt = @bignum.send(@method, @bignum)
110+
flt = nil
111+
-> {
112+
flt = @bignum.send(@method, @bignum)
113+
}.should complain(/warning: in a\*\*b, b may be too big/)
109114
flt.should be_kind_of(Float)
110115
flt.infinite?.should == 1
111116
end

core/io/bytes_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
describe "IO#bytes" do
77
before :each do
88
@io = IOSpecs.io_fixture "lines.txt"
9+
@verbose, $VERBOSE = $VERBOSE, nil
910
end
1011

1112
after :each do
13+
$VERBOSE = @verbose
1214
@io.close unless @io.closed?
1315
end
1416

core/io/chars_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@
55

66
ruby_version_is ''...'3.0' do
77
describe "IO#chars" do
8+
before :each do
9+
@verbose, $VERBOSE = $VERBOSE, nil
10+
end
11+
12+
after :each do
13+
$VERBOSE = @verbose
14+
end
15+
816
it_behaves_like :io_chars, :chars
917
end
1018

1119
describe "IO#chars" do
20+
before :each do
21+
@verbose, $VERBOSE = $VERBOSE, nil
22+
end
23+
24+
after :each do
25+
$VERBOSE = @verbose
26+
end
27+
1228
it_behaves_like :io_chars_empty, :chars
1329
end
1430
end

core/io/codepoints_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@
66

77
# See redmine #1667
88
describe "IO#codepoints" do
9+
before :each do
10+
@verbose, $VERBOSE = $VERBOSE, nil
11+
end
12+
13+
after :each do
14+
$VERBOSE = @verbose
15+
end
16+
917
it_behaves_like :io_codepoints, :codepoints
1018
end
1119

1220
describe "IO#codepoints" do
1321
before :each do
1422
@io = IOSpecs.io_fixture "lines.txt"
23+
@verbose, $VERBOSE = $VERBOSE, nil
1524
end
1625

1726
after :each do
27+
$VERBOSE = @verbose
1828
@io.close unless @io.closed?
1929
end
2030

core/io/lines_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
describe "IO#lines" do
77
before :each do
88
@io = IOSpecs.io_fixture "lines.txt"
9+
@verbose, $VERBOSE = $VERBOSE, nil
910
end
1011

1112
after :each do
13+
$VERBOSE = @verbose
1214
@io.close if @io
1315
end
1416

language/pattern_matching_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# TODO: Remove excessive eval calls when support of previous version
66
# Ruby 2.6 will be dropped
77

8-
before do
8+
before :each do
99
ScratchPad.record []
1010
end
1111

@@ -41,14 +41,20 @@
4141
end
4242

4343
describe "warning" do
44-
before do
44+
before :each do
4545
ruby_version_is ""..."3.0" do
4646
@src = 'case [0, 1]; in [a, b]; end'
4747
end
4848

4949
ruby_version_is "3.0" do
5050
@src = '[0, 1] => [a, b]'
5151
end
52+
53+
@experimental, Warning[:experimental] = Warning[:experimental], true
54+
end
55+
56+
after :each do
57+
Warning[:experimental] = @experimental
5258
end
5359

5460
it "warns about pattern matching is experimental feature" do

library/stringio/bytes_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@
44

55
ruby_version_is ''...'3.0' do
66
describe "StringIO#bytes" do
7+
before :each do
8+
@verbose, $VERBOSE = $VERBOSE, nil
9+
end
10+
11+
after :each do
12+
$VERBOSE = @verbose
13+
end
14+
715
it_behaves_like :stringio_each_byte, :bytes
816
end
917

1018
describe "StringIO#bytes when self is not readable" do
19+
before :each do
20+
@verbose, $VERBOSE = $VERBOSE, nil
21+
end
22+
23+
after :each do
24+
$VERBOSE = @verbose
25+
end
26+
1127
it_behaves_like :stringio_each_byte_not_readable, :bytes
1228
end
1329
end

library/stringio/chars_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@
44

55
ruby_version_is ''...'3.0' do
66
describe "StringIO#chars" do
7+
before :each do
8+
@verbose, $VERBOSE = $VERBOSE, nil
9+
end
10+
11+
after :each do
12+
$VERBOSE = @verbose
13+
end
14+
715
it_behaves_like :stringio_each_char, :chars
816
end
917

1018
describe "StringIO#chars when self is not readable" do
19+
before :each do
20+
@verbose, $VERBOSE = $VERBOSE, nil
21+
end
22+
23+
after :each do
24+
$VERBOSE = @verbose
25+
end
26+
1127
it_behaves_like :stringio_each_char_not_readable, :chars
1228
end
1329
end

library/stringio/codepoints_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44
require_relative 'shared/codepoints'
55

66
ruby_version_is ''...'3.0' do
7-
87
# See redmine #1667
98
describe "StringIO#codepoints" do
9+
before :each do
10+
@verbose, $VERBOSE = $VERBOSE, nil
11+
end
12+
13+
after :each do
14+
$VERBOSE = @verbose
15+
end
16+
1017
it_behaves_like :stringio_codepoints, :codepoints
1118
end
1219
end

0 commit comments

Comments
 (0)