lookout 2.3.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (328) hide show
  1. checksums.yaml +7 -0
  2. data/README +351 -181
  3. data/Rakefile +20 -5
  4. data/lib/lookout-3.0.rb +138 -0
  5. data/lib/lookout-3.0/actual.rb +30 -0
  6. data/lib/lookout-3.0/actual/method.rb +31 -0
  7. data/lib/lookout-3.0/actual/not.rb +13 -0
  8. data/lib/lookout-3.0/actual/not/method.rb +10 -0
  9. data/lib/lookout-3.0/aphonic.rb +44 -0
  10. data/lib/lookout-3.0/diff.rb +29 -0
  11. data/lib/{lookout → lookout-3.0}/diff/algorithms.rb +1 -1
  12. data/lib/lookout-3.0/diff/algorithms/difflib.rb +62 -0
  13. data/lib/lookout-3.0/diff/algorithms/difflib/position.rb +63 -0
  14. data/lib/{lookout/diff/algorithms/difflib/position/to.rb → lookout-3.0/diff/algorithms/difflib/position/new.rb} +8 -17
  15. data/lib/lookout-3.0/diff/formats.rb +5 -0
  16. data/lib/lookout-3.0/diff/formats/inline.rb +43 -0
  17. data/lib/lookout-3.0/diff/formats/set.rb +48 -0
  18. data/lib/lookout-3.0/diff/formats/unified.rb +56 -0
  19. data/lib/lookout-3.0/diff/group.rb +57 -0
  20. data/lib/lookout-3.0/diff/groups.rb +47 -0
  21. data/lib/lookout-3.0/diff/match.rb +31 -0
  22. data/lib/lookout-3.0/diff/operation.rb +41 -0
  23. data/lib/lookout-3.0/diff/operations.rb +35 -0
  24. data/lib/lookout-3.0/diff/operations/copy.rb +25 -0
  25. data/lib/lookout-3.0/diff/operations/delete.rb +5 -0
  26. data/lib/lookout-3.0/diff/operations/insert.rb +5 -0
  27. data/lib/lookout-3.0/diff/operations/replace.rb +6 -0
  28. data/lib/lookout-3.0/diff/slice.rb +97 -0
  29. data/lib/lookout-3.0/difference.rb +10 -0
  30. data/lib/lookout-3.0/difference/array.rb +22 -0
  31. data/lib/lookout-3.0/difference/exception.rb +40 -0
  32. data/lib/lookout-3.0/difference/hash.rb +31 -0
  33. data/lib/lookout-3.0/difference/lookout.rb +5 -0
  34. data/lib/lookout-3.0/difference/lookout/actual.rb +6 -0
  35. data/lib/lookout-3.0/difference/lookout/actual/method.rb +13 -0
  36. data/lib/lookout-3.0/difference/lookout/actual/not.rb +6 -0
  37. data/lib/lookout-3.0/difference/lookout/actual/not/method.rb +9 -0
  38. data/lib/lookout-3.0/difference/lookout/output.rb +8 -0
  39. data/lib/lookout-3.0/difference/lookout/reception.rb +21 -0
  40. data/lib/lookout-3.0/difference/lookout/warning.rb +9 -0
  41. data/lib/lookout-3.0/difference/module.rb +12 -0
  42. data/lib/lookout-3.0/difference/object.rb +73 -0
  43. data/lib/lookout-3.0/difference/range.rb +12 -0
  44. data/lib/lookout-3.0/difference/regexp.rb +12 -0
  45. data/lib/lookout-3.0/difference/string.rb +21 -0
  46. data/lib/lookout-3.0/difference/symbol.rb +21 -0
  47. data/lib/lookout-3.0/encode.rb +20 -0
  48. data/lib/lookout-3.0/exception.rb +79 -0
  49. data/lib/lookout-3.0/exception/backtrace.rb +65 -0
  50. data/lib/lookout-3.0/exception/unknown.rb +25 -0
  51. data/lib/lookout-3.0/expect.rb +32 -0
  52. data/lib/lookout-3.0/expect/classes.rb +6 -0
  53. data/lib/lookout-3.0/expect/classes/exception.rb +27 -0
  54. data/lib/lookout-3.0/expect/exception.rb +30 -0
  55. data/lib/lookout-3.0/expect/object.rb +54 -0
  56. data/lib/lookout-3.0/expect/object/context.rb +149 -0
  57. data/lib/lookout-3.0/expectations.rb +69 -0
  58. data/lib/lookout-3.0/expectations/context.rb +52 -0
  59. data/lib/lookout-3.0/expected.rb +10 -0
  60. data/lib/lookout-3.0/expected/array.rb +16 -0
  61. data/lib/lookout-3.0/expected/classes.rb +5 -0
  62. data/lib/lookout-3.0/expected/classes/exception.rb +14 -0
  63. data/lib/lookout-3.0/expected/exception.rb +46 -0
  64. data/lib/lookout-3.0/expected/falseclass.rb +9 -0
  65. data/lib/lookout-3.0/expected/hash.rb +14 -0
  66. data/lib/lookout-3.0/expected/lookout.rb +5 -0
  67. data/lib/lookout-3.0/expected/lookout/actual.rb +5 -0
  68. data/lib/lookout-3.0/expected/lookout/actual/method.rb +13 -0
  69. data/lib/lookout-3.0/expected/lookout/actual/not.rb +6 -0
  70. data/lib/lookout-3.0/expected/lookout/actual/not/method.rb +13 -0
  71. data/lib/lookout-3.0/expected/lookout/output.rb +26 -0
  72. data/lib/lookout-3.0/expected/lookout/reception.rb +24 -0
  73. data/lib/lookout-3.0/expected/lookout/warning.rb +29 -0
  74. data/lib/lookout-3.0/expected/module.rb +12 -0
  75. data/lib/lookout-3.0/expected/object.rb +30 -0
  76. data/lib/lookout-3.0/expected/range.rb +12 -0
  77. data/lib/lookout-3.0/expected/regexp.rb +12 -0
  78. data/lib/lookout-3.0/expected/string.rb +11 -0
  79. data/lib/lookout-3.0/expected/symbol.rb +21 -0
  80. data/lib/lookout-3.0/expected/trueclass.rb +9 -0
  81. data/lib/lookout-3.0/inspect.rb +45 -0
  82. data/lib/lookout-3.0/interfaces.rb +5 -0
  83. data/lib/lookout-3.0/interfaces/commandline.rb +109 -0
  84. data/lib/lookout-3.0/literal.rb +18 -0
  85. data/lib/lookout-3.0/mock.rb +24 -0
  86. data/lib/lookout-3.0/object.rb +6 -0
  87. data/lib/lookout-3.0/object/not.rb +16 -0
  88. data/lib/lookout-3.0/object/not/receive.rb +18 -0
  89. data/lib/lookout-3.0/object/to.rb +12 -0
  90. data/lib/lookout-3.0/object/to/receive.rb +18 -0
  91. data/lib/lookout-3.0/output.rb +20 -0
  92. data/lib/lookout-3.0/plugins.rb +7 -0
  93. data/lib/lookout-3.0/reception.rb +128 -0
  94. data/lib/lookout-3.0/reception/arguments.rb +20 -0
  95. data/lib/lookout-3.0/reception/arguments/any.rb +16 -0
  96. data/lib/lookout-3.0/reception/arguments/error.rb +5 -0
  97. data/lib/lookout-3.0/reception/arguments/list.rb +17 -0
  98. data/lib/lookout-3.0/reception/arguments/none.rb +6 -0
  99. data/lib/lookout-3.0/reception/error.rb +24 -0
  100. data/lib/lookout-3.0/result.rb +16 -0
  101. data/lib/lookout-3.0/results.rb +5 -0
  102. data/lib/lookout-3.0/results/error.rb +18 -0
  103. data/lib/lookout-3.0/results/failure.rb +15 -0
  104. data/lib/lookout-3.0/results/success.rb +7 -0
  105. data/lib/lookout-3.0/stub.rb +55 -0
  106. data/lib/lookout-3.0/version.rb +133 -0
  107. data/lib/lookout-3.0/warning.rb +40 -0
  108. data/test/unit/examples.rb +208 -83
  109. data/test/unit/{lookout.rb → lookout-3.0.rb} +0 -0
  110. data/test/unit/lookout-3.0/actual.rb +13 -0
  111. data/test/unit/lookout-3.0/actual/method.rb +31 -0
  112. data/test/unit/lookout-3.0/actual/not.rb +15 -0
  113. data/test/unit/lookout-3.0/actual/not/method.rb +7 -0
  114. data/test/unit/lookout-3.0/aphonic.rb +31 -0
  115. data/test/unit/{lookout → lookout-3.0}/diff.rb +0 -0
  116. data/test/unit/{lookout/diff/group.rb → lookout-3.0/diff/algorithms.rb} +0 -0
  117. data/test/unit/lookout-3.0/diff/algorithms/difflib.rb +56 -0
  118. data/test/unit/lookout-3.0/diff/algorithms/difflib/position.rb +92 -0
  119. data/test/unit/{lookout/diff/algorithms/difflib/position/to.rb → lookout-3.0/diff/algorithms/difflib/position/new.rb} +1 -2
  120. data/test/unit/{lookout/results.rb → lookout-3.0/diff/formats.rb} +0 -0
  121. data/test/unit/{lookout → lookout-3.0}/diff/formats/inline.rb +0 -0
  122. data/test/unit/lookout-3.0/diff/formats/set.rb +26 -0
  123. data/test/unit/{lookout → lookout-3.0}/diff/formats/unified.rb +0 -0
  124. data/test/unit/{lookout/results/error.rb → lookout-3.0/diff/group.rb} +0 -0
  125. data/test/unit/lookout-3.0/diff/groups.rb +102 -0
  126. data/test/unit/{lookout → lookout-3.0}/diff/match.rb +0 -0
  127. data/test/unit/lookout-3.0/diff/operation.rb +17 -0
  128. data/test/unit/lookout-3.0/diff/operations.rb +22 -0
  129. data/test/unit/lookout-3.0/diff/operations/copy.rb +50 -0
  130. data/test/unit/lookout-3.0/diff/operations/delete.rb +45 -0
  131. data/test/unit/lookout-3.0/diff/operations/insert.rb +45 -0
  132. data/test/unit/lookout-3.0/diff/operations/replace.rb +45 -0
  133. data/test/unit/lookout-3.0/diff/slice.rb +56 -0
  134. data/test/unit/{lookout/results/failures/behavior.rb → lookout-3.0/difference.rb} +0 -0
  135. data/test/unit/lookout-3.0/difference/array.rb +32 -0
  136. data/test/unit/lookout-3.0/difference/exception.rb +69 -0
  137. data/test/unit/lookout-3.0/difference/hash.rb +30 -0
  138. data/test/unit/{lookout/results/failures/state.rb → lookout-3.0/difference/lookout.rb} +0 -0
  139. data/test/unit/{lookout/results/fulfilled.rb → lookout-3.0/difference/lookout/actual.rb} +0 -0
  140. data/test/unit/lookout-3.0/difference/lookout/actual/method.rb +7 -0
  141. data/test/unit/{lookout/runners/console.rb → lookout-3.0/difference/lookout/actual/not.rb} +0 -0
  142. data/test/unit/lookout-3.0/difference/lookout/actual/not/method.rb +7 -0
  143. data/test/unit/lookout-3.0/difference/lookout/output.rb +11 -0
  144. data/test/unit/lookout-3.0/difference/lookout/reception.rb +11 -0
  145. data/test/unit/lookout-3.0/difference/lookout/warning.rb +11 -0
  146. data/test/unit/lookout-3.0/difference/module.rb +11 -0
  147. data/test/unit/lookout-3.0/difference/object.rb +31 -0
  148. data/test/unit/lookout-3.0/difference/range.rb +11 -0
  149. data/test/unit/lookout-3.0/difference/regexp.rb +11 -0
  150. data/test/unit/lookout-3.0/difference/string.rb +29 -0
  151. data/test/unit/lookout-3.0/difference/symbol.rb +11 -0
  152. data/test/unit/lookout-3.0/encode.rb +28 -0
  153. data/test/unit/lookout-3.0/exception.rb +107 -0
  154. data/test/unit/lookout-3.0/exception/backtrace.rb +75 -0
  155. data/test/unit/lookout-3.0/exception/unknown.rb +23 -0
  156. data/test/unit/lookout-3.0/expect.rb +15 -0
  157. data/test/unit/{lookout/ui/console.rb → lookout-3.0/expect/classes.rb} +0 -0
  158. data/test/unit/lookout-3.0/expect/classes/exception.rb +41 -0
  159. data/test/unit/lookout-3.0/expect/exception.rb +63 -0
  160. data/test/unit/lookout-3.0/expect/object.rb +55 -0
  161. data/test/unit/lookout-3.0/expect/object/context.rb +120 -0
  162. data/test/unit/lookout-3.0/expectations.rb +55 -0
  163. data/test/unit/lookout-3.0/expectations/context.rb +44 -0
  164. data/test/unit/lookout-3.0/expected.rb +4 -0
  165. data/test/unit/lookout-3.0/expected/array.rb +19 -0
  166. data/test/unit/lookout-3.0/expected/classes.rb +4 -0
  167. data/test/unit/lookout-3.0/expected/classes/exception.rb +7 -0
  168. data/test/unit/lookout-3.0/expected/exception.rb +24 -0
  169. data/test/unit/lookout-3.0/expected/falseclass.rb +23 -0
  170. data/test/unit/lookout-3.0/expected/hash.rb +23 -0
  171. data/test/unit/lookout-3.0/expected/lookout.rb +4 -0
  172. data/test/unit/lookout-3.0/expected/lookout/actual.rb +4 -0
  173. data/test/unit/lookout-3.0/expected/lookout/actual/method.rb +11 -0
  174. data/test/unit/lookout-3.0/expected/lookout/actual/not.rb +4 -0
  175. data/test/unit/lookout-3.0/expected/lookout/actual/not/method.rb +11 -0
  176. data/test/unit/lookout-3.0/expected/lookout/output.rb +27 -0
  177. data/test/unit/lookout-3.0/expected/lookout/reception.rb +25 -0
  178. data/test/unit/lookout-3.0/expected/lookout/warning.rb +48 -0
  179. data/test/unit/lookout-3.0/expected/module.rb +23 -0
  180. data/test/unit/lookout-3.0/expected/object.rb +24 -0
  181. data/test/unit/lookout-3.0/expected/range.rb +19 -0
  182. data/test/unit/lookout-3.0/expected/regexp.rb +19 -0
  183. data/test/unit/lookout-3.0/expected/string.rb +44 -0
  184. data/test/unit/lookout-3.0/expected/symbol.rb +35 -0
  185. data/test/unit/lookout-3.0/expected/trueclass.rb +23 -0
  186. data/test/unit/lookout-3.0/inspect.rb +39 -0
  187. data/test/unit/lookout-3.0/interfaces.rb +4 -0
  188. data/test/unit/lookout-3.0/interfaces/commandline.rb +4 -0
  189. data/test/unit/lookout-3.0/literal.rb +15 -0
  190. data/test/unit/lookout-3.0/mock.rb +22 -0
  191. data/test/unit/lookout-3.0/object.rb +4 -0
  192. data/test/unit/lookout-3.0/object/not.rb +7 -0
  193. data/test/unit/lookout-3.0/object/not/receive.rb +9 -0
  194. data/test/unit/lookout-3.0/object/to.rb +7 -0
  195. data/test/unit/lookout-3.0/object/to/receive.rb +9 -0
  196. data/test/unit/lookout-3.0/output.rb +31 -0
  197. data/test/unit/lookout-3.0/plugins.rb +4 -0
  198. data/test/unit/lookout-3.0/reception.rb +86 -0
  199. data/test/unit/lookout-3.0/reception/arguments.rb +23 -0
  200. data/test/unit/lookout-3.0/reception/arguments/any.rb +15 -0
  201. data/test/unit/lookout-3.0/reception/arguments/error.rb +4 -0
  202. data/test/unit/lookout-3.0/reception/arguments/list.rb +19 -0
  203. data/test/unit/lookout-3.0/reception/arguments/none.rb +15 -0
  204. data/test/unit/lookout-3.0/reception/error.rb +4 -0
  205. data/test/unit/lookout-3.0/result.rb +27 -0
  206. data/test/unit/lookout-3.0/results.rb +4 -0
  207. data/test/unit/lookout-3.0/results/error.rb +37 -0
  208. data/test/unit/lookout-3.0/results/failure.rb +21 -0
  209. data/test/unit/lookout-3.0/results/success.rb +4 -0
  210. data/test/unit/lookout-3.0/stub.rb +53 -0
  211. data/test/unit/lookout-3.0/version.rb +4 -0
  212. data/test/unit/lookout-3.0/warning.rb +47 -0
  213. metadata +1159 -456
  214. data/lib/lookout.rb +0 -30
  215. data/lib/lookout/aphonic.rb +0 -40
  216. data/lib/lookout/diff.rb +0 -10
  217. data/lib/lookout/diff/algorithms/difflib.rb +0 -38
  218. data/lib/lookout/diff/algorithms/difflib/position.rb +0 -92
  219. data/lib/lookout/diff/formats.rb +0 -7
  220. data/lib/lookout/diff/formats/hash.rb +0 -53
  221. data/lib/lookout/diff/formats/inline.rb +0 -39
  222. data/lib/lookout/diff/formats/unified.rb +0 -57
  223. data/lib/lookout/diff/group.rb +0 -61
  224. data/lib/lookout/diff/groups.rb +0 -34
  225. data/lib/lookout/diff/match.rb +0 -36
  226. data/lib/lookout/diff/operation.rb +0 -33
  227. data/lib/lookout/diff/operations.rb +0 -36
  228. data/lib/lookout/diff/operations/delete.rb +0 -9
  229. data/lib/lookout/diff/operations/equal.rb +0 -27
  230. data/lib/lookout/diff/operations/insert.rb +0 -9
  231. data/lib/lookout/diff/operations/replace.rb +0 -9
  232. data/lib/lookout/diff/range.rb +0 -91
  233. data/lib/lookout/equalities.rb +0 -13
  234. data/lib/lookout/equalities/array.rb +0 -22
  235. data/lib/lookout/equalities/boolean.rb +0 -9
  236. data/lib/lookout/equalities/hash.rb +0 -25
  237. data/lib/lookout/equalities/include.rb +0 -9
  238. data/lib/lookout/equalities/object.rb +0 -24
  239. data/lib/lookout/equalities/output.rb +0 -19
  240. data/lib/lookout/equalities/standarderror.rb +0 -32
  241. data/lib/lookout/equalities/string.rb +0 -19
  242. data/lib/lookout/equalities/warning.rb +0 -16
  243. data/lib/lookout/equality.rb +0 -36
  244. data/lib/lookout/expectation.rb +0 -69
  245. data/lib/lookout/expectations.rb +0 -49
  246. data/lib/lookout/expectations/behavior.rb +0 -20
  247. data/lib/lookout/expectations/line.rb +0 -29
  248. data/lib/lookout/expectations/state.rb +0 -31
  249. data/lib/lookout/expectations/state/warning.rb +0 -26
  250. data/lib/lookout/mock.rb +0 -20
  251. data/lib/lookout/mock/method.rb +0 -70
  252. data/lib/lookout/mock/method/arguments.rb +0 -33
  253. data/lib/lookout/mock/method/arguments/any.rb +0 -11
  254. data/lib/lookout/mock/method/arguments/anything.rb +0 -11
  255. data/lib/lookout/mock/method/arguments/list.rb +0 -15
  256. data/lib/lookout/mock/method/arguments/none.rb +0 -11
  257. data/lib/lookout/mock/method/arguments/one.rb +0 -11
  258. data/lib/lookout/mock/method/calls.rb +0 -11
  259. data/lib/lookout/mock/method/calls/class.rb +0 -21
  260. data/lib/lookout/mock/method/calls/exactly.rb +0 -28
  261. data/lib/lookout/mock/method/calls/instance.rb +0 -25
  262. data/lib/lookout/mock/method/calls/lower.rb +0 -22
  263. data/lib/lookout/mock/method/calls/upper.rb +0 -22
  264. data/lib/lookout/mock/methods.rb +0 -12
  265. data/lib/lookout/mock/object.rb +0 -12
  266. data/lib/lookout/object.rb +0 -11
  267. data/lib/lookout/output.rb +0 -21
  268. data/lib/lookout/rake/tasks.rb +0 -36
  269. data/lib/lookout/rake/tasks/gem.rb +0 -49
  270. data/lib/lookout/rake/tasks/tags.rb +0 -16
  271. data/lib/lookout/rake/tasks/test.rb +0 -46
  272. data/lib/lookout/rake/tasks/test/loader.rb +0 -22
  273. data/lib/lookout/recorder.rb +0 -45
  274. data/lib/lookout/recorder/not.rb +0 -11
  275. data/lib/lookout/recorder/tape.rb +0 -21
  276. data/lib/lookout/recorders.rb +0 -6
  277. data/lib/lookout/recorders/reception.rb +0 -47
  278. data/lib/lookout/recorders/state.rb +0 -35
  279. data/lib/lookout/result.rb +0 -13
  280. data/lib/lookout/results.rb +0 -25
  281. data/lib/lookout/results/error.rb +0 -18
  282. data/lib/lookout/results/error/exception.rb +0 -34
  283. data/lib/lookout/results/error/exception/backtrace.rb +0 -50
  284. data/lib/lookout/results/failure.rb +0 -16
  285. data/lib/lookout/results/failures.rb +0 -6
  286. data/lib/lookout/results/failures/behavior.rb +0 -5
  287. data/lib/lookout/results/failures/state.rb +0 -5
  288. data/lib/lookout/results/fulfilled.rb +0 -5
  289. data/lib/lookout/results/unsuccessful.rb +0 -31
  290. data/lib/lookout/runners.rb +0 -6
  291. data/lib/lookout/runners/console.rb +0 -49
  292. data/lib/lookout/runners/trackers.rb +0 -5
  293. data/lib/lookout/runners/trackers/failure.rb +0 -14
  294. data/lib/lookout/stub.rb +0 -18
  295. data/lib/lookout/stub/method.rb +0 -105
  296. data/lib/lookout/stub/methods.rb +0 -18
  297. data/lib/lookout/stub/object.rb +0 -11
  298. data/lib/lookout/ui.rb +0 -7
  299. data/lib/lookout/ui/console.rb +0 -19
  300. data/lib/lookout/ui/silent.rb +0 -9
  301. data/lib/lookout/version.rb +0 -5
  302. data/lib/lookout/warning.rb +0 -7
  303. data/lib/lookout/xml.rb +0 -17
  304. data/test/unit/lookout/diff/algorithms/difflib.rb +0 -56
  305. data/test/unit/lookout/diff/algorithms/difflib/position.rb +0 -92
  306. data/test/unit/lookout/diff/groups.rb +0 -102
  307. data/test/unit/lookout/diff/operations.rb +0 -22
  308. data/test/unit/lookout/diff/operations/delete.rb +0 -45
  309. data/test/unit/lookout/diff/operations/equal.rb +0 -45
  310. data/test/unit/lookout/diff/operations/insert.rb +0 -45
  311. data/test/unit/lookout/diff/operations/replace.rb +0 -45
  312. data/test/unit/lookout/diff/range.rb +0 -50
  313. data/test/unit/lookout/equality.rb +0 -113
  314. data/test/unit/lookout/expectation.rb +0 -47
  315. data/test/unit/lookout/expectations.rb +0 -36
  316. data/test/unit/lookout/expectations/behavior.rb +0 -35
  317. data/test/unit/lookout/expectations/line.rb +0 -29
  318. data/test/unit/lookout/expectations/state.rb +0 -29
  319. data/test/unit/lookout/mock/method.rb +0 -143
  320. data/test/unit/lookout/mock/method/arguments.rb +0 -57
  321. data/test/unit/lookout/mock/method/arguments/any.rb +0 -11
  322. data/test/unit/lookout/recorder.rb +0 -11
  323. data/test/unit/lookout/results/error/exception/backtrace.rb +0 -20
  324. data/test/unit/lookout/results/unsuccessful.rb +0 -9
  325. data/test/unit/lookout/runners/trackers/failure.rb +0 -30
  326. data/test/unit/lookout/stub/method.rb +0 -48
  327. data/test/unit/lookout/stub/methods.rb +0 -19
  328. data/test/unit/lookout/xml.rb +0 -55
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Represents expected {::String}s.
4
+ class Lookout::Expected::String < Lookout::Expected::Object
5
+ # @param [::String] actual
6
+ # @return [Difference::String, nil] A difference report between ACTUAL and
7
+ # {#expected} unless they’re `#==`
8
+ def difference(actual)
9
+ Lookout::Difference::String.new(actual, expected) unless expected == actual
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Represents expected {::Symbol}s. A Symbol that’s suffixed by “?” is
4
+ # considered to be a query to be invoked on the actual result. If such a
5
+ # symbol is prefixed by “not_”, the result of the query is inversed.
6
+ class Lookout::Expected::Symbol < Lookout::Expected::Object
7
+ def initialize(expected)
8
+ super
9
+ @negated, @query = /\A(?:(not)_)?(?:(.+\?)|.*)\z/m.match(expected.to_s)[1..2]
10
+ end
11
+
12
+ # @param [::Symbol, ::Object] actual
13
+ # @return [Difference::Symbol, nil] A difference report between _actual_ and
14
+ # {#expected} if {#expected} is a query and the result of the query doesn’t
15
+ # equal what’s expected, {super} otherwise
16
+ def difference(actual)
17
+ return super if not @query or Symbol === actual or actual.method(@query).arity != 0
18
+ Lookout::Difference::Symbol.new(actual, expected, @query, @negated) unless
19
+ (not not actual.send(@query)) ^ !!@negated
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Represents expected TrueClasses (of which `true` is the only instance).
4
+ class Lookout::Expected::TrueClass < Lookout::Expected::Object
5
+ # @param [Boolean] actual
6
+ # @return [Difference::Object] A difference report between ACTUAL and
7
+ # {#expected} unless ACTUAL is truthful
8
+ def difference(actual) super((not not actual)) end
9
+ end
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Non-failing inspection of objects. The inspection is {Lookout::Encode
4
+ # encoded} for output.
5
+ class Lookout::Inspect
6
+ # Non-failing inspection of OBJECT, using TYPE as a description of the
7
+ # type of object being inspected for failure outputs.
8
+ # @param [Object] object
9
+ # @param [String] type
10
+ Value(:object, :type)
11
+
12
+ class << self
13
+ # @param [Object, …] args
14
+ # @return [String] The inspections of ARGS, separated by “, ”’s
15
+ def args(*args)
16
+ args.map{ |e| Lookout::Inspect.new(e, 'argument') }.join(', ')
17
+ end
18
+ end
19
+
20
+ # @return [String] An UTF-8-encoded String inspection of the given object,
21
+ # generated by invoking #inspect on it, then {Lookout::Encode encoding} it
22
+ # as UTF-8, using #dump if any transcoding that may take place fails
23
+ def call
24
+ Lookout::Encode.new(inspection = inspect_object).call
25
+ rescue => e
26
+ '(cannot encode inspected %s for output: %s; %s)' %
27
+ [type,
28
+ Lookout::Exception.new(e),
29
+ begin
30
+ 'dumping instead: %s' % [inspection.dump]
31
+ rescue => inner
32
+ 'dumping also failed: %s' % Lookout::Exception.new(inner)
33
+ end]
34
+ end
35
+
36
+ alias to_s call
37
+
38
+ private
39
+
40
+ def inspect_object
41
+ String(object.inspect)
42
+ rescue => e
43
+ '(cannot inspect %s: %s)' % [type, Lookout::Exception.new(e)]
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Namespace for interfaces to Lookout.
4
+ module Lookout::Interfaces
5
+ end
@@ -0,0 +1,109 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Command-line interface to Lookout.
4
+ class Lookout::Interfaces::Commandline
5
+ # Processes ARGUMENTS, looking for options, running from the directory
6
+ # PWD and outputting results to IO.
7
+ #
8
+ # Valid arguments are
9
+ #
10
+ # * --: Stops processing of options, treating remaining arguments as files
11
+ # * -rFEATURE: Requires _FEATURE_
12
+ # * -lLINE: Only runs expectation closest before or on _LINE_
13
+ # * -c: Reports test coverage
14
+ # * FILENAME: Loads expectations from _FILENAME_, relative to PWD
15
+ #
16
+ # @param [Array<String>] arguments
17
+ # @param [String] pwd
18
+ # @param [IO] io
19
+ # @raise [ArgumentError] If an unknown option exists among ARGUMENTS
20
+ def initialize(arguments = ARGV, pwd = Dir.pwd, io = $stderr)
21
+ @pwd, @io = pwd, io
22
+ @line = nil
23
+ @files = []
24
+ @requires = []
25
+ @coverage = false
26
+ only_load = false
27
+ arguments.each do |argument|
28
+ if not only_load and argument == '--'
29
+ only_load = true
30
+ elsif not only_load and argument =~ /\A-r(.*)/
31
+ @requires << $1
32
+ elsif not only_load and argument =~ /\A-l(.*)/
33
+ @line = $1.to_i
34
+ elsif not only_load and argument == '-c'
35
+ @coverage = true
36
+ elsif not only_load and argument =~ /\A-/
37
+ raise ArgumentError, 'unknown option: %s' % argument
38
+ else
39
+ @files << [File.expand_path(argument, pwd), argument]
40
+ end
41
+ end
42
+ end
43
+
44
+ # Requires requested features, sets up coverage reporting, if desired, and
45
+ # checks the requested expectations. Coverage reporting will only be done if
46
+ # all expectations passed.
47
+ #
48
+ # @return [Boolean] True if all expectations passed
49
+ def call
50
+ require
51
+ coverage do
52
+ return false unless expectations
53
+ end
54
+ true
55
+ end
56
+
57
+ private
58
+
59
+ def require
60
+ @requires.each do |feature| super feature end
61
+ end
62
+
63
+ def coverage
64
+ return yield unless @coverage
65
+ require 'coverage'
66
+ Coverage.start
67
+ yield
68
+ Coverage.result.
69
+ select{ |file, _| file.start_with? @pwd }.
70
+ reject{ |file, _| files.assoc(file) }.
71
+ sort.
72
+ each do |file, counts|
73
+ counts.
74
+ each_cons(2).
75
+ with_index.
76
+ slice_before{ |(c1, c2), _| (c1 != 0 and c2 == 0) or (c1 == 0 and c2 != 0) }.
77
+ select{ |e| e.first.first.last == 0 }.
78
+ map{ |e| e.first.last+2..e.last.last+2 }.
79
+ each do |lines|
80
+ io.puts '%s:%s: not covered by test' %
81
+ [relativize(file),
82
+ lines.one? ? lines.begin : ('%d-%d' % [lines.begin, lines.end])]
83
+ end
84
+ end
85
+ end
86
+
87
+ def expectations
88
+ passed = true
89
+ @files.each do |expanded, file|
90
+ expectations = Lookout::Expectations.new(expanded)
91
+ if @line
92
+ target = nil.to_lookout_expected.expect(expanded, @line){
93
+ raise RuntimeError, 'line expectation not found: %s:%d' % [file, @line]
94
+ }
95
+ [(expectations.take_while{ |expect| expect <= target }.last or target)]
96
+ else
97
+ expectations
98
+ end.each do |expect|
99
+ result = expect.call
100
+ next if Lookout::Results::Success === result
101
+ passed = false
102
+ @io.puts relativize(result.to_s)
103
+ end
104
+ end
105
+ passed
106
+ end
107
+
108
+ def relativize(path) path.start_with?(@pwd) ? path[@pwd.length+1..-1] : path end
109
+ end
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Proxies objects that should be literally expected. This is achieved by
4
+ # overriding #to_lookout_expected to wrap the object in a
5
+ # {Lookout::Expected::Object} instead of using whatever #to_lookout_expected on
6
+ # the object would normally return. This allows us to expect a literal {Range}
7
+ # instead of allowing either a Range or an item included in the range.
8
+ class Lookout::Literal
9
+ # Proxies the EXPECTED value, allowing it to be expected literally.
10
+ # @param [Object] expected
11
+ Value(:expected)
12
+
13
+ def inspect; 'literal(%p)' % output end
14
+
15
+ # @return [Expected::Object] An expected value wrapper around the expected
16
+ # value
17
+ def to_lookout_expected; Lookout::Expected::Object.new(@expected) end
18
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Object that doesn’t respond to anything except for what’s been explicitly
4
+ # defined on it and throws a mock error whenever it receives a method call.
5
+ class Lookout::Mock < Lookout::Stub
6
+ def inspect; 'mock' end
7
+
8
+ private
9
+
10
+ # @param [Symbol] method
11
+ # @param [Object, …] args
12
+ # @raise [Reception::Error] When called, including the METHOD that was called
13
+ # and with what ARGS in the messaged and with the proper backtrace, making
14
+ # it easy to see where things went wrong
15
+ def method_missing(method, *args)
16
+ raise Lookout::Reception::Error.
17
+ from('%p#%s(%s)%s' % [self,
18
+ method,
19
+ Lookout::Inspect.args(*args),
20
+ block_given? ? '{ … }' : ''],
21
+ 1,
22
+ 0..0)
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Namespace for extensions to {::Object}. Implements the “to” and “not”
4
+ # keywords on objects that are used to build {Reception} expectations.
5
+ module Lookout::Object
6
+ end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # The “not” keyword on {::Object}s.
4
+ class Lookout::Object::Not
5
+ # Wraps OBJECT as a “not”.
6
+ # @param [::Object] object
7
+ def initialize(object) @object = object end
8
+
9
+ # Method for improving readability of “not” keyword set-up.
10
+ # @return [self]
11
+ def to; self end
12
+
13
+ # @return [Receive] A wrapper around the object that’ll set up a reception
14
+ # expectation on it
15
+ def receive; Receive.new(@object) end
16
+ end
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # The “not to receive” keywords on {::Object}s.
4
+ class Lookout::Object::Not::Receive < Lookout::Aphonic
5
+ # Stands in for OBJECT, allowing a {Reception} exception that expects the
6
+ # given method never to be called to be set up.
7
+ # @param [::Object] object
8
+ def initialize(object) @object = object end
9
+
10
+ private
11
+
12
+ # @param (see Reception#initialize)
13
+ # @return [Reception] A method reception expectation on the object that
14
+ # expects METHOD {Reception#never never} to be called
15
+ def method_missing(method, *args, &body)
16
+ Lookout::Reception.of(@object, method, *args, &body).never
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # The “to” keyword on {::Object}s.
4
+ class Lookout::Object::To
5
+ # Wraps OBJECT as a “to”.
6
+ # @param [::Object] object
7
+ def initialize(object) @object = object end
8
+
9
+ # @return [Receive] A wrapper around the object that’ll set up a reception
10
+ # expectation on it
11
+ def receive; Receive.new(@object) end
12
+ end
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # The “to receive” keywords on {::Object}s.
4
+ class Lookout::Object::To::Receive < Lookout::Aphonic
5
+ # Stands in for OBJECT, allowing a {Reception} exception that expects the
6
+ # given method to be called to be set up.
7
+ # @param [::Object] object
8
+ def initialize(object) @object = object end
9
+
10
+ private
11
+
12
+ # @param (see Reception#initialize)
13
+ # @return [Reception] A method reception expectation on the subject for
14
+ # METHOD with _args_, using _body_ as the method definition
15
+ def method_missing(method, *args, &body)
16
+ Lookout::Reception.of(@object, method, *args, &body)
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Output expectation proxy. Used to expect output on an IO object during the
4
+ # execution of an {Lookout::Expect expect block}.
5
+ class Lookout::Output
6
+ # Proxies the EXPECTED output.
7
+ # @param [String] expected
8
+ Value(:expected)
9
+
10
+ def inspect; 'output(%p)' % expected end
11
+
12
+ # @return [Enumerable<String>] An Enumerable over the formatted operations
13
+ # that would have to be applied to the actual output to get the expected
14
+ # output
15
+ def diff(other) expected.to_lookout_expected.difference(other.expected).diff end
16
+
17
+ # @return [Expected::Lookout::Output] A wrapper around the receiver, making
18
+ # it an expected value
19
+ def to_lookout_expected; Lookout::Expected::Lookout::Output.new(self) end
20
+ end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Namespace for Lookout plugins. Plugins should place their top-level
4
+ # class/module under this namespace. For example, the Rack plugin is named
5
+ # Lookout::Plugins::Rack.
6
+ module Lookout::Plugins
7
+ end
@@ -0,0 +1,128 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Method reception expectation builder. Method reception expectations can set
4
+ # expectations on what method is going to be called, with what arguments, and
5
+ # how many times it’s to take place.
6
+ class Lookout::Reception
7
+ Value(:object, :method, :range, :'*args', :'&body')
8
+ # @return [Range] The range of number of times that the method may be called
9
+ public :range
10
+
11
+ class << self
12
+ # @param [Symbol] method
13
+ # @param [Object, …] args
14
+ # @return [Lookout::Reception] A reception expectation expecting METHOD to
15
+ # be called on OBJECT with ARGS, using BODY as the method definition.
16
+ def of(object, method, *args, &body)
17
+ new(object, method, 1..1.0/0, *args, &body)
18
+ end
19
+
20
+ private :new
21
+ end
22
+
23
+ # This is an alias for {#exactly}(0).
24
+ def never; exactly(0) end
25
+
26
+ # This is an alias for {#at_most}(1).
27
+ def at_most_once; at_most(1) end
28
+
29
+ # This is an alias for {#exactly}(1).
30
+ def once; exactly(1) end
31
+
32
+ # This is an alias for {#at_least}(1).
33
+ def at_least_once; at_least(1) end
34
+
35
+ # This is an alias for {#exactly}(2).
36
+ def twice; exactly(2) end
37
+
38
+ # @param [Integer] times
39
+ # @return [Lookout::Reception] A reception expectation with a maximum number
40
+ # of TIMES that the method may be called
41
+ # @raise [ArgumentError] If TIMES < 1
42
+ def at_most(times)
43
+ limit('cannot convert upper reception limit to Integer: %s', times){ |i|
44
+ raise ArgumentError,
45
+ 'upper reception limit must be positive: %d < 1' % i if i < 1
46
+ 0..i
47
+ }
48
+ end
49
+
50
+ # @param [Integer] times
51
+ # @return [Lookout::Reception] A reception expectation with a minimum and
52
+ # maximum number of TIMES that the method may be called
53
+ # @raise [ArgumentError] If TIMES < 0
54
+ def exactly(times)
55
+ limit('cannot convert reception invocation count to Integer: %s', times){ |i|
56
+ raise ArgumentError,
57
+ 'expected reception count must be non-negative: %d < 0' % i if i < 0
58
+ i..i
59
+ }
60
+ end
61
+
62
+ # Sets the minimum number of times that the method may be called.
63
+ # @param [Integer] times
64
+ # @return [Lookout::Reception] A reception expectation with a minimum number
65
+ # of TIMES that the method may be called
66
+ # @raise [ArgumentError] If TIMES < 1
67
+ def at_least(times)
68
+ limit('cannot convert lower reception limit to Integer: %s', times){ |i|
69
+ raise ArgumentError,
70
+ 'lower reception limit must be positive: %d < 1' % i if i < 1
71
+ i..1.0/0
72
+ }
73
+ end
74
+
75
+ # @return [Expected::Lookout::Reception] A wrapper around the object that
76
+ # represents the expected reception of this method
77
+ def to_lookout_expected
78
+ Lookout::Expected::Lookout::Reception.new(self)
79
+ end
80
+
81
+ # @return [Proc] A block to be used by {Expected::Lookout::Reception#expect}
82
+ # that’ll set up a stub for the expected method reception that’ll check
83
+ # that the call count doesn’t exceed any upper limit imposed upon it and
84
+ # verify that any arguments are what they’re expected to be and then invoke
85
+ # BLOCK
86
+ def block(&block)
87
+ args, calls = Arguments.for(*@args), 0
88
+ reception, object, method, range, body = self, @object, @method, @range, @body || Nil
89
+ proc{
90
+ stub(object, method => proc{ |*mock_args, &mock_block|
91
+ calls += 1
92
+ raise Error.from(reception, calls, range) if calls > range.end
93
+ raise Arguments::Error,
94
+ '%s: unexpected arguments: [%s]≠[%s]' %
95
+ [reception, Arguments::List.new(*mock_args), args] unless
96
+ args =~ mock_args
97
+ body.call(*mock_args, &mock_block)
98
+ }, &block) if block
99
+ calls
100
+ }
101
+ end
102
+
103
+ # @return A String consisting of the inspection of the object, followed by
104
+ # either ‘.’ or ‘#’ depending on whether the object is a Class or not, and
105
+ # the method name
106
+ def to_s
107
+ [Lookout::Inspect.new(object, 'object'),
108
+ Class === object ? '.' : '#',
109
+ method].join('')
110
+ end
111
+
112
+ private
113
+
114
+ def limit(format, times)
115
+ self.class.send(:new,
116
+ object,
117
+ method,
118
+ yield(begin
119
+ times.to_int
120
+ rescue => e
121
+ raise e, format % e
122
+ end),
123
+ *args,
124
+ &body)
125
+ end
126
+
127
+ Nil = proc{ Lookout::Stub.new }
128
+ end