handshake 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +1 -0
- data/README.txt +3 -0
- data/lib/handshake/version.rb +2 -2
- data/lib/handshake.rb +4 -0
- data/test/tc_disable_handshake.rb +29 -0
- data/test/tc_handshake.rb +2 -22
- metadata +4 -2
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -5,6 +5,9 @@ It's intended to allow Ruby developers to apply simple, clear constraints
|
|
5
5
|
to their methods and classes. Handshake is written by Brian Guthrie
|
6
6
|
(btguthrie@gmail.com) and lives at http://handshake.rubyforge.org.
|
7
7
|
|
8
|
+
Contracts defined with Handshake are not enforced unless the global $DEBUG
|
9
|
+
flag is set.
|
10
|
+
|
8
11
|
=== Features
|
9
12
|
|
10
13
|
* Method signature contracts
|
data/lib/handshake/version.rb
CHANGED
data/lib/handshake.rb
CHANGED
@@ -46,6 +46,10 @@ module Handshake
|
|
46
46
|
base.class_inheritable_hash :method_contracts
|
47
47
|
base.write_inheritable_hash :method_contracts, {}
|
48
48
|
|
49
|
+
# No contracts will ever be checked if we return now, so it's a good place
|
50
|
+
# to put the $DEBUG flag check.
|
51
|
+
return unless $DEBUG
|
52
|
+
|
49
53
|
class << base
|
50
54
|
alias :instantiate :new
|
51
55
|
# Override the class-level new method of every class that includes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'handshake'
|
3
|
+
|
4
|
+
# The purpose of this test case is to ensure that when the $DEBUG flag is not
|
5
|
+
# set contracts may still be declared without raising a syntax error, although
|
6
|
+
# they are not enforced.
|
7
|
+
class TestDisableHandshake < Test::Unit::TestCase
|
8
|
+
|
9
|
+
class ComprehensiveContracts
|
10
|
+
include Handshake
|
11
|
+
|
12
|
+
invariant("foo must always be true") { @foo == true }
|
13
|
+
|
14
|
+
contract /foo/ => /bar/
|
15
|
+
before do |arg|
|
16
|
+
assert_equal "foo", arg
|
17
|
+
end
|
18
|
+
after do |arg, returned|
|
19
|
+
assert_equal "bar", returned
|
20
|
+
end
|
21
|
+
def call(str); "baz"; end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_contracts_not_enforced
|
25
|
+
assert_nothing_raised { ComprehensiveContracts.new }
|
26
|
+
assert_nothing_raised { ComprehensiveContracts.new.call 3 }
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/test/tc_handshake.rb
CHANGED
@@ -1,28 +1,8 @@
|
|
1
|
-
# test_handshake.rb
|
2
|
-
# Copyright (c) 2007 Brian Guthrie
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
# a copy of this software and associated documentation files (the
|
6
|
-
# "Software"), to deal in the Software without restriction, including
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
# the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be
|
13
|
-
# included in all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
|
23
1
|
require 'test/unit'
|
24
2
|
require 'handshake'
|
25
3
|
|
4
|
+
$DEBUG = true
|
5
|
+
|
26
6
|
class TestContract < Test::Unit::TestCase
|
27
7
|
|
28
8
|
class InvariantDeclarations
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: handshake
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-05-
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2007-05-03 00:00:00 -04:00
|
8
8
|
summary: Handshake is a simple design-by-contract system for Ruby.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -40,7 +40,9 @@ files:
|
|
40
40
|
- lib/handshake/proxy_self.rb
|
41
41
|
- lib/handshake/version.rb
|
42
42
|
- test/tc_handshake.rb
|
43
|
+
- test/tc_disable_handshake.rb
|
43
44
|
test_files:
|
45
|
+
- test/tc_disable_handshake.rb
|
44
46
|
- test/tc_handshake.rb
|
45
47
|
rdoc_options: []
|
46
48
|
|