Module: AppTester Abstract

Defined in:
lib/app-tester.rb,
lib/app-tester/core.rb,
lib/app-tester/test.rb,
lib/app-tester/timer.rb,
lib/app-tester/utils.rb,
lib/app-tester/parser.rb,
lib/app-tester/checker.rb,
lib/app-tester/options.rb,
lib/app-tester/connection.rb,
lib/app-tester/exceptions.rb,
lib/app-tester/utils/colors.rb,
lib/app-tester/utils/strings.rb

Overview

This module is abstract.

AppTester main module and namespace

Defined Under Namespace

Modules: Checker, Error, Utils Classes: Connection, Core, Options, Parser, Test, Timer

Constant Summary collapse

VERSION =
'0.1.2.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/app-tester.rb', line 13

def options
  @options
end

.testsObject (readonly)

Returns the value of attribute tests.



14
15
16
# File 'lib/app-tester.rb', line 14

def tests
  @tests
end

Class Method Details

.define_test(name = "") { ... } ⇒ AppTester::Test, NilClass

Create a new test object

Examples:

Define a new test

apptester.define_test "my test" do |cmd_options, connection|
  result = connection.get do |request|
    request.url "/"
  end
  AppTester::Checker.status result

  p AppTester::Utils.file_to_array cmd_options[:file] unless cmd_options[:file].nil?
end

Parameters:

  • name (String) (defaults to: "")

    name for this test

Yields:

  • code snippet that will be executed when AppTester::Test.run is issued

Returns:

  • (AppTester::Test)

    if the creation of this test was successfull with a block

  • (NilClass)

    if the creation of this test was successfull with no block

Raises:



55
56
57
58
59
60
61
62
63
# File 'lib/app-tester.rb', line 55

def define_test name="", &block
  if name.empty?
    raise AppTester::Error::NameEmptyError, "Attempted to define a test without a name"
  end
  block = Proc.new{} unless block_given?
  test = AppTester::Test.new(name, @options, &block)
  @tests.push title: name, test: test
  test
end

.get_test(name) ⇒ AppTester::Test

Retrieve a test by name

Examples:

Get a pre-defined test

apptester = AppTester.new do |options|
  options.add_environment :github => "https://github.com"
  options.add_environment :google => "https://google.com"
  options.default_environment = :google
end

apptester.define_test "my test"
my_test = apptester.get_test "my test"

Parameters:

  • name (String)

    test to retrieve

Returns:

Raises:



82
83
84
85
86
87
88
# File 'lib/app-tester.rb', line 82

def get_test name
  entry = @tests.find { |t| t[:title] == name }
  if entry.nil?
    raise AppTester::Error::TestNotFoundError, "Could not find test #{name}" 
  end
  entry[:test]
end

.new {|options| ... } ⇒ AppTester

Construct AppTester framework

Examples:

Start AppTester handler

apptester = AppTester.new do |options|
  options.add_environment :github => "https://github.com"
  options.add_environment :google => "https://google.com"
  options.default_environment = :google
  options.log_connection = true
end

Yields:

  • (options)

    Gives the user the possibility to set generic options for the framework

Yield Parameters:

Returns:



28
29
30
31
32
33
# File 'lib/app-tester.rb', line 28

def new
  @tests = []
  @options = AppTester::Options.new
  yield @options if block_given?
  self
end

.run_allObject

Run all tests

Raises:

  • (Faraday::Error::ConnectionFailed)

    if there was a problem connecting to the selected server



152
153
154
155
156
# File 'lib/app-tester.rb', line 152

def run_all
  @tests.each do |test|
    run_test test[:title]
  end
end

.run_test(name, arguments = ARGV) ⇒ AppTester::Test

Run a test

Examples:

Run a test

apptester = AppTester.new do |options|
  options.add_environment :github => "https://github.com"
  options.add_environment :google => "https://google.com"
  options.default_environment = :google
end
apptester.define_test "my test" do |cmd_options, connection|
  result = connection.get do |request|
    request.url "/"
  end
  AppTester::Checker.status result

  p AppTester::Utils.file_to_array cmd_options[:file] unless cmd_options[:file].nil?
end

my_test = apptester.run_test

Parameters:

  • name (String)

    test name that we want to run

  • arguments (Array) (defaults to: ARGV)

    overwrite ARGV array with a custom one, useful for unit tests

Returns:

Raises:



143
144
145
146
147
# File 'lib/app-tester.rb', line 143

def run_test name, arguments=ARGV
  the_test = get_test(name)
  the_test.run(arguments)
  the_test
end

.set_options_for(name) {|options_parser| ... } ⇒ AppTester::Test

Defines command line options for a given test

Examples:

Set options for a test

apptester = AppTester.new do |options|
  options.add_environment :github => "https://github.com"
  options.add_environment :google => "https://google.com"
  options.default_environment = :google
end

apptester.define_test "my test"

apptester.set_options_for "my test" do |options_parser|
  options_parser.set_option(:file, "-f", "--file FILE", "File to load")
end

Parameters:

  • name (String)

    test name to which we want to define the command line options

Yields:

  • (options_parser)

    set the command line options for this test

Yield Parameters:

Returns:



111
112
113
114
115
# File 'lib/app-tester.rb', line 111

def set_options_for name
  test = get_test name
  yield test.parser
  test
end