Class: Compact::Contract
- Inherits:
-
Object
- Object
- Compact::Contract
- Defined in:
- lib/compact/contract.rb
Instance Attribute Summary collapse
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
Instance Method Summary collapse
- #add_invocation(invocation) ⇒ Object
- #describe_failing_specs ⇒ Object
- #describe_pending_specs ⇒ Object
- #describe_untested_specs ⇒ Object
- #has_failing? ⇒ Boolean
- #has_pending? ⇒ Boolean
- #has_untested? ⇒ Boolean
-
#initialize ⇒ Contract
constructor
A new instance of Contract.
- #prepare_double(block = Proc.new) ⇒ Object
- #verified? ⇒ Boolean
- #verify(collaborator, block = Proc.new) ⇒ Object
Constructor Details
#initialize ⇒ Contract
Returns a new instance of Contract.
8 9 10 11 |
# File 'lib/compact/contract.rb', line 8 def initialize @collaborator_invocations = Set.new @test_double_invocations = Set.new end |
Instance Attribute Details
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
6 7 8 |
# File 'lib/compact/contract.rb', line 6 def specs @specs end |
Instance Method Details
#add_invocation(invocation) ⇒ Object
64 65 66 |
# File 'lib/compact/contract.rb', line 64 def add_invocation(invocation) @test_double_invocations.add(invocation) end |
#describe_failing_specs ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/compact/contract.rb', line 48 def describe_failing_specs headline = "Attempts to verify the following method invocations failed:" = failing_invocations.map do |invocation| bad_results = unspecified_invocations.select{|p| p.matches_call(invocation) } invocation.describe.gsub("returns", "expected") + "\nMatching invocations returned the following values: #{bad_results.map(&:returns).inspect}" end (headline, ) end |
#describe_pending_specs ⇒ Object
42 43 44 45 46 |
# File 'lib/compact/contract.rb', line 42 def describe_pending_specs headline = "No test doubles mirror the following verified invocations:" = pending_invocations.map(&:describe) (headline, ) end |
#describe_untested_specs ⇒ Object
36 37 38 39 40 |
# File 'lib/compact/contract.rb', line 36 def describe_untested_specs headline = "The following methods were invoked on test doubles without corresponding contract tests:" = untested_invocations.map(&:describe) (headline, ) end |
#has_failing? ⇒ Boolean
32 33 34 |
# File 'lib/compact/contract.rb', line 32 def has_failing? !failing_invocations.empty? end |
#has_pending? ⇒ Boolean
24 25 26 |
# File 'lib/compact/contract.rb', line 24 def has_pending? !pending_invocations.empty? end |
#has_untested? ⇒ Boolean
28 29 30 |
# File 'lib/compact/contract.rb', line 28 def has_untested? !untested_invocations.empty? end |
#prepare_double(block = Proc.new) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/compact/contract.rb', line 13 def prepare_double(block = Proc.new) double = block.call interceptor = ArgumentInterceptor.new(double) interceptor.register(self) interceptor end |
#verified? ⇒ Boolean
20 21 22 |
# File 'lib/compact/contract.rb', line 20 def verified? @test_double_invocations == @collaborator_invocations end |
#verify(collaborator, block = Proc.new) ⇒ Object
58 59 60 61 62 |
# File 'lib/compact/contract.rb', line 58 def verify(collaborator, block = Proc.new) interceptor = ArgumentInterceptor.new(collaborator) block.call(interceptor) interceptor.invocations.each{|inv| @collaborator_invocations.add(inv) } end |