39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/cmd_line_test.rb', line 39
def run_with_argv(*args, &block)
raise RuntimeError, "Command is not defined: 'run_command_line_as()' must be called first." unless
self.cli_block
options = args.last.is_a?(Hash) ? args.pop : {}
argv = args
test_name = options[:name] || "after running with arguments '#{argv.join(', ')}'"
generate_test test_name do
with_ARGV_set_to *argv do
begin
self.class.cli_exit_status = 0
self.class.cli_error = ""
self.class.cli_error_stack = ""
self.class.cli_output = ""
$test_class = self.class
class <<$stdout
alias_method :original_write, :write
def write(*s)
original_write(s) if $test_class.show_output
$test_class.cli_output << s.to_s if $test_class.cli_output
end
end
execute
rescue SystemExit => exit_error
self.class.cli_exit_status = exit_error.status
rescue Exception => error
self.class.cli_error_stack = error.backtrace.join("\n")
self.class.cli_error = error.message
ensure
class <<$stdout
remove_method :write, :original_write
end
end
instance_eval(&block)
end
end
end
|