File: kernel_spec.rb

package info (click to toggle)
ruby-rspec 3.13.0c0e0m0s1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,856 kB
  • sloc: ruby: 70,868; sh: 1,423; makefile: 99
file content (79 lines) | stat: -rw-r--r-- 2,559 bytes parent folder | download
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
RSpec.describe Object, "#should" do
  before(:example) do
    @target = "target"
    @matcher = double("matcher", :supports_value_expectations? => true)
    allow(@matcher).to receive(:matches?).and_return(true)
    allow(@matcher).to receive(:failure_message)
  end

  it "accepts and interacts with a matcher" do
    expect(@matcher).to receive(:matches?).with(@target).and_return(true)
    expect(@target).to @matcher
  end

  it "asks for a failure_message when matches? returns false" do
    expect(@matcher).to receive(:matches?).with(@target).and_return(false)
    expect(@matcher).to receive(:failure_message).and_return("the failure message")
    expect {
      expect(@target).to @matcher
    }.to fail_with("the failure message")
  end

  context "on interpreters that have BasicObject", :if => defined?(BasicObject) do
    let(:proxy_class) do
      Class.new(BasicObject) do
        def initialize(target)
          @target = target
        end

        def proxied?
          true
        end

        def respond_to?(method, *args)
          method.to_sym == :proxied? || @target.respond_to?(symbol, *args)
        end

        def method_missing(name, *args)
          @target.send(name, *args)
        end
      end
    end

    it 'works properly on BasicObject-subclassed proxy objects' do
      expect(proxy_class.new(Object.new)).to be_proxied
    end

    it 'does not break the deprecation check on BasicObject-subclassed proxy objects' do
      begin
        should_enabled = RSpec::Expectations::Syntax.should_enabled?
        RSpec::Expectations::Syntax.enable_should unless should_enabled
        proxy_class.new(BasicObject.new).should be_proxied
      ensure
        RSpec::Expectations::Syntax.disable_should if should_enabled
      end
    end
  end
end

RSpec.describe Object, "#should_not" do
  before(:example) do
    @target = "target"
    @matcher = double("matcher", :supports_value_expectations? => true)
  end

  it "accepts and interacts with a matcher" do
    expect(@matcher).to receive(:matches?).with(@target).and_return(false)
    allow(@matcher).to receive(:failure_message_when_negated)

    expect(@target).not_to @matcher
  end

  it "asks for a failure_message_when_negated when matches? returns true" do
    expect(@matcher).to receive(:matches?).with(@target).and_return(true)
    expect(@matcher).to receive(:failure_message_when_negated).and_return("the failure message for should not")
    expect {
      expect(@target).not_to @matcher
    }.to fail_with("the failure message for should not")
  end
end