|
| 1 | +Feature: Pretty printing Contract violations |
| 2 | + |
| 3 | + Scenario: Big array argument being passed to big array method parameter |
| 4 | + Given a file named "example.rb" with: |
| 5 | + """ruby |
| 6 | + require "contracts" |
| 7 | + C = Contracts |
| 8 | +
|
| 9 | + class Example |
| 10 | + include Contracts::Core |
| 11 | +
|
| 12 | + class << self |
| 13 | + Contract [ |
| 14 | + C::Or[String, Symbol], |
| 15 | + C::Or[String, Symbol], |
| 16 | + C::Or[String, Symbol], |
| 17 | + C::Or[String, Symbol], |
| 18 | + C::Or[String, Symbol], |
| 19 | + C::Or[String, Symbol], |
| 20 | + C::Or[String, Symbol] |
| 21 | + ] => nil |
| 22 | + def run(data) |
| 23 | + nil |
| 24 | + end |
| 25 | + end |
| 26 | + end |
| 27 | +
|
| 28 | + puts Example.run([ |
| 29 | + ["foo", "foo"], |
| 30 | + ["foo", "foo"], |
| 31 | + ["foo", "foo"], |
| 32 | + ["foo", "foo"], |
| 33 | + ["foo", "foo"], |
| 34 | + ["foo", "foo"], |
| 35 | + ["foo", "foo"], |
| 36 | + ["foo", "foo"], |
| 37 | + ["foo", "foo"] |
| 38 | + ]) |
| 39 | + """ |
| 40 | + When I run `ruby example.rb` |
| 41 | + Then the output should contain: |
| 42 | + """ |
| 43 | + : Contract violation for argument 1 of 1: (ParamContractError) |
| 44 | + Expected: [(String or Symbol), |
| 45 | + (String or Symbol), |
| 46 | + (String or Symbol), |
| 47 | + (String or Symbol), |
| 48 | + (String or Symbol), |
| 49 | + (String or Symbol), |
| 50 | + (String or Symbol)], |
| 51 | + Actual: [["foo", "foo"], |
| 52 | + ["foo", "foo"], |
| 53 | + ["foo", "foo"], |
| 54 | + ["foo", "foo"], |
| 55 | + ["foo", "foo"], |
| 56 | + ["foo", "foo"], |
| 57 | + ["foo", "foo"], |
| 58 | + ["foo", "foo"], |
| 59 | + ["foo", "foo"]] |
| 60 | + Value guarded in: Example::run |
| 61 | + With Contract: Array => NilClass |
| 62 | + At: example.rb:17 |
| 63 | + """ |
| 64 | + |
| 65 | + Scenario: Big array value being returned from method expecting different big array type |
| 66 | + Given a file named "example.rb" with: |
| 67 | + """ruby |
| 68 | + require "contracts" |
| 69 | + C = Contracts |
| 70 | +
|
| 71 | + class Example |
| 72 | + include Contracts::Core |
| 73 | +
|
| 74 | + class << self |
| 75 | + Contract C::None => [ |
| 76 | + C::Or[String, Symbol], |
| 77 | + C::Or[String, Symbol], |
| 78 | + C::Or[String, Symbol], |
| 79 | + C::Or[String, Symbol], |
| 80 | + C::Or[String, Symbol], |
| 81 | + C::Or[String, Symbol], |
| 82 | + C::Or[String, Symbol] |
| 83 | + ] |
| 84 | + def run |
| 85 | + [ |
| 86 | + ["foo", "foo"], |
| 87 | + ["foo", "foo"], |
| 88 | + ["foo", "foo"], |
| 89 | + ["foo", "foo"], |
| 90 | + ["foo", "foo"], |
| 91 | + ["foo", "foo"], |
| 92 | + ["foo", "foo"], |
| 93 | + ["foo", "foo"], |
| 94 | + ["foo", "foo"] |
| 95 | + ] |
| 96 | + end |
| 97 | + end |
| 98 | + end |
| 99 | +
|
| 100 | + puts Example.run |
| 101 | + """ |
| 102 | + When I run `ruby example.rb` |
| 103 | + Then the output should contain: |
| 104 | + """ |
| 105 | + : Contract violation for return value: (ReturnContractError) |
| 106 | + Expected: [(String or Symbol), |
| 107 | + (String or Symbol), |
| 108 | + (String or Symbol), |
| 109 | + (String or Symbol), |
| 110 | + (String or Symbol), |
| 111 | + (String or Symbol), |
| 112 | + (String or Symbol)], |
| 113 | + Actual: [["foo", "foo"], |
| 114 | + ["foo", "foo"], |
| 115 | + ["foo", "foo"], |
| 116 | + ["foo", "foo"], |
| 117 | + ["foo", "foo"], |
| 118 | + ["foo", "foo"], |
| 119 | + ["foo", "foo"], |
| 120 | + ["foo", "foo"], |
| 121 | + ["foo", "foo"]] |
| 122 | + Value guarded in: Example::run |
| 123 | + With Contract: None => Array |
| 124 | + At: example.rb:17 |
| 125 | + """ |
| 126 | + |
| 127 | + Scenario: Big hash argument being passed to big hash method parameter |
| 128 | + Given a file named "example.rb" with: |
| 129 | + """ruby |
| 130 | + require "contracts" |
| 131 | + C = Contracts |
| 132 | +
|
| 133 | + class Example |
| 134 | + include Contracts::Core |
| 135 | +
|
| 136 | + class << self |
| 137 | + Contract ({ |
| 138 | + a: C::Or[String, Symbol], |
| 139 | + b: C::Or[String, Symbol], |
| 140 | + c: C::Or[String, Symbol], |
| 141 | + d: C::Or[String, Symbol], |
| 142 | + e: C::Or[String, Symbol], |
| 143 | + f: C::Or[String, Symbol], |
| 144 | + g: C::Or[String, Symbol] |
| 145 | + }) => nil |
| 146 | + def run(data) |
| 147 | + nil |
| 148 | + end |
| 149 | + end |
| 150 | + end |
| 151 | +
|
| 152 | + puts Example.run({ |
| 153 | + a: ["foo", "foo"], |
| 154 | + b: ["foo", "foo"], |
| 155 | + c: ["foo", "foo"], |
| 156 | + d: ["foo", "foo"], |
| 157 | + e: ["foo", "foo"], |
| 158 | + f: ["foo", "foo"], |
| 159 | + g: ["foo", "foo"] |
| 160 | + }) |
| 161 | + """ |
| 162 | + When I run `ruby example.rb` |
| 163 | + Then the output should contain: |
| 164 | + """ |
| 165 | + : Contract violation for argument 1 of 1: (ParamContractError) |
| 166 | + Expected: {:a=>(String or Symbol), |
| 167 | + :b=>(String or Symbol), |
| 168 | + :c=>(String or Symbol), |
| 169 | + :d=>(String or Symbol), |
| 170 | + :e=>(String or Symbol), |
| 171 | + :f=>(String or Symbol), |
| 172 | + :g=>(String or Symbol)}, |
| 173 | + Actual: {:a=>["foo", "foo"], |
| 174 | + :b=>["foo", "foo"], |
| 175 | + :c=>["foo", "foo"], |
| 176 | + :d=>["foo", "foo"], |
| 177 | + :e=>["foo", "foo"], |
| 178 | + :f=>["foo", "foo"], |
| 179 | + :g=>["foo", "foo"]} |
| 180 | + Value guarded in: Example::run |
| 181 | + With Contract: Hash => NilClass |
| 182 | + At: example.rb:17 |
| 183 | + """ |
| 184 | + |
| 185 | + Scenario: Big hash value being returned from method expecting different big hash type |
| 186 | + Given a file named "example.rb" with: |
| 187 | + """ruby |
| 188 | + require "contracts" |
| 189 | + C = Contracts |
| 190 | +
|
| 191 | + class Example |
| 192 | + include Contracts::Core |
| 193 | +
|
| 194 | + class << self |
| 195 | + Contract C::None => ({ |
| 196 | + a: C::Or[String, Symbol], |
| 197 | + b: C::Or[String, Symbol], |
| 198 | + c: C::Or[String, Symbol], |
| 199 | + d: C::Or[String, Symbol], |
| 200 | + e: C::Or[String, Symbol], |
| 201 | + f: C::Or[String, Symbol], |
| 202 | + g: C::Or[String, Symbol] |
| 203 | + }) |
| 204 | + def run |
| 205 | + { |
| 206 | + a: ["foo", "foo"], |
| 207 | + b: ["foo", "foo"], |
| 208 | + c: ["foo", "foo"], |
| 209 | + d: ["foo", "foo"], |
| 210 | + e: ["foo", "foo"], |
| 211 | + f: ["foo", "foo"], |
| 212 | + g: ["foo", "foo"] |
| 213 | + } |
| 214 | + end |
| 215 | + end |
| 216 | + end |
| 217 | +
|
| 218 | + puts Example.run |
| 219 | + """ |
| 220 | + When I run `ruby example.rb` |
| 221 | + Then the output should contain: |
| 222 | + """ |
| 223 | + : Contract violation for return value: (ReturnContractError) |
| 224 | + Expected: {:a=>(String or Symbol), |
| 225 | + :b=>(String or Symbol), |
| 226 | + :c=>(String or Symbol), |
| 227 | + :d=>(String or Symbol), |
| 228 | + :e=>(String or Symbol), |
| 229 | + :f=>(String or Symbol), |
| 230 | + :g=>(String or Symbol)}, |
| 231 | + Actual: {:a=>["foo", "foo"], |
| 232 | + :b=>["foo", "foo"], |
| 233 | + :c=>["foo", "foo"], |
| 234 | + :d=>["foo", "foo"], |
| 235 | + :e=>["foo", "foo"], |
| 236 | + :f=>["foo", "foo"], |
| 237 | + :g=>["foo", "foo"]} |
| 238 | + Value guarded in: Example::run |
| 239 | + With Contract: None => Hash |
| 240 | + At: example.rb:17 |
| 241 | + """ |
0 commit comments