Class: NanDoc::MockPrompt
Instance Method Summary
collapse
#method_name_to_record, #recordings, #story
Constructor Details
#initialize(test_case = nil) ⇒ MockPrompt
Returns a new instance of MockPrompt.
22
23
24
25
26
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 22
def initialize test_case=nil
@last_both = @last_out = @last_err = nil
@record = false
@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.
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 32
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
45
46
47
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 45
def cosmetic_ellipsis str
@record && @recordings.add(:cosmetic_ellipsis, str)
end
|
#enter2(cmd) ⇒ Object
49
50
51
52
53
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 49
def enter2 cmd
@last_both = nil
@record && @recordings.add(:command, cmd)
@last_out, @last_err = sopen2(cmd)
end
|
#err(string, opts = {}) ⇒ Object
55
56
57
58
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 55
def err string, opts={}
exp = reindent string
assert_equal_strings exp, @last_err, opts
end
|
#note(*a, &b) ⇒ Object
60
61
62
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 60
def note(*a,&b)
@record && @recordings.note(*a, &b)
end
|
#out(string, opts = {}) ⇒ Object
64
65
66
67
68
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 64
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
70
71
72
73
74
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 70
def out_begin exp_begin
@exp_begin = reindent(exp_begin)
@record && @recordings.add(:out_begin, @exp_begin)
end
|
#out_end(exp_end, opts = {}) ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 76
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
86
87
88
89
90
91
92
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 86
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
94
95
96
97
|
# File 'lib/nandoc/spec-doc/mock-prompt.rb', line 94
def record_stop
@record = false
@recordings = nil
end
|