Module: TestDsl

### Home Classes Methods

### In Files

- lib/debugger/test/test_dsl.rb

### Namespace

- MODULE TestDsl::ClassMethods
- MODULE TestDsl::Shared

### Methods

- ::included
- #binding
- #breakpoint
- #change_line_in_file
- #check_output
- #check_output_doesnt_include
- #check_output_includes
- #context
- #debug_file
- #enter
- #force_set_const
- #interface
- #pi
- #state
- #temporary_change_hash_value
- #temporary_change_method_value
- #temporary_set_const

### Included Modules

- TestDsl::Shared

### Class/Module Index

Quicksearch

- Debugger
- Debugger::AddBreakpoint
- Debugger::Breakpoint
- Debugger::Context
- Debugger::ContinueCommand
- Debugger::DeleteBreakpointCommand
- Debugger::FinishCommand
- Debugger::HelpCommand
- Debugger::IRBCommand
- Debugger::InfoCommand
- Debugger::JumpCommand
- Debugger::KillCommand
- Debugger::ListCommand
- Debugger::LocalInterface
- Debugger::LocalInterface::Debugger
- Debugger::MethodCommand
- Debugger::MethodSigCommand
- Debugger::NextCommand
- Debugger::ParseFunctions
- Debugger::Processor
- Debugger::QuitCommand
- Debugger::ReloadCommand
- Debugger::SetCommand
- Debugger::ShowCommand
- Debugger::SkipCommand
- Debugger::SourceCommand
- Debugger::StepCommand
- Debugger::VarClassVarCommand
- Debugger::VarInheritCommand
- Debugger::VarLocalCommand
- Debugger::WhereCommand
- Printers
- Printers::Base
- Printers::Base::MissedArgument
- Printers::Base::MissedPath
- Printers::Plain
- Mocha
- Mocha::Call
- Mocha::Expectation
- Mocha::Mock
- MiniTest
- MiniTest::Assertions
- MiniTest::Expectations
- TestDsl
- TestDsl::ClassMethods
- TestDsl::Shared
- Kernel
- Module
- PrinterHelpers
- TestInterface

No matching classes.

# TestDsl

### Public Class Methods

included(base) click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 9
    def self.included(base)
      base.class_eval do
        extend ClassMethods
        before do
          Debugger.interface = TestInterface.new
          Debugger.handler.display.clear
        end
        after do
          Debugger.handler.display.clear
        end
      end
    end

### Public Instance Methods

binding() click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 117
    def binding
      context.frame_binding(state.frame_pos)
    end

breakpoint() click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 121
    def breakpoint
      Debugger.breakpoints.first
    end

change_line_in_file(file, line, new_line_content) click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 130
    def change_line_in_file(file, line, new_line_content)
      old_content = File.read(file)
      new_content = old_content.split("\n").tap { |c| c[line - 1] = new_line_content }.join("\n")
      File.open(file, 'w') { |f| f.write(new_content) }
    end

check_output(check_method, *args) click to toggle source

Checks the output of the debugger. By default it checks output queue of the current interface, but you can check again any queue by providing it as a second argument.

Usage:

    enter 'break 4', 'cont'
    debug("ex1")
    check_output "Breakpoint 1 at #{fullpath('ex1')}:4"

    # File lib/debugger/test/test_dsl.rb, line 90
    def check_output(check_method, *args)
      queue = args.last.is_a?(String) || args.last.is_a?(Regexp) ? interface.output_queue : args.pop
      queue_messages = queue.map(&:strip)
      messages = Array(args).map { |msg| msg.is_a?(String) ? msg.strip : msg }
      queue_messages.send(check_method, messages)
    end

check_output_doesnt_include(*args) click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 101
    def check_output_doesnt_include(*args)
      check_output :wont_include_in_order, *args
    end

check_output_includes(*args) click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 97
    def check_output_includes(*args)
      check_output :must_include_in_order, *args
    end

context() click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 113
    def context
      state.context
    end

debug_file(filename, &block) click to toggle source

Runs a debugger with the provided basename for a file. The file should be placed to the test/new/examples dir.

You also can specify block, which will be executed when Processor extracts all the commands from the input queue. You can use it e.g. for making asserts for the current test. If you specified the block, and it never was executed, the test will fail.

Usage:

    debug "ex1" # ex1 should be placed in test/new/examples/ex1.rb

    enter 'b 4', 'cont'
    debug("ex1") { state.line.must_equal 4 } # It will be executed after running 'cont' and stopping at the breakpoint

    # File lib/debugger/test/test_dsl.rb, line 54
    def debug_file(filename, &block)
      is_test_block_called = false
      debug_completed = false
      exception = nil
      Debugger.stubs(:run_init_script)
      if block
        interface.test_block = lambda do
          is_test_block_called = true
          # We need to store exception and reraise it after completing debugging, because
          # Debugger will swallow any exceptions, so e.g. our failed assertions will be ignored
          begin
            block.call
          rescue Exception => e
            exception = e
            raise e
          end
        end
      end
      Debugger.start do
        Debugger.debug_load(fullpath(filename))
        debug_completed = true
      end
      flunk "Debug block was not completed" unless debug_completed
      flunk "test block is provided, but not called" if block && !is_test_block_called
      raise exception if exception
    end

enter(*messages) click to toggle source

Adds commands to the input queue, so they will be retrieved by Processor later. I.e. it emulates user's input.

If a command is a Proc object, it will be executed before retrieving by Processor. May be handy when you need build a command depending on the current context/state.

Usage:

    enter 'b 12'
    enter 'b 12', 'cont'
    enter ['b 12', 'cont']
    enter 'b 12', ->{"disable #{breakpoint.id}"}, 'cont'

    # File lib/debugger/test/test_dsl.rb, line 35
    def enter(*messages)
      messages = messages.first.is_a?(Array) ? messages.first : messages
      interface.input_queue.concat(messages)
    end

force_set_const(klass, const, value) click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 125
    def force_set_const(klass, const, value)
      klass.send(:remove_const, const) if klass.const_defined?(const)
      klass.const_set(const, value)
    end

interface() click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 105
    def interface
      Debugger.handler.interface
    end

pi() click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 168
    def pi
      puts
      puts "Output Queue:"
      puts interface.output_queue.join("")
      puts
      puts "Error Queue:"
      puts interface.error_queue.join("")
      puts
      puts "Confirm Queue:"
      puts interface.confirm_queue.join("")
      puts
      puts "Print Queue:"
      puts interface.print_queue.join("")
      puts
    end

state() click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 109
    def state
      $rdebug_state
    end

temporary_change_hash_value(item, key, value) click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 144
    def temporary_change_hash_value(item, key, value)
      old_value = item[key]
      begin
        item[key] = value
        yield
      ensure
        item[key] = old_value
      end
    end

temporary_change_method_value(item, method, value) click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 136
    def temporary_change_method_value(item, method, value)
      old = item.send(method)
      item.send("#{method}=", value)
      yield
    ensure
      item.send("#{method}=", old)
    end

temporary_set_const(klass, const, value) click to toggle source

    # File lib/debugger/test/test_dsl.rb, line 154
    def temporary_set_const(klass, const, value)
      old_value = klass.const_defined?(const) ? klass.const_get(const) : :__undefined__
      begin
        force_set_const(klass, const, value)
        yield
      ensure
        if old_value == :__undefined__
          klass.send(:remove_const, const)
        else
          force_set_const(klass, const, old_value)
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.