File: pebble_spec.rb

package info (click to toggle)
ruby-naught 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: ruby: 1,091; makefile: 6
file content (77 lines) | stat: -rw-r--r-- 2,107 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'
require 'stringio'

describe 'pebble null object' do
  class Caller
    def call_method(thing)
      thing.info
    end

    def call_method_inside_block(thing)
      2.times.each { thing.info }
    end

    def call_method_inside_nested_block(thing)
      2.times.each { 2.times.each { thing.info } }
    end
  end

  subject(:null) { null_class.new }
  let(:null_class) do
    output = test_output # getting local binding
    Naught.build do |b|
      b.pebble output
    end
  end

  let(:test_output) { StringIO.new }

  it 'prints the name of the method called' do
    expect(test_output).to receive(:puts).with(/^info\(\)/)
    null.info
  end

  it 'prints the arguments received' do
    expect(test_output).to receive(:puts).with(/^info\(\'foo\', 5, \:sym\)/)
    null.info('foo', 5, :sym)
  end

  it 'prints the name of the caller' do
    expect(test_output).to receive(:puts).with(/from call_method$/)
    Caller.new.call_method(null)
  end

  it 'returns self' do
    expect(null.info).to be(null)
  end

  context 'when is called from a block' do
    it 'prints the indication of a block',
       :pending => jruby? || rubinius? || ruby_18? do
      expect(test_output).to receive(:puts).twice.
        with(/from block/)
      Caller.new.call_method_inside_block(null)
    end

    it 'prints the name of the method that has the block' do
      expect(test_output).to receive(:puts).twice.
        with(/call_method_inside_block$/)
      Caller.new.call_method_inside_block(null)
    end
  end

  context 'when is called from many levels blocks' do
    it 'prints the indication of blocks and its levels',
       :pending => jruby? || rubinius? || ruby_18? do
      expect(test_output).to receive(:puts).exactly(4).times.
        with(/from block \(2 levels\)/)
      Caller.new.call_method_inside_nested_block(null)
    end

    it 'prints the name of the method that has the block' do
      expect(test_output).to receive(:puts).exactly(4).times.
        with(/call_method_inside_nested_block$/)
      Caller.new.call_method_inside_nested_block(null)
    end
  end
end