File: contract_not_fulfilled.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-- 757 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
module Bogus
  class ContractNotFulfilled < StandardError
    attr_reader :fake_name, :missed_interactions, :actual_interactions

    def initialize(fake_name, opts = {})
      @fake_name = fake_name
      @actual_interactions = opts.fetch(:actual)
      @missed_interactions = opts.fetch(:missed)
      super(message)
    end

    def message
      str = <<-EOF
      Contract not fullfilled for #{fake_name}!

      Missed interactions:
      #{interactions_str(missed_interactions)}

      Actual interactions:
      #{interactions_str(actual_interactions)}
      EOF
      str.gsub(' ' * 6, '')
    end

    private

    def interactions_str(interactions)
      interactions.map { |i| "  - #{InteractionPresenter.new(i)}" }.join("\n")
    end
  end
end