File: frozen_fakes_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 (59 lines) | stat: -rw-r--r-- 1,135 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
require "spec_helper"

describe "Frozen Fakes" do
  include Bogus::MockingDSL

  class ExampleForFreezing
    def foo(x)
    end
  end

  shared_examples_for "frozen fakes" do
    before { object.freeze }

    describe "stubbing" do
      it "allows stubbing" do
        stub(object).foo(1) { 123 }

        expect(object.foo(1)).to eq 123
      end
    end

    describe "mocking" do
      it "allows mocking" do
        mock(object).foo(1) { 123 }

        expect(object.foo(1)).to eq 123
      end

      it "allows verifying expectations" do
        mock(object).foo(1) { 123 }

        expect {
          Bogus.after_each_test
        }.to raise_error(Bogus::NotAllExpectationsSatisfied)
      end
    end

    describe "spying" do
      it "allows spying" do
        object.foo(1)

        expect(object).to have_received.foo(1)
        expect(object).to_not have_received.foo(2)
      end
    end
  end

  context "anonymous fakes" do
    let(:object) { fake }

    include_examples "frozen fakes"
  end

  context "named fakes" do
    let(:object) { fake(:example_for_freezing) }

    include_examples "frozen fakes"
  end
end