class Compact::Contract
Attributes
specs[R]
Public Class Methods
new()
click to toggle source
# File lib/compact/contract.rb, line 8 def initialize @collaborator_invocations = Set.new @test_double_invocations = Set.new end
Public Instance Methods
add_invocation(invocation)
click to toggle source
# File lib/compact/contract.rb, line 64 def add_invocation(invocation) @test_double_invocations.add(invocation) end
describe_failing_specs()
click to toggle source
# File lib/compact/contract.rb, line 48 def describe_failing_specs headline = "Attempts to verify the following method invocations failed:" messages = 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 print_banner_separated(headline, messages) end
describe_pending_specs()
click to toggle source
# File lib/compact/contract.rb, line 42 def describe_pending_specs headline = "No test doubles mirror the following verified invocations:" messages = pending_invocations.map(&:describe) print_banner_separated(headline, messages) end
describe_untested_specs()
click to toggle source
# File lib/compact/contract.rb, line 36 def describe_untested_specs headline = "The following methods were invoked on test doubles without corresponding contract tests:" messages = untested_invocations.map(&:describe) print_banner_separated(headline, messages) end
has_failing?()
click to toggle source
# File lib/compact/contract.rb, line 32 def has_failing? !failing_invocations.empty? end
has_pending?()
click to toggle source
# File lib/compact/contract.rb, line 24 def has_pending? !pending_invocations.empty? end
has_untested?()
click to toggle source
# File lib/compact/contract.rb, line 28 def has_untested? !untested_invocations.empty? end
prepare_double(block = Proc.new)
click to toggle source
# 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?()
click to toggle source
# File lib/compact/contract.rb, line 20 def verified? @test_double_invocations == @collaborator_invocations end
verify(collaborator, block = Proc.new)
click to toggle source
# 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
Private Instance Methods
failing_invocations()
click to toggle source
# File lib/compact/contract.rb, line 88 def failing_invocations uncorroborated_invocations.select do |spec| unspecified_invocations.any?{|inv| inv.matches_call(spec)} end end
pending_invocations()
click to toggle source
# File lib/compact/contract.rb, line 74 def pending_invocations unspecified_invocations.reject do |inv| failing_invocations.any? {|failure| inv.matches_call(failure)} end end
uncorroborated_invocations()
click to toggle source
# File lib/compact/contract.rb, line 80 def uncorroborated_invocations (@test_double_invocations - @collaborator_invocations).to_a end
unspecified_invocations()
click to toggle source
# File lib/compact/contract.rb, line 84 def unspecified_invocations (@collaborator_invocations - @test_double_invocations).to_a end
untested_invocations()
click to toggle source
# File lib/compact/contract.rb, line 70 def untested_invocations uncorroborated_invocations - failing_invocations end