Class: NanDoc::MockPrompt
Instance Attribute Summary collapse
Instance Method Summary
collapse
#method_name_to_record, #recordings, #story
Constructor Details
#initialize(test_case = nil) ⇒ MockPrompt
Returns a new instance of MockPrompt.
16
17
18
19
20
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 16
def initialize test_case=nil
@last_both = @last_out = @last_err = nil
@record = false
@test_case = test_case
end
|
Instance Attribute Details
#test_case ⇒ Object
Returns the value of attribute test_case.
113
114
115
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 113
def test_case
@test_case
end
|
Instance Method Details
#cd(actual_basedir, specdoc_subdir = nil, &block) ⇒ Object
wrapper around FileUtils cd that takes block form the tail portion of the path if any that you want to go documented with SpecDoc is the second arg. The first arg if any is the part of the path that will go undocumented.
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 26
def cd actual_basedir, specdoc_subdir=nil, &block
actual_path = File.join( * [actual_basedir, specdoc_subdir].compact)
if specdoc_subdir && @record
@recordings.add(:cd, specdoc_subdir)
end
FileUtils.cd(actual_path) do
block.call(self)
end
if specdoc_subdir && @record
@recordings.add(:cd_end)
end
end
|
#cosmetic_ellipsis(str) ⇒ Object
39
40
41
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 39
def cosmetic_ellipsis str
@record && @recordings.add(:cosmetic_ellipsis, str)
end
|
#enter2(cmd) ⇒ Object
43
44
45
46
47
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 43
def enter2 cmd
@last_both = nil
@record && @recordings.add(:command, cmd)
@last_out, @last_err = sopen2(cmd)
end
|
#err(string, opts = {}) ⇒ Object
49
50
51
52
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 49
def err string, opts={}
exp = reindent string
assert_equal_strings exp, @last_err, opts
end
|
#note(*a, &b) ⇒ Object
54
55
56
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 54
def note(*a,&b)
@record && @recordings.note(*a, &b)
end
|
#out(string, opts = {}) ⇒ Object
58
59
60
61
62
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 58
def out string, opts={}
exp = reindent(string)
@record && @recordings.add(:out, exp)
assert_equal_strings exp, @last_out, opts
end
|
#out_begin(exp_begin) ⇒ Object
64
65
66
67
68
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 64
def out_begin exp_begin
@exp_begin = reindent(exp_begin)
@record && @recordings.add(:out_begin, @exp_begin)
end
|
#out_end(exp_end, opts = {}) ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 70
def out_end exp_end, opts={}
@exp_begin or fail("no begin found for end")
exp_end2 = reindent(exp_end)
@record && @recordings.add(:out_end, exp_end2)
act_begin = @last_out[0..@exp_begin.length-1]
assert_equal_strings @exp_begin, act_begin, opts
act_end = @last_out[(exp_end2.length * -1)..-1]
assert_equal_strings exp_end2, act_end, opts
end
|
#record(story_name = nil) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 80
def record story_name=nil
method = method_name_to_record(caller)
@record = true
recordings
@recordings.add(:method, method)
@recordings.add(:story, story_name) if story_name
end
|
#record_stop ⇒ Object
88
89
90
91
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 88
def record_stop
@record = false
@recordings = nil
end
|