File: test_api.rb

package info (click to toggle)
ruby-spy 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 360 kB
  • sloc: ruby: 3,101; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 807 bytes parent folder | download | duplicates (2)
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
require 'test_helper'

class TestApi < Minitest::Test
  include Spy::API

  def setup
    @pen = Pen.new
    Spy.on(@pen, :write)
  end

  def test_assert_received
    @pen.write(:hello)
    assert_received(@pen, :write)
  end

  def test_assert_received_with
    @pen.write(:world)
    assert_received_with(@pen, :write, :world)
    assert_received_with(@pen, :write) do |call|
      call.args == [:world]
    end
  end

  def test_have_received
    @pen.write(:foo)
    matcher = have_received(:write)
    assert matcher.matches?(@pen)
  end

  def test_have_received_with
    @pen.write(:bar)
    matcher = have_received(:write).with(:bar)
    assert matcher.matches?(@pen)

    matcher = have_received(:write).with do |call|
      call.args == [:bar]
    end
    assert matcher.matches?(@pen)
  end
end