File: ensures_all_interactions_satisfied_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 (43 lines) | stat: -rw-r--r-- 1,318 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
require 'spec_helper'

describe Bogus::EnsuresAllInteractionsSatisfied do
  let(:ensures_all_interactions_satisfied) { isolate(Bogus::EnsuresAllInteractionsSatisfied) }

  it "does nothing with all interactions satisfied" do
    objects = 3.times.map { |n| Samples::FooFake.new }

    expect {
      ensures_all_interactions_satisfied.ensure_satisfied!(objects)
    }.not_to raise_error
  end

  it "raises an error enumerating satisfied and unsatisfied interactions" do
    foo = Samples::FooFake.new
    foo.__shadow__.mocks(:foo, "a", "b") { "result" }
    foo.__shadow__.mocks(:foo, "a", "c") { "result 2" }
    foo.__shadow__.run(:foo, "a", "b")

    bar = Samples::FooFake.new
    bar.__shadow__.stubs(:foo, "a", "b") { "result" }
    bar.__shadow__.stubs(:foo, "a", "c") { "result 2" }
    bar.__shadow__.run(:foo, "a", "b")
    bar.__shadow__.run(:foo, "x", "y")

    msg = <<-EOF
    Some of the mocked interactions were not satisfied:

      - #{foo.inspect}.foo("a", "c")

    The following calls were recorded:

      - #{foo.inspect}.foo("a", "b")
      - #{bar.inspect}.foo("a", "b")
      - #{bar.inspect}.foo("x", "y")
    EOF

    expect {
      ensures_all_interactions_satisfied.ensure_satisfied!([foo, bar])
    }.to raise_error(Bogus::NotAllExpectationsSatisfied, msg.gsub(/ {4}/, ''))
  end

end