Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. require "spec_helper"
  2.  
  3. RSpec.describe Scrawl do
  4. let(:inputs) { [input] }
  5. let(:scrawl) { described_class.new(*inputs) }
  6.  
  7. shared_context "for single input" do
  8. let(:input) do
  9. { "a" => "a" }
  10. end
  11.  
  12. let(:output) do
  13. "a=a"
  14. end
  15. end
  16.  
  17. shared_context "for multiple input" do
  18. let(:input) do
  19. { "a" => "a", "b" => "b" }
  20. end
  21.  
  22. let(:output) do
  23. "a=a b=b"
  24. end
  25. end
  26.  
  27. shared_examples "for output" do
  28. it "joins the key value together with an =" do
  29. expect(inspect).to eq(output)
  30. end
  31. end
  32.  
  33. describe "#inspect" do
  34. context "with single input" do
  35. context "that is a string" do
  36. let(:input) do
  37. { "a" => "a" }
  38. end
  39. let(:output) do
  40. "a=a"
  41. end
  42.  
  43. include_examples "for output"
  44. end
  45.  
  46. context "that is a nil" do
  47. let(:input) do
  48. { "a" => nil }
  49. end
  50. let(:output) do
  51.  
  52. end
  53.  
  54. include_examples "for output"
  55. end
  56.  
  57. context "that is a numeric" do
  58. let(:input) do
  59. { "a" => 1 }
  60. end
  61. let(:output) do
  62.  
  63. end
  64.  
  65. include_examples "for output"
  66. end
  67.  
  68. context "that is a lambda" do
  69. let(:input) do
  70. { "a" => -> { "a" + "a" } }
  71. end
  72. let(:output) do
  73.  
  74. end
  75.  
  76. include_examples "for output"
  77. end
  78.  
  79. context "that is a empty hash" do
  80. let(:output) do
  81. { "a" => {} }
  82. end
  83.  
  84. include_examples "for output"
  85. end
  86.  
  87. context "that is a hash" do
  88. let(:input) do
  89. { "a" => { "a" => "a" } }
  90. end
  91. let(:output) do
  92.  
  93. end
  94.  
  95. include_examples "for output"
  96. end
  97.  
  98. context "that is a empty array" do
  99. let(:input) do
  100. { "a" => [] }
  101. end
  102. let(:output) do
  103.  
  104. end
  105.  
  106. include_examples "for output"
  107. end
  108.  
  109. context "that is a array" do
  110. let(:input) do
  111. { "a" => ["b", "c"] }
  112. end
  113. let(:output) do
  114.  
  115. end
  116.  
  117. include_examples "for output"
  118. end
  119.  
  120. context "that is a scrawl" do
  121. let(:input) do
  122. { "a" => Scrawl.new({ "a" => "a" }) }
  123. end
  124. let(:output) do
  125.  
  126. end
  127.  
  128. include_examples "for output"
  129. end
  130. end
  131.  
  132. context "with multiple input" do
  133. context "that are strings" do
  134. let(:input) do
  135. { "a" => "a", "b" => "b" }
  136. end
  137. let(:output) do
  138. "a=a"
  139. end
  140.  
  141. include_examples "for output"
  142. end
  143.  
  144. context "that are nils" do
  145. let(:input) do
  146. { "a" => nil, "b" => nil }
  147. end
  148. let(:output) do
  149.  
  150. end
  151.  
  152. include_examples "for output"
  153. end
  154.  
  155. context "that are numerics" do
  156. let(:input) do
  157. { "a" => 1, "b" => 2 }
  158. end
  159. let(:output) do
  160.  
  161. end
  162.  
  163. include_examples "for output"
  164. end
  165.  
  166. context "that are lambdas" do
  167. let(:input) do
  168. { "a" => -> { "a" + "a" }, "b" => -> { "b" + "b" } }
  169. end
  170. let(:output) do
  171.  
  172. end
  173.  
  174. include_examples "for output"
  175. end
  176.  
  177. context "that are empty hashs" do
  178. let(:output) do
  179. { "a" => {}, "b" => {} }
  180. end
  181.  
  182. include_examples "for output"
  183. end
  184.  
  185. context "that are hashs" do
  186. let(:input) do
  187. { "a" => { "a" => "a" }, "b" => { "b" => "b" } }
  188. end
  189. let(:output) do
  190.  
  191. end
  192.  
  193. include_examples "for output"
  194. end
  195.  
  196. context "that are empty arrays" do
  197. let(:input) do
  198. { "a" => [], "b" => [] }
  199. end
  200. let(:output) do
  201.  
  202. end
  203.  
  204. include_examples "for output"
  205. end
  206.  
  207. context "that are arrays" do
  208. let(:input) do
  209. { "a" => ["b", "c"], "b" => ["e", "f"] }
  210. end
  211. let(:output) do
  212.  
  213. end
  214.  
  215. include_examples "for output"
  216. end
  217.  
  218. context "that are scrawls" do
  219. let(:input) do
  220. { "a" => Scrawl.new({ "a" => "a" }, "b" => Scrawl.new({ "b" => "b" }) }
  221. end
  222. let(:output) do
  223.  
  224. end
  225.  
  226. include_examples "for output"
  227. end
  228. end
  229. end
  230.  
  231. describe "#to_s" do
  232. it "uses inspect with no namespace" do
  233. expect(scrawl).to receive(:inspect).with(nil)
  234. scrawl.to_s
  235. end
  236. end
  237.  
  238. # describe "#tree" do
  239. # let(:tree) { scrawl.tree }
  240. #
  241. # it "returns the internal tree" do
  242. # expect(tree).to eq(internal_tree)
  243. # end
  244. # end
  245. #
  246. # describe "#to_h" do
  247. # let(:to_h) { scrawl.to_h }
  248. #
  249. # it "returns the internal tree" do
  250. # expect(to_h).to eq(internal_tree)
  251. # end
  252. # end
  253. #
  254. # describe "#to_hash" do
  255. # let(:to_hash) { scrawl.to_hash }
  256. #
  257. # it "returns the internal tree" do
  258. # expect(to_hash).to eq(internal_tree)
  259. # end
  260. # end
  261. #
  262. # describe "#=="
  263. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement