Class: Compact::Ledger
- Inherits:
-
Object
- Object
- Compact::Ledger
- Defined in:
- lib/compact/ledger.rb
Instance Method Summary collapse
-
#initialize ⇒ Ledger
constructor
A new instance of Ledger.
- #prepare_double(name, block = Proc.new) ⇒ Object
-
#record_contract(name, test_double, methods_to_watch = []) ⇒ Object
deprecate this?.
- #summary ⇒ Object
- #verify_contract(name, collaborator, block = Proc.new) ⇒ Object
Constructor Details
#initialize ⇒ Ledger
Returns a new instance of Ledger.
4 5 6 |
# File 'lib/compact/ledger.rb', line 4 def initialize @contracts = {} end |
Instance Method Details
#prepare_double(name, block = Proc.new) ⇒ Object
8 9 10 11 12 |
# File 'lib/compact/ledger.rb', line 8 def prepare_double(name, block = Proc.new) @contracts[name] ||= Contract.new contract = @contracts[name] contract.prepare_double(block) end |
#record_contract(name, test_double, methods_to_watch = []) ⇒ Object
deprecate this?
15 16 17 18 19 |
# File 'lib/compact/ledger.rb', line 15 def record_contract(name, test_double, methods_to_watch = []) @contracts[name] ||= Contract.new contract = @contracts[name] contract.watch(test_double, methods_to_watch) end |
#summary ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/compact/ledger.rb', line 27 def summary unverified_contracts = [] @contracts.each do |name, contract| unverified_contracts << contract unless contract.verified? end if unverified_contracts.empty? 'All test double contracts are satisfied.' else msg = <<~EOF The following contracts could not be verified: #{summarise_untested_contracts} #{summarise_pending_contracts} #{summarise_failing_contracts} EOF msg.gsub(/\n+/, "\n") end end |