Module: CmdLineTest::Macros
- Included in:
- Test::Unit::TestCase
- Defined in:
- lib/cmd_line_test.rb
Overview
InstanceMethods
Instance Method Summary collapse
Instance Method Details
#run_with_options(options, name = nil, &block) ⇒ Object
37 38 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 |
# File 'lib/cmd_line_test.rb', line 37 def (, name = nil, &block) raise RuntimeError, "Command is not defined: 'run_command_line_as()' must be called first." unless self.cli_block test_name = name || "after running with options '#{.join(', ')}'" generate_test test_name do with_ARGV_set_to 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 #It used to be $stdout = StringIO.new(...), but it does not work well with rdebug class <<$stdout alias_method :original_write, :write def write(*s) #original_write(s) $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. ensure class <<$stdout remove_method :write, :original_write end end instance_eval(&block) end end end |