entitlements 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/deploy-entitlements +10 -1
  4. data/lib/contracts-ruby2/CHANGELOG.markdown +115 -0
  5. data/lib/contracts-ruby2/Gemfile +17 -0
  6. data/lib/contracts-ruby2/LICENSE +23 -0
  7. data/lib/contracts-ruby2/README.md +108 -0
  8. data/lib/contracts-ruby2/Rakefile +8 -0
  9. data/lib/contracts-ruby2/TODO.markdown +6 -0
  10. data/lib/contracts-ruby2/TUTORIAL.md +773 -0
  11. data/lib/contracts-ruby2/benchmarks/bench.rb +67 -0
  12. data/lib/contracts-ruby2/benchmarks/hash.rb +69 -0
  13. data/lib/contracts-ruby2/benchmarks/invariants.rb +91 -0
  14. data/lib/contracts-ruby2/benchmarks/io.rb +62 -0
  15. data/lib/contracts-ruby2/benchmarks/wrap_test.rb +57 -0
  16. data/lib/contracts-ruby2/contracts.gemspec +17 -0
  17. data/lib/contracts-ruby2/cucumber.yml +1 -0
  18. data/lib/contracts-ruby2/dependabot.yml +20 -0
  19. data/lib/contracts-ruby2/features/README.md +17 -0
  20. data/lib/contracts-ruby2/features/basics/functype.feature +71 -0
  21. data/lib/contracts-ruby2/features/basics/pretty-print.feature +241 -0
  22. data/lib/contracts-ruby2/features/basics/simple_example.feature +210 -0
  23. data/lib/contracts-ruby2/features/builtin_contracts/README.md +22 -0
  24. data/lib/contracts-ruby2/features/builtin_contracts/and.feature +103 -0
  25. data/lib/contracts-ruby2/features/builtin_contracts/any.feature +44 -0
  26. data/lib/contracts-ruby2/features/builtin_contracts/args.feature +80 -0
  27. data/lib/contracts-ruby2/features/builtin_contracts/array_of.feature +1 -0
  28. data/lib/contracts-ruby2/features/builtin_contracts/bool.feature +64 -0
  29. data/lib/contracts-ruby2/features/builtin_contracts/enum.feature +1 -0
  30. data/lib/contracts-ruby2/features/builtin_contracts/eq.feature +1 -0
  31. data/lib/contracts-ruby2/features/builtin_contracts/exactly.feature +1 -0
  32. data/lib/contracts-ruby2/features/builtin_contracts/func.feature +1 -0
  33. data/lib/contracts-ruby2/features/builtin_contracts/hash_of.feature +1 -0
  34. data/lib/contracts-ruby2/features/builtin_contracts/int.feature +93 -0
  35. data/lib/contracts-ruby2/features/builtin_contracts/keyword_args.feature +1 -0
  36. data/lib/contracts-ruby2/features/builtin_contracts/maybe.feature +1 -0
  37. data/lib/contracts-ruby2/features/builtin_contracts/nat.feature +115 -0
  38. data/lib/contracts-ruby2/features/builtin_contracts/nat_pos.feature +119 -0
  39. data/lib/contracts-ruby2/features/builtin_contracts/neg.feature +115 -0
  40. data/lib/contracts-ruby2/features/builtin_contracts/none.feature +145 -0
  41. data/lib/contracts-ruby2/features/builtin_contracts/not.feature +1 -0
  42. data/lib/contracts-ruby2/features/builtin_contracts/num.feature +64 -0
  43. data/lib/contracts-ruby2/features/builtin_contracts/or.feature +83 -0
  44. data/lib/contracts-ruby2/features/builtin_contracts/pos.feature +116 -0
  45. data/lib/contracts-ruby2/features/builtin_contracts/range_of.feature +1 -0
  46. data/lib/contracts-ruby2/features/builtin_contracts/respond_to.feature +78 -0
  47. data/lib/contracts-ruby2/features/builtin_contracts/send.feature +147 -0
  48. data/lib/contracts-ruby2/features/builtin_contracts/set_of.feature +1 -0
  49. data/lib/contracts-ruby2/features/builtin_contracts/xor.feature +99 -0
  50. data/lib/contracts-ruby2/features/support/env.rb +6 -0
  51. data/lib/contracts-ruby2/lib/contracts/attrs.rb +24 -0
  52. data/lib/contracts-ruby2/lib/contracts/builtin_contracts.rb +542 -0
  53. data/lib/contracts-ruby2/lib/contracts/call_with.rb +108 -0
  54. data/lib/contracts-ruby2/lib/contracts/core.rb +52 -0
  55. data/lib/contracts-ruby2/lib/contracts/decorators.rb +47 -0
  56. data/lib/contracts-ruby2/lib/contracts/engine/base.rb +136 -0
  57. data/lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb +50 -0
  58. data/lib/contracts-ruby2/lib/contracts/engine/target.rb +70 -0
  59. data/lib/contracts-ruby2/lib/contracts/engine.rb +26 -0
  60. data/lib/contracts-ruby2/lib/contracts/errors.rb +71 -0
  61. data/lib/contracts-ruby2/lib/contracts/formatters.rb +136 -0
  62. data/lib/contracts-ruby2/lib/contracts/invariants.rb +68 -0
  63. data/lib/contracts-ruby2/lib/contracts/method_handler.rb +187 -0
  64. data/lib/contracts-ruby2/lib/contracts/method_reference.rb +100 -0
  65. data/lib/contracts-ruby2/lib/contracts/support.rb +61 -0
  66. data/lib/contracts-ruby2/lib/contracts/validators.rb +139 -0
  67. data/lib/contracts-ruby2/lib/contracts/version.rb +3 -0
  68. data/lib/contracts-ruby2/lib/contracts.rb +281 -0
  69. data/lib/contracts-ruby2/script/docs-release +3 -0
  70. data/lib/contracts-ruby2/script/docs-staging +3 -0
  71. data/lib/contracts-ruby2/script/rubocop.rb +5 -0
  72. data/lib/contracts-ruby2/spec/attrs_spec.rb +119 -0
  73. data/lib/contracts-ruby2/spec/builtin_contracts_spec.rb +461 -0
  74. data/lib/contracts-ruby2/spec/contracts_spec.rb +770 -0
  75. data/lib/contracts-ruby2/spec/fixtures/fixtures.rb +730 -0
  76. data/lib/contracts-ruby2/spec/invariants_spec.rb +17 -0
  77. data/lib/contracts-ruby2/spec/methods_spec.rb +54 -0
  78. data/lib/contracts-ruby2/spec/module_spec.rb +18 -0
  79. data/lib/contracts-ruby2/spec/override_validators_spec.rb +162 -0
  80. data/lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_1.9.rb +24 -0
  81. data/lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_2.0.rb +55 -0
  82. data/lib/contracts-ruby2/spec/ruby_version_specific/contracts_spec_2.1.rb +63 -0
  83. data/lib/contracts-ruby2/spec/spec_helper.rb +102 -0
  84. data/lib/contracts-ruby2/spec/support.rb +10 -0
  85. data/lib/contracts-ruby2/spec/support_spec.rb +21 -0
  86. data/lib/contracts-ruby2/spec/validators_spec.rb +47 -0
  87. data/lib/contracts-ruby3/CHANGELOG.markdown +117 -0
  88. data/lib/contracts-ruby3/Gemfile +21 -0
  89. data/lib/contracts-ruby3/LICENSE +23 -0
  90. data/lib/contracts-ruby3/README.md +114 -0
  91. data/lib/contracts-ruby3/Rakefile +10 -0
  92. data/lib/contracts-ruby3/TODO.markdown +6 -0
  93. data/lib/contracts-ruby3/TUTORIAL.md +773 -0
  94. data/lib/contracts-ruby3/benchmarks/bench.rb +67 -0
  95. data/lib/contracts-ruby3/benchmarks/hash.rb +69 -0
  96. data/lib/contracts-ruby3/benchmarks/invariants.rb +91 -0
  97. data/lib/contracts-ruby3/benchmarks/io.rb +62 -0
  98. data/lib/contracts-ruby3/benchmarks/wrap_test.rb +57 -0
  99. data/lib/contracts-ruby3/contracts.gemspec +20 -0
  100. data/lib/contracts-ruby3/cucumber.yml +1 -0
  101. data/lib/contracts-ruby3/dependabot.yml +20 -0
  102. data/lib/contracts-ruby3/features/README.md +17 -0
  103. data/lib/contracts-ruby3/features/basics/functype.feature +71 -0
  104. data/lib/contracts-ruby3/features/basics/pretty-print.feature +241 -0
  105. data/lib/contracts-ruby3/features/basics/simple_example.feature +210 -0
  106. data/lib/contracts-ruby3/features/builtin_contracts/README.md +22 -0
  107. data/lib/contracts-ruby3/features/builtin_contracts/and.feature +103 -0
  108. data/lib/contracts-ruby3/features/builtin_contracts/any.feature +44 -0
  109. data/lib/contracts-ruby3/features/builtin_contracts/args.feature +80 -0
  110. data/lib/contracts-ruby3/features/builtin_contracts/array_of.feature +1 -0
  111. data/lib/contracts-ruby3/features/builtin_contracts/bool.feature +64 -0
  112. data/lib/contracts-ruby3/features/builtin_contracts/enum.feature +1 -0
  113. data/lib/contracts-ruby3/features/builtin_contracts/eq.feature +1 -0
  114. data/lib/contracts-ruby3/features/builtin_contracts/exactly.feature +1 -0
  115. data/lib/contracts-ruby3/features/builtin_contracts/func.feature +1 -0
  116. data/lib/contracts-ruby3/features/builtin_contracts/hash_of.feature +1 -0
  117. data/lib/contracts-ruby3/features/builtin_contracts/int.feature +93 -0
  118. data/lib/contracts-ruby3/features/builtin_contracts/keyword_args.feature +1 -0
  119. data/lib/contracts-ruby3/features/builtin_contracts/maybe.feature +1 -0
  120. data/lib/contracts-ruby3/features/builtin_contracts/nat.feature +115 -0
  121. data/lib/contracts-ruby3/features/builtin_contracts/nat_pos.feature +119 -0
  122. data/lib/contracts-ruby3/features/builtin_contracts/neg.feature +115 -0
  123. data/lib/contracts-ruby3/features/builtin_contracts/none.feature +145 -0
  124. data/lib/contracts-ruby3/features/builtin_contracts/not.feature +1 -0
  125. data/lib/contracts-ruby3/features/builtin_contracts/num.feature +64 -0
  126. data/lib/contracts-ruby3/features/builtin_contracts/or.feature +83 -0
  127. data/lib/contracts-ruby3/features/builtin_contracts/pos.feature +116 -0
  128. data/lib/contracts-ruby3/features/builtin_contracts/range_of.feature +1 -0
  129. data/lib/contracts-ruby3/features/builtin_contracts/respond_to.feature +78 -0
  130. data/lib/contracts-ruby3/features/builtin_contracts/send.feature +147 -0
  131. data/lib/contracts-ruby3/features/builtin_contracts/set_of.feature +1 -0
  132. data/lib/contracts-ruby3/features/builtin_contracts/xor.feature +99 -0
  133. data/lib/contracts-ruby3/features/support/env.rb +8 -0
  134. data/lib/contracts-ruby3/lib/contracts/attrs.rb +26 -0
  135. data/lib/contracts-ruby3/lib/contracts/builtin_contracts.rb +575 -0
  136. data/lib/contracts-ruby3/lib/contracts/call_with.rb +119 -0
  137. data/lib/contracts-ruby3/lib/contracts/core.rb +54 -0
  138. data/lib/contracts-ruby3/lib/contracts/decorators.rb +50 -0
  139. data/lib/contracts-ruby3/lib/contracts/engine/base.rb +137 -0
  140. data/lib/contracts-ruby3/lib/contracts/engine/eigenclass.rb +51 -0
  141. data/lib/contracts-ruby3/lib/contracts/engine/target.rb +72 -0
  142. data/lib/contracts-ruby3/lib/contracts/engine.rb +28 -0
  143. data/lib/contracts-ruby3/lib/contracts/errors.rb +74 -0
  144. data/lib/contracts-ruby3/lib/contracts/formatters.rb +140 -0
  145. data/lib/contracts-ruby3/lib/contracts/invariants.rb +72 -0
  146. data/lib/contracts-ruby3/lib/contracts/method_handler.rb +197 -0
  147. data/lib/contracts-ruby3/lib/contracts/method_reference.rb +102 -0
  148. data/lib/contracts-ruby3/lib/contracts/support.rb +63 -0
  149. data/lib/contracts-ruby3/lib/contracts/validators.rb +143 -0
  150. data/lib/contracts-ruby3/lib/contracts/version.rb +5 -0
  151. data/lib/contracts-ruby3/lib/contracts.rb +290 -0
  152. data/lib/contracts-ruby3/script/docs-release +3 -0
  153. data/lib/contracts-ruby3/script/docs-staging +3 -0
  154. data/lib/contracts-ruby3/script/rubocop.rb +5 -0
  155. data/lib/contracts-ruby3/spec/attrs_spec.rb +119 -0
  156. data/lib/contracts-ruby3/spec/builtin_contracts_spec.rb +457 -0
  157. data/lib/contracts-ruby3/spec/contracts_spec.rb +773 -0
  158. data/lib/contracts-ruby3/spec/fixtures/fixtures.rb +725 -0
  159. data/lib/contracts-ruby3/spec/invariants_spec.rb +17 -0
  160. data/lib/contracts-ruby3/spec/methods_spec.rb +54 -0
  161. data/lib/contracts-ruby3/spec/module_spec.rb +18 -0
  162. data/lib/contracts-ruby3/spec/override_validators_spec.rb +162 -0
  163. data/lib/contracts-ruby3/spec/ruby_version_specific/contracts_spec_1.9.rb +24 -0
  164. data/lib/contracts-ruby3/spec/ruby_version_specific/contracts_spec_2.0.rb +55 -0
  165. data/lib/contracts-ruby3/spec/ruby_version_specific/contracts_spec_2.1.rb +63 -0
  166. data/lib/contracts-ruby3/spec/spec_helper.rb +102 -0
  167. data/lib/contracts-ruby3/spec/support.rb +10 -0
  168. data/lib/contracts-ruby3/spec/support_spec.rb +21 -0
  169. data/lib/contracts-ruby3/spec/validators_spec.rb +47 -0
  170. data/lib/entitlements/data/groups/calculated/yaml.rb +7 -1
  171. data/lib/entitlements/data/people/yaml.rb +9 -1
  172. data/lib/entitlements/extras/ldap_group/rules/ldap_group.rb +5 -1
  173. data/lib/entitlements/extras/orgchart/person_methods.rb +7 -1
  174. data/lib/entitlements.rb +13 -2
  175. data/lib/ruby_version_check.rb +17 -0
  176. metadata +209 -14
