Sha256: 6de01d0e8f9b10d3b8e22b47e56a6afc9bf407024281edf349e80d94b2944d83
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
# This file provides a few new assertions and class methods for expressing # contracts in a comfortable way that does not require manually writing test # methods. # # See Contract.provides. class Contract < Test::Unit::TestCase # Tests that the tested Object provides the specified methods with the # specified behavior. # # If a block is supplied it will be evaluated in the context of the # contract so <code>@object</code> will refer to the object being tested. # # This can be used like this: # class ListContract < Contract # provides :size do # assert(@object.size >= 0, "#size should never be negative.") # end # # provides :include? # # provides :each do # count = 0 # @object.each do |item| # assert(@object.include?(item), # "#each should only yield items that the list includes.") # count += 1 # end # assert_equal(@object.size, count, # "#each should yield #size items.") # end # end def self.provides(*symbols, &block) # :yields: symbols.each do |symbol| define_method("test_provides_#{symbol}".intern) do assert_respond_to(@object, symbol) instance_eval(&block) if block end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby-contract-0.1.1 | lib/contract/assertions.rb |