ruby-contract 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +56 -0
- data/Manifest +85 -0
- data/README +32 -0
- data/TODO +83 -0
- data/doc/classes/Contract.html +599 -0
- data/doc/classes/Contract/Check.html +229 -0
- data/doc/classes/Contract/Check/All.html +172 -0
- data/doc/classes/Contract/Check/Any.html +172 -0
- data/doc/classes/Contract/Check/Block.html +172 -0
- data/doc/classes/Contract/Check/None.html +173 -0
- data/doc/classes/Contract/Check/Quack.html +172 -0
- data/doc/classes/Contract/ContractError.html +151 -0
- data/doc/classes/Contract/ContractException.html +162 -0
- data/doc/classes/Contract/ContractMismatch.html +134 -0
- data/doc/classes/Kernel.html +256 -0
- data/doc/classes/Method.html +135 -0
- data/doc/classes/MethodSignatureMixin.html +208 -0
- data/doc/classes/Module.html +526 -0
- data/doc/created.rid +1 -0
- data/doc/dot/f_0.dot +14 -0
- data/doc/dot/f_0.png +0 -0
- data/doc/dot/f_1.dot +14 -0
- data/doc/dot/f_1.png +0 -0
- data/doc/dot/f_2.dot +14 -0
- data/doc/dot/f_2.png +0 -0
- data/doc/dot/f_3.dot +112 -0
- data/doc/dot/f_3.png +0 -0
- data/doc/dot/f_4.dot +62 -0
- data/doc/dot/f_4.png +0 -0
- data/doc/dot/f_5.dot +62 -0
- data/doc/dot/f_5.png +0 -0
- data/doc/dot/f_6.dot +224 -0
- data/doc/dot/f_6.png +0 -0
- data/doc/dot/f_6_0.dot +24 -0
- data/doc/dot/f_6_0.png +0 -0
- data/doc/dot/f_6_1.dot +24 -0
- data/doc/dot/f_6_1.png +0 -0
- data/doc/dot/f_7.dot +62 -0
- data/doc/dot/f_7.png +0 -0
- data/doc/files/COPYING.html +168 -0
- data/doc/files/README.html +146 -0
- data/doc/files/TODO.html +240 -0
- data/doc/files/lib/contract/assertions_rb.html +118 -0
- data/doc/files/lib/contract/exception_rb.html +125 -0
- data/doc/files/lib/contract/integration_rb.html +130 -0
- data/doc/files/lib/contract/overrides_rb.html +118 -0
- data/doc/files/lib/contract_rb.html +127 -0
- data/doc/fr_class_index.html +40 -0
- data/doc/fr_file_index.html +34 -0
- data/doc/fr_method_index.html +45 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/contract.rb +146 -0
- data/lib/contract/assertions.rb +42 -0
- data/lib/contract/exception.rb +95 -0
- data/lib/contract/integration.rb +664 -0
- data/lib/contract/overrides.rb +41 -0
- data/setup.rb +1360 -0
- data/test/coverage/_-lib-contract-assertions_rb.html +526 -0
- data/test/coverage/_-lib-contract-exception_rb.html +632 -0
- data/test/coverage/_-lib-contract-integration_rb.html +1450 -0
- data/test/coverage/_-lib-contract-overrides_rb.html +524 -0
- data/test/coverage/_-lib-contract_rb.html +724 -0
- data/test/coverage/__-lib-contract-assertions_rb.html +484 -0
- data/test/coverage/__-lib-contract-exception_rb.html +537 -0
- data/test/coverage/__-lib-contract-integration_rb.html +946 -0
- data/test/coverage/__-lib-contract-overrides_rb.html +483 -0
- data/test/coverage/__-lib-contract_rb.html +583 -0
- data/test/coverage/index.html +93 -0
- data/test/tc_all.rb +8 -0
- data/test/tc_contract.rb +109 -0
- data/test/tc_exception.rb +43 -0
- data/test/tc_integration.rb +357 -0
- metadata +136 -0
data/COPYING
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
ruby-contract is copyrighted free software by Florian Gross <flgr@ccan.de>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the GPL
|
3
|
+
(see the file GPL), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a) place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b) use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c) give non-standard binaries non-standard names, with
|
21
|
+
instructions on where to get the original software distribution.
|
22
|
+
|
23
|
+
d) make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or binary form,
|
26
|
+
provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a) distribute the binaries and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b) accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c) give non-standard binaries non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d) make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under these terms.
|
43
|
+
|
44
|
+
For the list of those files and their copying conditions, see the
|
45
|
+
file LEGAL.
|
46
|
+
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
48
|
+
output from the software do not automatically fall under the
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
51
|
+
software.
|
52
|
+
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
56
|
+
PURPOSE.
|
data/Manifest
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
lib
|
2
|
+
test
|
3
|
+
doc
|
4
|
+
TODO
|
5
|
+
COPYING
|
6
|
+
README
|
7
|
+
setup.rb
|
8
|
+
Manifest
|
9
|
+
lib/contract.rb
|
10
|
+
lib/contract
|
11
|
+
lib/contract/integration.rb
|
12
|
+
lib/contract/assertions.rb
|
13
|
+
lib/contract/overrides.rb
|
14
|
+
lib/contract/exception.rb
|
15
|
+
test/tc_contract.rb
|
16
|
+
test/tc_integration.rb
|
17
|
+
test/coverage
|
18
|
+
test/tc_exception.rb
|
19
|
+
test/tc_all.rb
|
20
|
+
test/coverage/_-lib-contract-integration_rb.html
|
21
|
+
test/coverage/_-lib-contract-assertions_rb.html
|
22
|
+
test/coverage/_-lib-contract-overrides_rb.html
|
23
|
+
test/coverage/_-lib-contract-exception_rb.html
|
24
|
+
test/coverage/_-lib-contract_rb.html
|
25
|
+
test/coverage/__-lib-contract-assertions_rb.html
|
26
|
+
test/coverage/__-lib-contract-exception_rb.html
|
27
|
+
test/coverage/__-lib-contract_rb.html
|
28
|
+
test/coverage/__-lib-contract-overrides_rb.html
|
29
|
+
test/coverage/__-lib-contract-integration_rb.html
|
30
|
+
test/coverage/index.html
|
31
|
+
doc/index.html
|
32
|
+
doc/fr_method_index.html
|
33
|
+
doc/fr_class_index.html
|
34
|
+
doc/fr_file_index.html
|
35
|
+
doc/classes
|
36
|
+
doc/files
|
37
|
+
doc/rdoc-style.css
|
38
|
+
doc/dot
|
39
|
+
doc/created.rid
|
40
|
+
doc/classes/Kernel.html
|
41
|
+
doc/classes/MethodSignatureMixin.html
|
42
|
+
doc/classes/Module.html
|
43
|
+
doc/classes/Method.html
|
44
|
+
doc/classes/Contract
|
45
|
+
doc/classes/Contract.html
|
46
|
+
doc/classes/Contract/ContractMismatch.html
|
47
|
+
doc/classes/Contract/ContractError.html
|
48
|
+
doc/classes/Contract/Check
|
49
|
+
doc/classes/Contract/Check.html
|
50
|
+
doc/classes/Contract/ContractException.html
|
51
|
+
doc/classes/Contract/Check/Quack.html
|
52
|
+
doc/classes/Contract/Check/Block.html
|
53
|
+
doc/classes/Contract/Check/None.html
|
54
|
+
doc/classes/Contract/Check/All.html
|
55
|
+
doc/classes/Contract/Check/Any.html
|
56
|
+
doc/files/lib
|
57
|
+
doc/files/README.html
|
58
|
+
doc/files/COPYING.html
|
59
|
+
doc/files/TODO.html
|
60
|
+
doc/files/lib/contract_rb.html
|
61
|
+
doc/files/lib/contract
|
62
|
+
doc/files/lib/contract/integration_rb.html
|
63
|
+
doc/files/lib/contract/assertions_rb.html
|
64
|
+
doc/files/lib/contract/overrides_rb.html
|
65
|
+
doc/files/lib/contract/exception_rb.html
|
66
|
+
doc/dot/f_7.png
|
67
|
+
doc/dot/f_7.dot
|
68
|
+
doc/dot/f_6_1.png
|
69
|
+
doc/dot/f_6_1.dot
|
70
|
+
doc/dot/f_6_0.png
|
71
|
+
doc/dot/f_6_0.dot
|
72
|
+
doc/dot/f_6.png
|
73
|
+
doc/dot/f_6.dot
|
74
|
+
doc/dot/f_5.png
|
75
|
+
doc/dot/f_5.dot
|
76
|
+
doc/dot/f_4.png
|
77
|
+
doc/dot/f_4.dot
|
78
|
+
doc/dot/f_3.png
|
79
|
+
doc/dot/f_3.dot
|
80
|
+
doc/dot/f_2.png
|
81
|
+
doc/dot/f_2.dot
|
82
|
+
doc/dot/f_1.png
|
83
|
+
doc/dot/f_1.dot
|
84
|
+
doc/dot/f_0.png
|
85
|
+
doc/dot/f_0.dot
|
data/README
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= ruby-contract 0.1.1 README
|
2
|
+
|
3
|
+
ruby-contract provides support for describing and using types via unit-tests.
|
4
|
+
It offers support for specifying contracts (Contract), method signature checks
|
5
|
+
(Module#signature), automatic adaption between types (Kernel#adaption) and
|
6
|
+
integration with the classic message- and class-based typing.
|
7
|
+
|
8
|
+
== Requirements
|
9
|
+
|
10
|
+
* Ruby >= 1.8.1
|
11
|
+
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
|
15
|
+
De-compress archive and enter its top directory. Then type:
|
16
|
+
|
17
|
+
($ su)
|
18
|
+
# ruby setup.rb
|
19
|
+
|
20
|
+
These simple step installs this program under the default location of Ruby
|
21
|
+
libraries. You can also install files into your favorite directory by supplying
|
22
|
+
setup.rb some options. Try "ruby setup.rb --help".
|
23
|
+
|
24
|
+
|
25
|
+
== License
|
26
|
+
|
27
|
+
Dual licensed under GPL and Ruby's custom license. See COPYING.
|
28
|
+
|
29
|
+
|
30
|
+
== Author
|
31
|
+
|
32
|
+
Florian Gross, flgr@ccan.de
|
data/TODO
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
= TODO
|
2
|
+
|
3
|
+
* Also think about how to extend the DBC abilities. Invariants would be nice, but
|
4
|
+
how to implement them?
|
5
|
+
|
6
|
+
* Add multi method dispatch facilities similar to those from dispatch.rb. It would
|
7
|
+
be good if code could be shared between that and signatures.
|
8
|
+
|
9
|
+
* Write introductionary explanation of what we do and don't and why we do so.
|
10
|
+
Probably belongs into the README but should also appear in the RDoc output.
|
11
|
+
http://split-s.blogspot.com/2005/02/quack-quack.html might be useful for
|
12
|
+
explaining why this is better than doing the usual is-a typing of static
|
13
|
+
languages.
|
14
|
+
|
15
|
+
* Perhaps teach the Rakefile how to export the SVN tree to the RubyForge project
|
16
|
+
(see http://svn2cvs.tigris.org/)
|
17
|
+
|
18
|
+
* If we add DBC we probably ought to have ways of getting the pre and post
|
19
|
+
checks as well as the in-variants as an Array of Procs or something like
|
20
|
+
that.
|
21
|
+
|
22
|
+
* Make Method#signature return a meta object that allows you to do
|
23
|
+
method.signature.matches?(*args) or something similar?
|
24
|
+
|
25
|
+
|
26
|
+
= Done
|
27
|
+
|
28
|
+
* Add methods for querying signature meta information. (Unbound)Method#signature
|
29
|
+
would return the original Module#signature arguments.
|
30
|
+
|
31
|
+
* Set up a RubyForge project and teach the Rakefile how to upload releases
|
32
|
+
|
33
|
+
* Contact the pragprog guys about DBC in Ruby:
|
34
|
+
http://www.eng.cse.dmu.ac.uk/~hgs/projects/ruby_dbc.html
|
35
|
+
* Done, might base post/pre-conditions implementation on that project
|
36
|
+
|
37
|
+
* Think about the kind of object adaption that matz discussed on his weblog:
|
38
|
+
http://redhanded.hobix.com/inspect/staticTyping.html
|
39
|
+
Also see http://www.python.org/peps/pep-0246.html and
|
40
|
+
http://peak.telecommunity.com/DevCenter/MonkeyTyping
|
41
|
+
|
42
|
+
adaption :from => Pathname, :to => String, :via => :to_str
|
43
|
+
adaption :from => String, :to => Pathname do |string|
|
44
|
+
Pathname.new(string)
|
45
|
+
end
|
46
|
+
adaption :from => String, :to => Pathname, :via => Pathname.method(:new)
|
47
|
+
|
48
|
+
Perhaps make both :from and :to default to self so short forms are possible
|
49
|
+
inside classes: (raise Exception when :to == :from)
|
50
|
+
|
51
|
+
class String
|
52
|
+
adaption :to => Pathname, :via => Pathname.method(:new)
|
53
|
+
adaption :from => Pathname, :via => :to_str
|
54
|
+
|
55
|
+
adaption :to => Symbol, :via => :to_sym
|
56
|
+
end
|
57
|
+
|
58
|
+
Might be nice to have conditional adaption routes:
|
59
|
+
|
60
|
+
class Object
|
61
|
+
adaption :to => String, :via => :to_str, :if => Contract::Check::Quack[:to_str]
|
62
|
+
# perhaps also introduce this short form
|
63
|
+
adaption :to => String, :via => :to_str, :if => :to_str
|
64
|
+
end
|
65
|
+
|
66
|
+
Perhaps :if should default to :via if :via is a Symbol which would allow the
|
67
|
+
above to become
|
68
|
+
|
69
|
+
class Object
|
70
|
+
adaption :to => String, :via => :to_str
|
71
|
+
end
|
72
|
+
* Implemented.
|
73
|
+
|
74
|
+
* Think about implementing Contract#implies which would automatically trigger the
|
75
|
+
inclusion of a Module on other Modules/Classes that do fulfills(contract).
|
76
|
+
* Implemented.
|
77
|
+
|
78
|
+
* Module#fulfills(contract) -- a way of stating that all instances of a Class
|
79
|
+
should be checked against the contract after initialisation. This would always
|
80
|
+
need to be called after defining a custom initialize().
|
81
|
+
|
82
|
+
* Read http://www.smalltalk.org/articles/
|
83
|
+
* Has a few generic comments about static typing and dynamic typing.
|
@@ -0,0 +1,599 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Contract</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Contract</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/contract/exception_rb.html">
|
59
|
+
lib/contract/exception.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
<a href="../files/lib/contract/overrides_rb.html">
|
63
|
+
lib/contract/overrides.rb
|
64
|
+
</a>
|
65
|
+
<br />
|
66
|
+
<a href="../files/lib/contract/assertions_rb.html">
|
67
|
+
lib/contract/assertions.rb
|
68
|
+
</a>
|
69
|
+
<br />
|
70
|
+
<a href="../files/lib/contract/integration_rb.html">
|
71
|
+
lib/contract/integration.rb
|
72
|
+
</a>
|
73
|
+
<br />
|
74
|
+
<a href="../files/lib/contract_rb.html">
|
75
|
+
lib/contract.rb
|
76
|
+
</a>
|
77
|
+
<br />
|
78
|
+
</td>
|
79
|
+
</tr>
|
80
|
+
|
81
|
+
<tr class="top-aligned-row">
|
82
|
+
<td><strong>Parent:</strong></td>
|
83
|
+
<td>
|
84
|
+
Test::Unit::TestCase
|
85
|
+
</td>
|
86
|
+
</tr>
|
87
|
+
</table>
|
88
|
+
</div>
|
89
|
+
<!-- banner header -->
|
90
|
+
|
91
|
+
<div id="bodyContent">
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
<div id="contextContent">
|
96
|
+
<div id="diagram">
|
97
|
+
<map id="map" name="map">
|
98
|
+
<area shape="RECT" coords="32,113,104,161" href="Contract.html" alt="Contract" title="Contract">
|
99
|
+
</map>
|
100
|
+
<img src="../dot/f_7.png" usemap="#map" border=0 alt="lib/contract.rb">
|
101
|
+
</div>
|
102
|
+
|
103
|
+
<div id="description">
|
104
|
+
<p>
|
105
|
+
Represents a contract between Objects as a collection of test cases.
|
106
|
+
Objects are said to fulfill a contract if all test cases suceed. This is
|
107
|
+
useful for ensuring that Objects your code is getting behave in a way that
|
108
|
+
you expect them to behave so you can fail early or execute different logic
|
109
|
+
for Objects with different interfaces.
|
110
|
+
</p>
|
111
|
+
<p>
|
112
|
+
The tests of the test suite will be run on a copy of the tested Object so
|
113
|
+
you can safely test its behavior without having to fear data loss. By
|
114
|
+
default Contracts obtain deep copies of Objects by serializing and
|
115
|
+
unserializing them with Ruby’s <tt>Marshal</tt> functionality. This
|
116
|
+
will work in most cases but can fail for Objects containing unserializable
|
117
|
+
parts like Procs, Files or Sockets. In those cases it is currently of your
|
118
|
+
responsibility to provide a fitting implementation by overwriting the <a
|
119
|
+
href="Contract.html#M000007">Contract.deep_copy</a> method. In the future
|
120
|
+
the contract library might provide different implementations of it via
|
121
|
+
Ruby’s mixin mechanism.
|
122
|
+
</p>
|
123
|
+
|
124
|
+
</div>
|
125
|
+
|
126
|
+
|
127
|
+
</div>
|
128
|
+
|
129
|
+
<div id="method-list">
|
130
|
+
<h3 class="section-bar">Methods</h3>
|
131
|
+
|
132
|
+
<div class="name-list">
|
133
|
+
<a href="#M000002">adapt</a>
|
134
|
+
<a href="#M000007">deep_copy</a>
|
135
|
+
<a href="#M000004">enforce</a>
|
136
|
+
<a href="#M000003">fulfilled_by?</a>
|
137
|
+
<a href="#M000008">implies</a>
|
138
|
+
<a href="#M000001">provides</a>
|
139
|
+
<a href="#M000005">test</a>
|
140
|
+
<a href="#M000006">test_all</a>
|
141
|
+
</div>
|
142
|
+
</div>
|
143
|
+
|
144
|
+
</div>
|
145
|
+
|
146
|
+
|
147
|
+
<!-- if includes -->
|
148
|
+
|
149
|
+
<div id="section">
|
150
|
+
|
151
|
+
<div id="class-list">
|
152
|
+
<h3 class="section-bar">Classes and Modules</h3>
|
153
|
+
|
154
|
+
Module <a href="Contract/Check.html" class="link">Contract::Check</a><br />
|
155
|
+
Module <a href="Contract/ContractException.html" class="link">Contract::ContractException</a><br />
|
156
|
+
Class <a href="Contract/ContractError.html" class="link">Contract::ContractError</a><br />
|
157
|
+
Class <a href="Contract/ContractMismatch.html" class="link">Contract::ContractMismatch</a><br />
|
158
|
+
|
159
|
+
</div>
|
160
|
+
|
161
|
+
<div id="constants-list">
|
162
|
+
<h3 class="section-bar">Constants</h3>
|
163
|
+
|
164
|
+
<div class="name-list">
|
165
|
+
<table summary="Constants">
|
166
|
+
<tr class="top-aligned-row context-row">
|
167
|
+
<td class="context-item-name">Version</td>
|
168
|
+
<td>=</td>
|
169
|
+
<td class="context-item-value">current_version</td>
|
170
|
+
<td width="3em"> </td>
|
171
|
+
<td class="context-item-desc">
|
172
|
+
The Version of the contract library you are using as String of the 1.2.3
|
173
|
+
form where the digits stand for release, major and minor version
|
174
|
+
respectively.
|
175
|
+
|
176
|
+
</td>
|
177
|
+
</tr>
|
178
|
+
</table>
|
179
|
+
</div>
|
180
|
+
</div>
|
181
|
+
|
182
|
+
<div id="aliases-list">
|
183
|
+
<h3 class="section-bar">External Aliases</h3>
|
184
|
+
|
185
|
+
<div class="name-list">
|
186
|
+
<table summary="aliases">
|
187
|
+
<tr class="top-aligned-row context-row">
|
188
|
+
<td class="context-item-name">check_signatures</td>
|
189
|
+
<td>-></td>
|
190
|
+
<td class="context-item-value">check_signatures?</td>
|
191
|
+
</tr>
|
192
|
+
<tr class="top-aligned-row context-row">
|
193
|
+
<td class="context-item-name">check_fulfills</td>
|
194
|
+
<td>-></td>
|
195
|
+
<td class="context-item-value">check_fulfills?</td>
|
196
|
+
</tr>
|
197
|
+
<tr class="top-aligned-row context-row">
|
198
|
+
<td class="context-item-name">fulfilled_by?</td>
|
199
|
+
<td>-></td>
|
200
|
+
<td class="context-item-value">===</td>
|
201
|
+
</tr>
|
202
|
+
<tr class="top-aligned-row context-row">
|
203
|
+
<td> </td>
|
204
|
+
<td colspan="2" class="context-item-desc">
|
205
|
+
You can use contracts in <tt>case</tt> … <tt>when</tt> statements or
|
206
|
+
in <a href="Module.html#M000015">Module#signature</a> checks. For example:
|
207
|
+
|
208
|
+
<pre>
|
209
|
+
case obj
|
210
|
+
when Numeric then obj + 1
|
211
|
+
when ListContract then obj + [1]
|
212
|
+
end
|
213
|
+
</pre>
|
214
|
+
</td>
|
215
|
+
</tr>
|
216
|
+
</table>
|
217
|
+
</div>
|
218
|
+
</div>
|
219
|
+
|
220
|
+
|
221
|
+
<div id="attribute-list">
|
222
|
+
<h3 class="section-bar">Attributes</h3>
|
223
|
+
|
224
|
+
<div class="name-list">
|
225
|
+
<table>
|
226
|
+
<tr class="top-aligned-row context-row">
|
227
|
+
<td class="context-item-name">check_fulfills</td>
|
228
|
+
<td class="context-item-value"> [RW] </td>
|
229
|
+
<td class="context-item-desc">
|
230
|
+
Whether fulfills should be checked. This is enabled by default.
|
231
|
+
|
232
|
+
<p>
|
233
|
+
Note: If you want to change this you need to do so before doing any <a
|
234
|
+
href="Module.html#M000016">Module#fulfills</a> calls or it will not be
|
235
|
+
applied. It’s probably best set right after requiring the contract
|
236
|
+
library.
|
237
|
+
</p>
|
238
|
+
</td>
|
239
|
+
</tr>
|
240
|
+
<tr class="top-aligned-row context-row">
|
241
|
+
<td class="context-item-name">check_signatures</td>
|
242
|
+
<td class="context-item-value"> [RW] </td>
|
243
|
+
<td class="context-item-desc">
|
244
|
+
Whether signatures should be checked. By default signatures are checked
|
245
|
+
only when the application is run in $DEBUG mode. (By specifying the -d
|
246
|
+
switch on the invocation of Ruby.)
|
247
|
+
|
248
|
+
<p>
|
249
|
+
Note: If you want to change this you need to do so before doing any <a
|
250
|
+
href="Module.html#M000015">Module#signature</a> calls or it will not be
|
251
|
+
applied. It’s probably best set right after requiring the contract
|
252
|
+
library.
|
253
|
+
</p>
|
254
|
+
</td>
|
255
|
+
</tr>
|
256
|
+
<tr class="top-aligned-row context-row">
|
257
|
+
<td class="context-item-name">implications</td>
|
258
|
+
<td class="context-item-value"> [R] </td>
|
259
|
+
<td class="context-item-desc">
|
260
|
+
Returns all implications of a given contract that were stated via calling
|
261
|
+
<a href="Contract.html#M000008">Contract.implies</a>.
|
262
|
+
|
263
|
+
</td>
|
264
|
+
</tr>
|
265
|
+
</table>
|
266
|
+
</div>
|
267
|
+
</div>
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
<!-- if method_list -->
|
272
|
+
<div id="methods">
|
273
|
+
<h3 class="section-bar">Public Class methods</h3>
|
274
|
+
|
275
|
+
<div id="method-M000002" class="method-detail">
|
276
|
+
<a name="M000002"></a>
|
277
|
+
|
278
|
+
<div class="method-heading">
|
279
|
+
<a href="#M000002" class="method-signature">
|
280
|
+
<span class="method-name">adapt</span><span class="method-args">(object, type)</span>
|
281
|
+
</a>
|
282
|
+
</div>
|
283
|
+
|
284
|
+
<div class="method-description">
|
285
|
+
<p>
|
286
|
+
Tries to adapt the specified object to the specified type. Returns the old
|
287
|
+
object if no suitable adaption route was found or if it already is of the
|
288
|
+
specified type.
|
289
|
+
</p>
|
290
|
+
<p>
|
291
|
+
This will only use adaptions where the :to part is equal to the specified
|
292
|
+
type. No multi-step conversion will be performed.
|
293
|
+
</p>
|
294
|
+
<p><a class="source-toggle" href="#"
|
295
|
+
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
296
|
+
<div class="method-source-code" id="M000002-source">
|
297
|
+
<pre>
|
298
|
+
<span class="ruby-comment cmt"># File lib/contract/integration.rb, line 124</span>
|
299
|
+
124: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">adapt</span>(<span class="ruby-identifier">object</span>, <span class="ruby-identifier">type</span>)
|
300
|
+
125: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">object</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">object</span>
|
301
|
+
126:
|
302
|
+
127: <span class="ruby-ivar">@adaptions</span>[<span class="ruby-identifier">type</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">adaption</span><span class="ruby-operator">|</span>
|
303
|
+
128: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">adaption</span>[<span class="ruby-identifier">:from</span>] <span class="ruby-operator">===</span> <span class="ruby-identifier">object</span> <span class="ruby-keyword kw">and</span>
|
304
|
+
129: (<span class="ruby-identifier">adaption</span>[<span class="ruby-identifier">:if</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">adaption</span>[<span class="ruby-identifier">:if</span>] <span class="ruby-operator">===</span> <span class="ruby-identifier">object</span>)
|
305
|
+
130: <span class="ruby-keyword kw">then</span>
|
306
|
+
131: <span class="ruby-identifier">result</span> = <span class="ruby-identifier">adaption</span>[<span class="ruby-identifier">:via</span>].<span class="ruby-identifier">call</span>(<span class="ruby-identifier">object</span>)
|
307
|
+
132: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">result</span>
|
308
|
+
133: <span class="ruby-keyword kw">end</span>
|
309
|
+
134: <span class="ruby-keyword kw">end</span>
|
310
|
+
135:
|
311
|
+
136: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">object</span>
|
312
|
+
137: <span class="ruby-keyword kw">end</span>
|
313
|
+
</pre>
|
314
|
+
</div>
|
315
|
+
</div>
|
316
|
+
</div>
|
317
|
+
|
318
|
+
<div id="method-M000007" class="method-detail">
|
319
|
+
<a name="M000007"></a>
|
320
|
+
|
321
|
+
<div class="method-heading">
|
322
|
+
<a href="#M000007" class="method-signature">
|
323
|
+
<span class="method-name">deep_copy</span><span class="method-args">(object)</span>
|
324
|
+
</a>
|
325
|
+
</div>
|
326
|
+
|
327
|
+
<div class="method-description">
|
328
|
+
<p>
|
329
|
+
This method is used internally for getting a copy of Objects that the
|
330
|
+
contract is checked against. By default it uses Ruby’s
|
331
|
+
<tt>Marshal</tt> functionality for obtaining a copy, but this can fail if
|
332
|
+
the Object contains unserializable parts like Procs, Files or Sockets. It
|
333
|
+
is currently your responsibility to provide a fitting implementation of
|
334
|
+
this by overwriting the method in case the default implementation does not
|
335
|
+
work for you. In the future the contract library might offer different
|
336
|
+
implementations for this via Ruby’s mixin mechanism.
|
337
|
+
</p>
|
338
|
+
<p><a class="source-toggle" href="#"
|
339
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
340
|
+
<div class="method-source-code" id="M000007-source">
|
341
|
+
<pre>
|
342
|
+
<span class="ruby-comment cmt"># File lib/contract.rb, line 104</span>
|
343
|
+
104: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">deep_copy</span>(<span class="ruby-identifier">object</span>)
|
344
|
+
105: <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">object</span>))
|
345
|
+
106: <span class="ruby-keyword kw">end</span>
|
346
|
+
</pre>
|
347
|
+
</div>
|
348
|
+
</div>
|
349
|
+
</div>
|
350
|
+
|
351
|
+
<div id="method-M000004" class="method-detail">
|
352
|
+
<a name="M000004"></a>
|
353
|
+
|
354
|
+
<div class="method-heading">
|
355
|
+
<a href="#M000004" class="method-signature">
|
356
|
+
<span class="method-name">enforce</span><span class="method-args">(object)</span>
|
357
|
+
</a>
|
358
|
+
</div>
|
359
|
+
|
360
|
+
<div class="method-description">
|
361
|
+
<p>
|
362
|
+
Enforces that object implements this contract. If it does not an Exception
|
363
|
+
will be raised. This is useful for example useful when you need to ensure
|
364
|
+
that the arguments given to a method fulfill a given contract.
|
365
|
+
</p>
|
366
|
+
<p>
|
367
|
+
Note that using Module#enforce is a higher-level way of checking arguments
|
368
|
+
and return values for the conformance of a given type. You might however
|
369
|
+
still want to use <a href="Contract.html#M000004">Contract.enforce</a>
|
370
|
+
directly when you need more flexibility.
|
371
|
+
</p>
|
372
|
+
<p><a class="source-toggle" href="#"
|
373
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
374
|
+
<div class="method-source-code" id="M000004-source">
|
375
|
+
<pre>
|
376
|
+
<span class="ruby-comment cmt"># File lib/contract.rb, line 65</span>
|
377
|
+
65: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">enforce</span>(<span class="ruby-identifier">object</span>)
|
378
|
+
66: <span class="ruby-identifier">reason</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">test</span>(<span class="ruby-identifier">object</span>)
|
379
|
+
67: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">reason</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">reason</span>
|
380
|
+
68: <span class="ruby-keyword kw">end</span>
|
381
|
+
</pre>
|
382
|
+
</div>
|
383
|
+
</div>
|
384
|
+
</div>
|
385
|
+
|
386
|
+
<div id="method-M000003" class="method-detail">
|
387
|
+
<a name="M000003"></a>
|
388
|
+
|
389
|
+
<div class="method-heading">
|
390
|
+
<a href="#M000003" class="method-signature">
|
391
|
+
<span class="method-name">fulfilled_by?</span><span class="method-args">(object)</span>
|
392
|
+
</a>
|
393
|
+
</div>
|
394
|
+
|
395
|
+
<div class="method-description">
|
396
|
+
<p>
|
397
|
+
Returns true if the given object fulfills this contract. This is useful for
|
398
|
+
implementing dispatching mechanisms where you want to hit different code
|
399
|
+
branches based on whether an Object has one or another interface.
|
400
|
+
</p>
|
401
|
+
<p><a class="source-toggle" href="#"
|
402
|
+
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
403
|
+
<div class="method-source-code" id="M000003-source">
|
404
|
+
<pre>
|
405
|
+
<span class="ruby-comment cmt"># File lib/contract.rb, line 42</span>
|
406
|
+
42: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">fulfilled_by?</span>(<span class="ruby-identifier">object</span>)
|
407
|
+
43: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">test</span>(<span class="ruby-identifier">object</span>).<span class="ruby-identifier">nil?</span>
|
408
|
+
44: <span class="ruby-keyword kw">end</span>
|
409
|
+
</pre>
|
410
|
+
</div>
|
411
|
+
</div>
|
412
|
+
</div>
|
413
|
+
|
414
|
+
<div id="method-M000008" class="method-detail">
|
415
|
+
<a name="M000008"></a>
|
416
|
+
|
417
|
+
<div class="method-heading">
|
418
|
+
<a href="#M000008" class="method-signature">
|
419
|
+
<span class="method-name">implies</span><span class="method-args">(*mixins)</span>
|
420
|
+
</a>
|
421
|
+
</div>
|
422
|
+
|
423
|
+
<div class="method-description">
|
424
|
+
<p>
|
425
|
+
Fulfilling this <a href="Contract.html">Contract</a> (via <a
|
426
|
+
href="Module.html#M000016">Module#fulfills</a>) implies that the Object is
|
427
|
+
automatically compatible with the specified mixins which will then be
|
428
|
+
included automatically. For example the Enumerable relationship could be
|
429
|
+
expressed like this:
|
430
|
+
</p>
|
431
|
+
<pre>
|
432
|
+
class EnumerableContract < Contract
|
433
|
+
provides :each
|
434
|
+
implies Enumerable
|
435
|
+
end
|
436
|
+
</pre>
|
437
|
+
<p><a class="source-toggle" href="#"
|
438
|
+
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
439
|
+
<div class="method-source-code" id="M000008-source">
|
440
|
+
<pre>
|
441
|
+
<span class="ruby-comment cmt"># File lib/contract.rb, line 117</span>
|
442
|
+
117: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">implies</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">mixins</span>)
|
443
|
+
118: <span class="ruby-identifier">mixins</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mixin</span><span class="ruby-operator">|</span>
|
444
|
+
119: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">mixin</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Module</span>) <span class="ruby-keyword kw">then</span>
|
445
|
+
120: <span class="ruby-identifier">raise</span>(<span class="ruby-constant">TypeError</span>, <span class="ruby-node">"wrong argument type #{mixin.class} for "</span> <span class="ruby-operator">+</span>
|
446
|
+
121: <span class="ruby-node">"#{mixin.inspect} (expected Module)"</span>)
|
447
|
+
122: <span class="ruby-keyword kw">end</span>
|
448
|
+
123: <span class="ruby-keyword kw">end</span>
|
449
|
+
124:
|
450
|
+
125: <span class="ruby-ivar">@implications</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
|
451
|
+
126: <span class="ruby-ivar">@implications</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">mixins</span>
|
452
|
+
127: <span class="ruby-keyword kw">end</span>
|
453
|
+
</pre>
|
454
|
+
</div>
|
455
|
+
</div>
|
456
|
+
</div>
|
457
|
+
|
458
|
+
<div id="method-M000001" class="method-detail">
|
459
|
+
<a name="M000001"></a>
|
460
|
+
|
461
|
+
<div class="method-heading">
|
462
|
+
<a href="#M000001" class="method-signature">
|
463
|
+
<span class="method-name">provides</span><span class="method-args">(*symbols) {|| ...}</span>
|
464
|
+
</a>
|
465
|
+
</div>
|
466
|
+
|
467
|
+
<div class="method-description">
|
468
|
+
<p>
|
469
|
+
Tests that the tested Object provides the specified methods with the
|
470
|
+
specified behavior.
|
471
|
+
</p>
|
472
|
+
<p>
|
473
|
+
If a block is supplied it will be evaluated in the context of the contract
|
474
|
+
so <tt>@object</tt> will refer to the object being tested.
|
475
|
+
</p>
|
476
|
+
<p>
|
477
|
+
This can be used like this:
|
478
|
+
</p>
|
479
|
+
<pre>
|
480
|
+
class ListContract < Contract
|
481
|
+
provides :size do
|
482
|
+
assert(@object.size >= 0, "#size should never be negative.")
|
483
|
+
end
|
484
|
+
|
485
|
+
provides :include?
|
486
|
+
|
487
|
+
provides :each do
|
488
|
+
count = 0
|
489
|
+
@object.each do |item|
|
490
|
+
assert(@object.include?(item),
|
491
|
+
"#each should only yield items that the list includes.")
|
492
|
+
count += 1
|
493
|
+
end
|
494
|
+
assert_equal(@object.size, count,
|
495
|
+
"#each should yield #size items.")
|
496
|
+
end
|
497
|
+
end
|
498
|
+
</pre>
|
499
|
+
<p><a class="source-toggle" href="#"
|
500
|
+
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
501
|
+
<div class="method-source-code" id="M000001-source">
|
502
|
+
<pre>
|
503
|
+
<span class="ruby-comment cmt"># File lib/contract/assertions.rb, line 34</span>
|
504
|
+
34: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">provides</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>) <span class="ruby-comment cmt"># :yields:</span>
|
505
|
+
35: <span class="ruby-identifier">symbols</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">symbol</span><span class="ruby-operator">|</span>
|
506
|
+
36: <span class="ruby-identifier">define_method</span>(<span class="ruby-node">"test_provides_#{symbol}"</span>.<span class="ruby-identifier">intern</span>) <span class="ruby-keyword kw">do</span>
|
507
|
+
37: <span class="ruby-identifier">assert_respond_to</span>(<span class="ruby-ivar">@object</span>, <span class="ruby-identifier">symbol</span>)
|
508
|
+
38: <span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
|
509
|
+
39: <span class="ruby-keyword kw">end</span>
|
510
|
+
40: <span class="ruby-keyword kw">end</span>
|
511
|
+
41: <span class="ruby-keyword kw">end</span>
|
512
|
+
</pre>
|
513
|
+
</div>
|
514
|
+
</div>
|
515
|
+
</div>
|
516
|
+
|
517
|
+
<div id="method-M000005" class="method-detail">
|
518
|
+
<a name="M000005"></a>
|
519
|
+
|
520
|
+
<div class="method-heading">
|
521
|
+
<a href="#M000005" class="method-signature">
|
522
|
+
<span class="method-name">test</span><span class="method-args">(object, return_all = false)</span>
|
523
|
+
</a>
|
524
|
+
</div>
|
525
|
+
|
526
|
+
<div class="method-description">
|
527
|
+
<p>
|
528
|
+
Tests whether the given Object fulfils this contract.
|
529
|
+
</p>
|
530
|
+
<p>
|
531
|
+
Note: This will return the first reason for the Object not fulfilling the
|
532
|
+
contract or <tt>nil</tt> in case it fulfills it.
|
533
|
+
</p>
|
534
|
+
<p><a class="source-toggle" href="#"
|
535
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
536
|
+
<div class="method-source-code" id="M000005-source">
|
537
|
+
<pre>
|
538
|
+
<span class="ruby-comment cmt"># File lib/contract.rb, line 74</span>
|
539
|
+
74: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">test</span>(<span class="ruby-identifier">object</span>, <span class="ruby-identifier">return_all</span> = <span class="ruby-keyword kw">false</span>)
|
540
|
+
75: <span class="ruby-identifier">reasons</span> = []
|
541
|
+
76:
|
542
|
+
77: <span class="ruby-identifier">result</span> = <span class="ruby-constant">Test</span><span class="ruby-operator">::</span><span class="ruby-constant">Unit</span><span class="ruby-operator">::</span><span class="ruby-constant">TestResult</span>.<span class="ruby-identifier">new</span>
|
543
|
+
78: <span class="ruby-identifier">result</span>.<span class="ruby-identifier">add_listener</span>(<span class="ruby-constant">Test</span><span class="ruby-operator">::</span><span class="ruby-constant">Unit</span><span class="ruby-operator">::</span><span class="ruby-constant">TestResult</span><span class="ruby-operator">::</span><span class="ruby-constant">FAULT</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">fault</span><span class="ruby-operator">|</span>
|
544
|
+
79: <span class="ruby-identifier">reason</span> = <span class="ruby-constant">Contract</span>.<span class="ruby-identifier">fault_to_exception</span>(<span class="ruby-identifier">fault</span>, <span class="ruby-identifier">object</span>, <span class="ruby-keyword kw">self</span>)
|
545
|
+
80: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">reason</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">return_all</span>
|
546
|
+
81: <span class="ruby-identifier">reasons</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">reason</span>
|
547
|
+
82: <span class="ruby-keyword kw">end</span>
|
548
|
+
83:
|
549
|
+
84: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">suite</span>.<span class="ruby-identifier">run</span>(<span class="ruby-identifier">result</span>, <span class="ruby-identifier">deep_copy</span>(<span class="ruby-identifier">object</span>))
|
550
|
+
85:
|
551
|
+
86: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">reasons</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">passed?</span>
|
552
|
+
87: <span class="ruby-keyword kw">end</span>
|
553
|
+
</pre>
|
554
|
+
</div>
|
555
|
+
</div>
|
556
|
+
</div>
|
557
|
+
|
558
|
+
<div id="method-M000006" class="method-detail">
|
559
|
+
<a name="M000006"></a>
|
560
|
+
|
561
|
+
<div class="method-heading">
|
562
|
+
<a href="#M000006" class="method-signature">
|
563
|
+
<span class="method-name">test_all</span><span class="method-args">(object)</span>
|
564
|
+
</a>
|
565
|
+
</div>
|
566
|
+
|
567
|
+
<div class="method-description">
|
568
|
+
<p>
|
569
|
+
Same as <a href="Contract.html#M000005">Contract.test</a>, but will return
|
570
|
+
all reasons for the Object not fulfilling the contract in an Array or nil
|
571
|
+
in case of fulfillment. (as an Array of Exceptions) or <tt>nil</tt> in the
|
572
|
+
case it does fulfill it.
|
573
|
+
</p>
|
574
|
+
<p><a class="source-toggle" href="#"
|
575
|
+
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
576
|
+
<div class="method-source-code" id="M000006-source">
|
577
|
+
<pre>
|
578
|
+
<span class="ruby-comment cmt"># File lib/contract.rb, line 92</span>
|
579
|
+
92: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">test_all</span>(<span class="ruby-identifier">object</span>)
|
580
|
+
93: <span class="ruby-identifier">test</span>(<span class="ruby-identifier">object</span>, <span class="ruby-keyword kw">true</span>)
|
581
|
+
94: <span class="ruby-keyword kw">end</span>
|
582
|
+
</pre>
|
583
|
+
</div>
|
584
|
+
</div>
|
585
|
+
</div>
|
586
|
+
|
587
|
+
|
588
|
+
</div>
|
589
|
+
|
590
|
+
|
591
|
+
</div>
|
592
|
+
|
593
|
+
|
594
|
+
<div id="validator-badges">
|
595
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
596
|
+
</div>
|
597
|
+
|
598
|
+
</body>
|
599
|
+
</html>
|