@@ -0,0 +1,64 @@
1
+ Feature: Bool
2
+
3
+ Checks that the argument is a `true` or `false`.
4
+
5
+ ```ruby
6
+ Contract String => C::Bool
7
+ ```
8
+
9
+ Background:
10
+ Given a file named "bool_usage.rb" with:
11
+ """ruby
12
+ require "contracts"
13
+ C = Contracts
14
+
15
+ class Example
16
+ include Contracts::Core
17
+
18
+ Contract String => C::Bool
19
+ def self.strong?(password)
20
+ return if password == ""
21
+ password.length > 22
22
+ end
23
+ end
24
+ """
25
+
26
+ Scenario: Accepts `true`
27
+ Given a file named "true.rb" with:
28
+ """ruby
29
+ require "./bool_usage"
30
+ puts Example.strong?("verystrongandLon774gPassword!ForYouHere")
31
+ """
32
+ When I run `ruby true.rb`
33
+ Then output should contain:
34
+ """
35
+ true
36
+ """
37
+
38
+ Scenario: Accepts `false`
39
+ Given a file named "false.rb" with:
40
+ """ruby
41
+ require "./bool_usage"
42
+ puts Example.strong?("welcome")
43
+ """
44
+ When I run `ruby false.rb`
45
+ Then output should contain:
46
+ """
47
+ false
48
+ """
49
+
50
+ Scenario: Rejects everything else
51
+ Given a file named "nil.rb" with:
52
+ """ruby
53
+ require "./bool_usage"
54
+ puts Example.strong?("")
55
+ """
56
+ When I run `ruby nil.rb`
57
+ Then output should contain:
58
+ """
59
+ : Contract violation for return value: (ReturnContractError)
60
+ Expected: Bool,
61
+ Actual: nil
62
+ Value guarded in: Example::strong?
63
+ With Contract: String => Bool
64
+ """
@@ -0,0 +1 @@
1
+ Feature: Enum (TODO)
@@ -0,0 +1 @@
1
+ Feature: Eq (TODO)
@@ -0,0 +1 @@
1
+ Feature: Exactly (TODO)
@@ -0,0 +1 @@
1
+ Feature: Func (TODO)
@@ -0,0 +1 @@
1
+ Feature: HashOf (TODO)
@@ -0,0 +1,93 @@
1
+ Feature: Int
2
+
3
+ Checks that an argument is an integer.
4
+
5
+ ```ruby
6
+ Contract C::Int => C::Int
7
+ ```
8
+
9
+ Background:
10
+ Given a file named "int_usage.rb" with:
11
+ """ruby
12
+ require "contracts"
13
+ C = Contracts
14
+
15
+ class Integr
16
+ include Contracts::Core
17
+
18
+ Contract C::Int => C::Int
19
+ def prev(number)
20
+ number - 1
21
+ end
22
+ end
23
+ """
24
+
25
+ Scenario: Accepts positive integers
26
+ Given a file named "accepts_positive_integers.rb" with:
27
+ """ruby
28
+ require "./int_usage"
29
+ puts Integr.new.prev(7)
30
+ """
31
+ When I run `ruby accepts_positive_integers.rb`
32
+ Then output should contain:
33
+ """
34
+ 6
35
+ """
36
+
37
+ Scenario: Accepts zero
38
+ Given a file named "accepts_zero.rb" with:
39
+ """ruby
40
+ require "./int_usage"
41
+ puts Integr.new.prev(1)
42
+ """
43
+ When I run `ruby accepts_zero.rb`
44
+ Then output should contain:
45
+ """
46
+ 0
47
+ """
48
+
49
+ Scenario: Accepts negative integers
50
+ Given a file named "accepts_negative_integers.rb" with:
51
+ """ruby
52
+ require "./int_usage"
53
+ puts Integr.new.prev(-1)
54
+ """
55
+ When I run `ruby accepts_negative_integers.rb`
56
+ Then output should contain:
57
+ """
58
+ -2
59
+ """
60
+
61
+ Scenario: Rejects floats
62
+ Given a file named "rejects_floats.rb" with:
63
+ """ruby
64
+ require "./int_usage"
65
+ puts Integr.new.prev(3.43)
66
+ """
67
+ When I run `ruby rejects_floats.rb`
68
+ Then output should contain:
69
+ """
70
+ : Contract violation for argument 1 of 1: (ParamContractError)
71
+ Expected: Int,
72
+ Actual: 3.43
73
+ Value guarded in: Integr::prev
74
+ With Contract: Int => Int
75
+ """
76
+ And output should contain "int_usage.rb:8"
77
+
78
+ Scenario: Rejects other values
79
+ Given a file named "rejects_others.rb" with:
80
+ """ruby
81
+ require "./int_usage"
82
+ puts Integr.new.prev("foo")
83
+ """
84
+ When I run `ruby rejects_others.rb`
85
+ Then output should contain:
86
+ """
87
+ : Contract violation for argument 1 of 1: (ParamContractError)
88
+ Expected: Int,
89
+ Actual: "foo"
90
+ Value guarded in: Integr::prev
91
+ With Contract: Int => Int
92
+ """
93
+ And output should contain "int_usage.rb:8"
@@ -0,0 +1 @@
1
+ Feature: KeywordArgs (TODO)
@@ -0,0 +1 @@
1
+ Feature: Maybe (TODO)
@@ -0,0 +1,115 @@
1
+ Feature: Nat
2
+
3
+ Checks that an argument is a natural number.
4
+
5
+ ```ruby
6
+ Contract C::Nat => C::Nat
7
+ ```
8
+
9
+ Background:
10
+ Given a file named "nat_usage.rb" with:
11
+ """ruby
12
+ require "contracts"
13
+ C = Contracts
14
+
15
+ class Natural
16
+ include Contracts::Core
17
+
18
+ Contract C::Nat => C::Nat
19
+ def prev(number)
20
+ number - 1
21
+ end
22
+ end
23
+ """
24
+
25
+ Scenario: Accepts positive integers
26
+ Given a file named "accepts_positive_integers.rb" with:
27
+ """ruby
28
+ require "./nat_usage"
29
+ puts Natural.new.prev(7)
30
+ """
31
+ When I run `ruby accepts_positive_integers.rb`
32
+ Then output should contain:
33
+ """
34
+ 6
35
+ """
36
+
37
+ Scenario: Accepts zero
38
+ Given a file named "accepts_zero.rb" with:
39
+ """ruby
40
+ require "./nat_usage"
41
+ puts Natural.new.prev(1)
42
+ """
43
+ When I run `ruby accepts_zero.rb`
44
+ Then output should contain:
45
+ """
46
+ 0
47
+ """
48
+
49
+ Scenario: Rejects negative integers
50
+ Given a file named "rejects_negative_integers.rb" with:
51
+ """ruby
52
+ require "./nat_usage"
53
+ puts Natural.new.prev(-1)
54
+ """
55
+ When I run `ruby rejects_negative_integers.rb`
56
+ Then output should contain:
57
+ """
58
+ : Contract violation for argument 1 of 1: (ParamContractError)
59
+ Expected: Nat,
60
+ Actual: -1
61
+ Value guarded in: Natural::prev
62
+ With Contract: Nat => Nat
63
+ """
64
+ And output should contain "nat_usage.rb:8"
65
+
66
+ Scenario: Rejects negative integers as a return value
67
+ Given a file named "rejects_negative_integers.rb" with:
68
+ """ruby
69
+ require "./nat_usage"
70
+ puts Natural.new.prev(0)
71
+ """
72
+ When I run `ruby rejects_negative_integers.rb`
73
+ Then output should contain:
74
+ """
75
+ : Contract violation for return value: (ReturnContractError)
76
+ Expected: Nat,
77
+ Actual: -1
78
+ Value guarded in: Natural::prev
79
+ With Contract: Nat => Nat
80
+ """
81
+ And output should contain "nat_usage.rb:8"
82
+
83
+ Scenario: Rejects floats
84
+ Given a file named "rejects_floats.rb" with:
85
+ """ruby
86
+ require "./nat_usage"
87
+ puts Natural.new.prev(3.43)
88
+ """
89
+ When I run `ruby rejects_floats.rb`
90
+ Then output should contain:
91
+ """
92
+ : Contract violation for argument 1 of 1: (ParamContractError)
93
+ Expected: Nat,
94
+ Actual: 3.43
95
+ Value guarded in: Natural::prev
96
+ With Contract: Nat => Nat
97
+ """
98
+ And output should contain "nat_usage.rb:8"
99
+
100
+ Scenario: Rejects other values
101
+ Given a file named "rejects_others.rb" with:
102
+ """ruby
103
+ require "./nat_usage"
104
+ puts Natural.new.prev("foo")
105
+ """
106
+ When I run `ruby rejects_others.rb`
107
+ Then output should contain:
108
+ """
109
+ : Contract violation for argument 1 of 1: (ParamContractError)
110
+ Expected: Nat,
111
+ Actual: "foo"
112
+ Value guarded in: Natural::prev
113
+ With Contract: Nat => Nat
114
+ """
115
+ And output should contain "nat_usage.rb:8"
@@ -0,0 +1,119 @@
1
+ Feature: NatPos
2
+
3
+ Checks that an argument is a positive natural number.
4
+
5
+ ```ruby
6
+ Contract C::NatPos => C::NatPos
7
+ ```
8
+
9
+ Background:
10
+ Given a file named "nat_pos_usage.rb" with:
11
+ """ruby
12
+ require "contracts"
13
+ C = Contracts
14
+
15
+ class NaturalPositive
16
+ include Contracts::Core
17
+
18
+ Contract C::NatPos => C::NatPos
19
+ def prev(number)
20
+ number - 1
21
+ end
22
+ end
23
+ """
24
+
25
+ Scenario: Accepts positive integers
26
+ Given a file named "accepts_positive_integers.rb" with:
27
+ """ruby
28
+ require "./nat_pos_usage"
29
+ puts NaturalPositive.new.prev(7)
30
+ """
31
+ When I run `ruby accepts_positive_integers.rb`
32
+ Then output should contain:
33
+ """
34
+ 6
35
+ """
36
+
37
+ Scenario: Rejects zero
38
+ Given a file named "rejects_zero.rb" with:
39
+ """ruby
40
+ require "./nat_pos_usage"
41
+ puts NaturalPositive.new.prev(0)
42
+ """
43
+ When I run `ruby rejects_zero.rb`
44
+ Then output should contain:
45
+ """
46
+ : Contract violation for argument 1 of 1: (ParamContractError)
47
+ Expected: NatPos,
48
+ Actual: 0
49
+ Value guarded in: NaturalPositive::prev
50
+ With Contract: NatPos => NatPos
51
+ """
52
+
53
+ Scenario: Rejects negative integers
54
+ Given a file named "rejects_negative_integers.rb" with:
55
+ """ruby
56
+ require "./nat_pos_usage"
57
+ puts NaturalPositive.new.prev(-1)
58
+ """
59
+ When I run `ruby rejects_negative_integers.rb`
60
+ Then output should contain:
61
+ """
62
+ : Contract violation for argument 1 of 1: (ParamContractError)
63
+ Expected: NatPos,
64
+ Actual: -1
65
+ Value guarded in: NaturalPositive::prev
66
+ With Contract: NatPos => NatPos
67
+ """
68
+ And output should contain "nat_pos_usage.rb:8"
69
+
70
+ Scenario: Rejects negative integers as a return value
71
+ Given a file named "rejects_negative_integers.rb" with:
72
+ """ruby
73
+ require "./nat_pos_usage"
74
+ puts NaturalPositive.new.prev(1)
75
+ """
76
+ When I run `ruby rejects_negative_integers.rb`
77
+ Then output should contain:
78
+ """
79
+ : Contract violation for return value: (ReturnContractError)
80
+ Expected: NatPos,
81
+ Actual: 0
82
+ Value guarded in: NaturalPositive::prev
83
+ With Contract: NatPos => NatPos
84
+ """
85
+ And output should contain "nat_pos_usage.rb:8"
86
+
87
+ Scenario: Rejects floats
88
+ Given a file named "rejects_floats.rb" with:
89
+ """ruby
90
+ require "./nat_pos_usage"
91
+ puts NaturalPositive.new.prev(3.43)
92
+ """
93
+ When I run `ruby rejects_floats.rb`
94
+ Then output should contain:
95
+ """
96
+ : Contract violation for argument 1 of 1: (ParamContractError)
97
+ Expected: NatPos,
98
+ Actual: 3.43
99
+ Value guarded in: NaturalPositive::prev
100
+ With Contract: NatPos => NatPos
101
+ """
102
+ And output should contain "nat_pos_usage.rb:8"
103
+
104
+ Scenario: Rejects other values
105
+ Given a file named "rejects_others.rb" with:
106
+ """ruby
107
+ require "./nat_pos_usage"
108
+ puts NaturalPositive.new.prev("foo")
109
+ """
110
+ When I run `ruby rejects_others.rb`
111
+ Then output should contain:
112
+ """
113
+ : Contract violation for argument 1 of 1: (ParamContractError)
114
+ Expected: NatPos,
115
+ Actual: "foo"
116
+ Value guarded in: NaturalPositive::prev
117
+ With Contract: NatPos => NatPos
118
+ """
119
+ And output should contain "nat_pos_usage.rb:8"
@@ -0,0 +1,115 @@
1
+ Feature: Neg
2
+
3
+ Checks that an argument is negative `Numeric`.
4
+
5
+ ```ruby
6
+ Contract C::Neg => C::Neg
7
+ ```
8
+
9
+ Background:
10
+ Given a file named "pos_usage.rb" with:
11
+ """ruby
12
+ require "contracts"
13
+ C = Contracts
14
+
15
+ class Example
16
+ include Contracts::Core
17
+
18
+ Contract C::Neg => C::Neg
19
+ def double_expense(amount)
20
+ amount * 2
21
+ end
22
+ end
23
+ """
24
+
25
+ Scenario: Accepts negative integers
26
+ Given a file named "accepts_negative_integers.rb" with:
27
+ """ruby
28
+ require "./pos_usage"
29
+ puts Example.new.double_expense(-50)
30
+ """
31
+ When I run `ruby accepts_negative_integers.rb`
32
+ Then output should contain:
33
+ """
34
+ -100
35
+ """
36
+
37
+ Scenario: Accepts negative floats
38
+ Given a file named "accepts_negative_floats.rb" with:
39
+ """ruby
40
+ require "./pos_usage"
41
+ puts Example.new.double_expense(-37.99)
42
+ """
43
+ When I run `ruby accepts_negative_floats.rb`
44
+ Then output should contain:
45
+ """
46
+ -75.98
47
+ """
48
+
49
+ Scenario: Rejects positive integers
50
+ Given a file named "rejects_positive_integers.rb" with:
51
+ """ruby
52
+ require "./pos_usage"
53
+ puts Example.new.double_expense(50)
54
+ """
55
+ When I run `ruby rejects_positive_integers.rb`
56
+ Then output should contain:
57
+ """
58
+ : Contract violation for argument 1 of 1: (ParamContractError)
59
+ Expected: Neg,
60
+ Actual: 50
61
+ Value guarded in: Example::double_expense
62
+ With Contract: Neg => Neg
63
+ """
64
+ And output should contain "pos_usage.rb:8"
65
+
66
+ Scenario: Rejects positive floats
67
+ Given a file named "rejects_positive_floats.rb" with:
68
+ """ruby
69
+ require "./pos_usage"
70
+ puts Example.new.double_expense(42.50)
71
+ """
72
+ When I run `ruby rejects_positive_floats.rb`
73
+ Then output should contain:
74
+ """
75
+ : Contract violation for argument 1 of 1: (ParamContractError)
76
+ Expected: Neg,
77
+ Actual: 42.5
78
+ Value guarded in: Example::double_expense
79
+ With Contract: Neg => Neg
80
+ """
81
+ And output should contain "pos_usage.rb:8"
82
+
83
+ Scenario: Rejects zero
84
+ Given a file named "rejects_zero.rb" with:
85
+ """ruby
86
+ require "./pos_usage"
87
+ puts Example.new.double_expense(0)
88
+ """
89
+ When I run `ruby rejects_zero.rb`
90
+ Then output should contain:
91
+ """
92
+ : Contract violation for argument 1 of 1: (ParamContractError)
93
+ Expected: Neg,
94
+ Actual: 0
95
+ Value guarded in: Example::double_expense
96
+ With Contract: Neg => Neg
97
+ """
98
+ And output should contain "pos_usage.rb:8"
99
+
100
+ Scenario: Rejects other values
101
+ Given a file named "rejects_others.rb" with:
102
+ """ruby
103
+ require "./pos_usage"
104
+ puts Example.new.double_expense("foo")
105
+ """
106
+ When I run `ruby rejects_others.rb`
107
+ Then output should contain:
108
+ """
109
+ : Contract violation for argument 1 of 1: (ParamContractError)
110
+ Expected: Neg,
111
+ Actual: "foo"
112
+ Value guarded in: Example::double_expense
113
+ With Contract: Neg => Neg
114
+ """
115
+ And output should contain "pos_usage.rb:8"
@@ -0,0 +1,145 @@
1
+ Feature: None
2
+
3
+ Fails for any argument.
4
+
5
+ Often used to explicitly specify that method does not accept any arguments:
6
+
7
+ ```ruby
8
+ Contract C::None => Symbol
9
+ def a_symbol
10
+ :a_symbol
11
+ end
12
+ ```
13
+
14
+ The same behavior can be achieved when argument list omitted:
15
+
16
+ ```ruby
17
+ Contract Symbol
18
+ def a_symbol
19
+ :a_symbol
20
+ end
21
+ ```
22
+
23
+ Background:
24
+ Given a file named "helper.rb" with:
25
+ """ruby
26
+ def autorescue
27
+ yield
28
+ rescue => e
29
+ puts e.inspect
30
+ end
31
+ """
32
+ Given a file named "none_usage.rb" with:
33
+ """ruby
34
+ require "contracts"
35
+ require "./helper"
36
+ C = Contracts
37
+
38
+ class Example
39
+ include Contracts::Core
40
+
41
+ Contract C::None => Symbol
42
+ def self.a_symbol(*args)
43
+ :a_symbol
44
+ end
45
+ end
46
+ """
47
+
48
+ Scenario: Accepts nothing
49
+ Given a file named "nothing.rb" with:
50
+ """ruby
51
+ require "./none_usage"
52
+ puts Example.a_symbol
53
+ """
54
+ When I run `ruby nothing.rb`
55
+ Then output should contain:
56
+ """
57
+ a_symbol
58
+ """
59
+
60
+ Scenario: Rejects any argument
61
+ Given a file named "anything.rb" with:
62
+ """ruby
63
+ require "./none_usage"
64
+ autorescue { Example.a_symbol(nil) }
65
+ autorescue { Example.a_symbol(12) }
66
+ autorescue { Example.a_symbol(37.5) }
67
+ autorescue { Example.a_symbol("foo") }
68
+ autorescue { Example.a_symbol(:foo) }
69
+ autorescue { Example.a_symbol({}) }
70
+ autorescue { Example.a_symbol([]) }
71
+ autorescue { Example.a_symbol(Object) }
72
+ """
73
+ When I run `ruby anything.rb`
74
+
75
+ Then output should contain:
76
+ """
77
+ ParamContractError: Contract violation for argument 1 of 1:
78
+ Expected: None,
79
+ Actual: nil
80
+ Value guarded in: Example::a_symbol
81
+ With Contract: None => Symbol
82
+ """
83
+
84
+ Then output should contain:
85
+ """
86
+ ParamContractError: Contract violation for argument 1 of 1:
87
+ Expected: None,
88
+ Actual: 12
89
+ Value guarded in: Example::a_symbol
90
+ With Contract: None => Symbol
91
+ """
92
+
93
+ Then output should contain:
94
+ """
95
+ ParamContractError: Contract violation for argument 1 of 1:
96
+ Expected: None,
97
+ Actual: 37.5
98
+ Value guarded in: Example::a_symbol
99
+ With Contract: None => Symbol
100
+ """
101
+
102
+ Then output should contain:
103
+ """
104
+ ParamContractError: Contract violation for argument 1 of 1:
105
+ Expected: None,
106
+ Actual: "foo"
107
+ Value guarded in: Example::a_symbol
108
+ With Contract: None => Symbol
109
+ """
110
+
111
+ Then output should contain:
112
+ """
113
+ ParamContractError: Contract violation for argument 1 of 1:
114
+ Expected: None,
115
+ Actual: :foo
116
+ Value guarded in: Example::a_symbol
117
+ With Contract: None => Symbol
118
+ """
119
+
120
+ Then output should contain:
121
+ """
122
+ ParamContractError: Contract violation for argument 1 of 1:
123
+ Expected: None,
124
+ Actual: {}
125
+ Value guarded in: Example::a_symbol
126
+ With Contract: None => Symbol
127
+ """
128
+
129
+ Then output should contain:
130
+ """
131
+ ParamContractError: Contract violation for argument 1 of 1:
132
+ Expected: None,
133
+ Actual: []
134
+ Value guarded in: Example::a_symbol
135
+ With Contract: None => Symbol
136
+ """
137
+
138
+ Then output should contain:
139
+ """
140
+ ParamContractError: Contract violation for argument 1 of 1:
141
+ Expected: None,
142
+ Actual: Object
143
+ Value guarded in: Example::a_symbol
144
+ With Contract: None => Symbol
145
+ """
@@ -0,0 +1 @@
1
+ Feature: Not (TODO)