ruby_contracts 0.3.0 → 0.3.1
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/lib/ruby_contracts/dsl.rb
CHANGED
@@ -60,23 +60,16 @@ module Contracts
|
|
60
60
|
__contracts = __contracts_for(name.to_s, @__contracts)
|
61
61
|
@__contracts = Contracts::List.new
|
62
62
|
|
63
|
-
if !__contracts.empty?
|
63
|
+
if !__contracts.first.empty?
|
64
64
|
@__skip_other_contracts_definitions = true
|
65
|
-
|
66
|
-
define_method(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
self.class.__eval_after_contracts("#{name}", self, __args, result)
|
74
|
-
return result
|
75
|
-
end
|
76
|
-
EOM
|
77
|
-
|
78
|
-
class_eval method
|
79
|
-
|
65
|
+
original_method = instance_method(name)
|
66
|
+
define_method(name) do |*args, &block|
|
67
|
+
__args = block.nil? ? args : args + [block]
|
68
|
+
self.class.__eval_before_contracts(name.to_s, self, __args)
|
69
|
+
result = original_method.bind(self).(*args, &block)
|
70
|
+
self.class.__eval_after_contracts(name.to_s, self, __args, result)
|
71
|
+
return result
|
72
|
+
end
|
80
73
|
@__skip_other_contracts_definitions = false
|
81
74
|
end
|
82
75
|
end
|
@@ -15,11 +15,11 @@ class Parent
|
|
15
15
|
pre "n > minimum_incr" do |n| n > minimum_incr end
|
16
16
|
post "value == old value + n" do "[dummy]" end
|
17
17
|
def increment(n)
|
18
|
-
value += n
|
18
|
+
@value += n
|
19
19
|
end
|
20
20
|
|
21
21
|
def to_s
|
22
|
-
value.to_s
|
22
|
+
@value.to_s
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -35,3 +35,9 @@ class ChildWithAddedPrecondition < Parent
|
|
35
35
|
@value += n
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
class ChildWithSuper < Parent
|
40
|
+
def increment(n)
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
data/test/inheritance_test.rb
CHANGED
@@ -46,5 +46,13 @@ describe 'the contracts behavior in an inheritance context' do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
describe 'the super keyword usage' do
|
51
|
+
let(:child) { ChildWithSuper.new(10, 3) }
|
52
|
+
|
53
|
+
it 'does not raise any error' do
|
54
|
+
child.increment(5).wont_be_nil
|
55
|
+
end
|
56
|
+
end
|
49
57
|
end
|
50
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_contracts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Micro DSL to add pre & post condition to methods. It tries to bring some
|
15
15
|
design by contract in the Ruby world.
|