summaryrefslogtreecommitdiff
path: root/spec/ruby/core/warning/element_set_spec.rb
blob: d20ee215adad3e9db470213a9377aefc9555dc1b (plain)
1
2
3
4
5
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
33
34
35
require_relative '../../spec_helper'

describe "Warning.[]=" do
  it "emits and suppresses warnings for :deprecated" do
    ruby_exe('Warning[:deprecated] = true; $; = ""', args: "2>&1").should =~ /is deprecated/
    ruby_exe('Warning[:deprecated] = false; $; = ""', args: "2>&1").should == ""
  end

  describe ":experimental" do
    before do
      ruby_version_is ""..."3.0" do
        @src = 'case [0, 1]; in [a, b]; end'
      end

      ruby_version_is "3.0" do
        @src = 'warn "This is experimental warning.", category: :experimental'
      end
    end

    it "emits and suppresses warnings for :experimental" do
      ruby_exe("Warning[:experimental] = true; eval('#{@src}')", args: "2>&1").should =~ /is experimental/
      ruby_exe("Warning[:experimental] = false; eval('#{@src}')", args: "2>&1").should == ""
    end
  end

  it "raises for unknown category" do
    -> { Warning[:noop] = false }.should raise_error(ArgumentError, /unknown category: noop/)
  end

  it "raises for non-Symbol category" do
    -> { Warning[42] = false }.should raise_error(TypeError)
    -> { Warning[false] = false }.should raise_error(TypeError)
    -> { Warning["noop"] = false }.should raise_error(TypeError)
  end
end