File: multi_stubber_spec.rb

package info (click to toggle)
ruby-bogus 0.1.5-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 828 kB
  • ctags: 628
  • sloc: ruby: 4,124; makefile: 6; sh: 2
file content (31 lines) | stat: -rw-r--r-- 795 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
require 'spec_helper'

describe Bogus::MultiStubber do
  let(:double) { FakeDouble.new }
  let(:create_double) { proc{ double } }
  let(:any_args) { Bogus::AnyArgs }

  let(:multi_stubber) { isolate(Bogus::MultiStubber) }

  it "stubs all the given methods with any args returning the given value" do
    multi_stubber.stub_all(Object.new, foo: 1, bar: 2)

    expect(double.stubbed).to eq([[:foo, [any_args], 1], [:bar, [any_args], 2]])
  end

  it "uses passed procs as the return value block" do
    multi_stubber.stub_all(Object.new, foo: proc{ 1 })

    expect(double.stubbed).to eq([[:foo, [any_args], 1]])
  end

  class FakeDouble
    def stubbed
      @stubbed ||= []
    end

    def stubs(name, *args, &return_value)
      stubbed << [name, args, return_value.call]
    end
  end
end