class AppTester::Test

@abstract Main object that hold all the data needed to run a test @attr_reader parser [AppTester::Parser] user selected options on command line @attr_reader name [String] name for this test @attr_reader source [Proc] block of code that holds the test to be executed @attr_reader connection [Faraday::Connection] connection handler @attr_reader options [AppTester::Options] the options that the user defined when he created the framework

Constants

BacktraceObject

Attributes

connection[R]
name[R]
options[R]
parser[R]
self_before_instance_eval[W]
source[R]

Public Class Methods

new(name, options={ }) click to toggle source
# File lib/app-tester/test.rb, line 23
def initialize name, options={ }, &block
  @name = name
  @options = options
  @source = block
  @parser = AppTester::Parser.new(options)
  @parser.banner = @name
end

Public Instance Methods

arguments() click to toggle source
# File lib/app-tester/test.rb, line 36
def arguments
  @parser.options
end
get(url="", parameters={}) click to toggle source
# File lib/app-tester/test.rb, line 40
def get url="", parameters={}
  connection.get url, parameters
end
post(url="", parameters={}) click to toggle source
# File lib/app-tester/test.rb, line 44
def post url="", parameters={}
  connection.post url, parameters
end
run(arguments=ARGV) click to toggle source

Run test

# File lib/app-tester/test.rb, line 51
def run(arguments=ARGV)
  append_help_option
  @parser.parse!(arguments)
  @parser.check_mandatory_arguments
  @connection = AppTester::Connection.new @parser.options[:server], @options
  @self_before_instance_eval = eval "self", @source.binding
  begin
    self.instance_eval &@source
  rescue RSpec::Expectations::ExpectationNotMetError => excp
    unless defined? IS_RSPEC
      # Extract and create a backtrace object
      backtrace = excp.backtrace.map { |x|
        x.match(/^(.+?):(\d+)(|:in `(.+)')$/);
        BacktraceObject.new($1, $2, $4)
      }
      line_number = 0
      # Because the correct line number is not the first on the error stack we need to iterate it and find what we want
      backtrace.each do |backtrace_entry|
        line_number = backtrace_entry.line_number if backtrace_entry.where == "block in <main>"
      end
      puts "#{AppTester::Utils::Strings::FAILED} #{excp.message} on line #{line_number}"
    end
  end
end
set_cmd_options() { |parser| ... } click to toggle source

Defines command options (arguments) that this test supports

# File lib/app-tester/test.rb, line 32
def set_cmd_options
  yield(@parser) if block_given?
end

Private Instance Methods

append_help_option() click to toggle source

Appends helper option. This options is always available on every test

# File lib/app-tester/test.rb, line 79
def append_help_option
  @parser.set_option(nil, "-h", "--help", "Show this message") do
    puts @parser
    exit
  end
end