Class: AppTester::Test Abstract

Inherits:
Core
  • Object
show all
Includes:
RSpec::Matchers
Defined in:
lib/app-tester/test.rb

Overview

This class is abstract.

Main object that hold all the data needed to run a test

Defined Under Namespace

Classes: BacktraceObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = { }, &block) ⇒ Test

Returns a new instance of Test.



23
24
25
26
27
28
29
# 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

Instance Attribute Details

#connectionFaraday::Connection (readonly)

connection handler

Returns:

  • (Faraday::Connection)

    the current value of connection



11
12
13
# File 'lib/app-tester/test.rb', line 11

def connection
  @connection
end

#nameString (readonly)

name for this test

Returns:

  • (String)

    the current value of name



11
12
13
# File 'lib/app-tester/test.rb', line 11

def name
  @name
end

#optionsAppTester::Options (readonly)

the options that the user defined when he created the framework

Returns:



11
12
13
# File 'lib/app-tester/test.rb', line 11

def options
  @options
end

#parserAppTester::Parser (readonly)

user selected options on command line

Returns:



11
12
13
# File 'lib/app-tester/test.rb', line 11

def parser
  @parser
end

#self_before_instance_eval=(value) ⇒ Object (writeonly)

Sets the attribute self_before_instance_eval

Parameters:

  • value

    the value to set the attribute self_before_instance_eval to.



19
20
21
# File 'lib/app-tester/test.rb', line 19

def self_before_instance_eval=(value)
  @self_before_instance_eval = value
end

#sourceProc (readonly)

block of code that holds the test to be executed

Returns:

  • (Proc)

    the current value of source



11
12
13
# File 'lib/app-tester/test.rb', line 11

def source
  @source
end

Instance Method Details

#argumentsObject



36
37
38
# File 'lib/app-tester/test.rb', line 36

def arguments
  @parser.options
end

#get(url = "", parameters = {}) ⇒ Object



40
41
42
# File 'lib/app-tester/test.rb', line 40

def get url="", parameters={}
  connection.get url, parameters
end

#post(url = "", parameters = {}) ⇒ Object



44
45
46
# File 'lib/app-tester/test.rb', line 44

def post url="", parameters={}
  connection.post url, parameters
end

#run(arguments = ARGV) ⇒ Object

Run test



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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| ... } ⇒ Object

Defines command options (arguments) that this test supports

Yields:



32
33
34
# File 'lib/app-tester/test.rb', line 32

def set_cmd_options
  yield(@parser) if block_given?
end