wip-runner 0.3.4 → 0.4.0

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.
@@ -1,81 +0,0 @@
1
- module WIP
2
- module Runner::Spec
3
- module Helpers::IOHelpers
4
- def io
5
- @io ||= CustomHighLine.new
6
- end
7
-
8
- def simulate(pairs = nil)
9
- unless pairs.nil?
10
- @simulated = pairs.inject(@simulated || {}) do |memo, (q, a)|
11
- memo[q] = a ; memo
12
- end
13
- end
14
-
15
- if block_given?
16
- begin
17
- originput = io.instance_variable_get(:@input)
18
- simulator = Simulator.new(@simulated.values, (@simulated.keys == ['*']))
19
- io.instance_variable_set(:@input, simulator)
20
-
21
- @simulated.keys.each do |question|
22
- # NOTE: the "|default|" is stripped because that is added
23
- # later by the Question instance, in time for a call to #say.
24
- if question.is_a?(Array)
25
- expect(io).to receive(:ask)
26
- .with(*question)
27
- .and_call_original
28
- else
29
- question = question.sub(/:\s\|.*\Z/, ': ')
30
- expect(io).to receive(:ask)
31
- .with(question)
32
- .and_call_original
33
- end unless question == '*'
34
- end
35
-
36
- yield
37
- ensure
38
- io.instance_variable_set(:@input, originput)
39
- end
40
- end
41
- end
42
-
43
- private
44
-
45
- class CustomHighLine < HighLine
46
- # Strips the same-line indicating, trailing space from questions in order
47
- # to print the newline in specs (that would come from user input).
48
- def ask(question, answer_type = String, &block)
49
- super("#{question.rstrip}", answer_type, &block)
50
- end
51
-
52
- # Strips double spaces between question and default.
53
- def say(statement)
54
- # puts statement.to_s.inspect
55
- super statement.to_s.gsub(/:\s{2,}\|/, ': |')
56
- end
57
-
58
- # Strips formatting for specs.
59
- def color(string, *colors)
60
- string
61
- end
62
- end
63
-
64
- # adapted from https://gist.github.com/194554
65
- class Simulator
66
- def initialize(values, all = false)
67
- @values = values.map { |s| s.nil? ? '' : s }
68
- @all = all
69
- end
70
-
71
- def gets
72
- @all ? @values.first : @values.shift
73
- end
74
-
75
- def eof?
76
- false
77
- end
78
- end
79
- end
80
- end
81
- end