Module: Omnitest

Extended by:
Core::Configurable, Delegators, RunAction
Includes:
Core::Logger, Core::Logging
Defined in:
lib/omnitest/run_action.rb,
yard_macros.rb,
lib/omnitest.rb,
lib/omnitest/cli.rb,
lib/omnitest/command.rb,
lib/omnitest/project.rb,
lib/omnitest/version.rb,
lib/omnitest/workflow.rb,
lib/omnitest/reporters.rb,
lib/omnitest/project_set.rb,
lib/omnitest/command/list.rb,
lib/omnitest/command/show.rb,
lib/omnitest/command/task.rb,
lib/omnitest/command/test.rb,
lib/omnitest/configuration.rb,
lib/omnitest/project_logger.rb,
lib/omnitest/command/generate.rb,
lib/omnitest/command/project_action.rb,
lib/omnitest/command/scenario_action.rb,
lib/omnitest/documentation_generator.rb,
lib/omnitest/reporters/hash_reporter.rb,
lib/omnitest/reporters/json_reporter.rb,
lib/omnitest/reporters/yaml_reporter.rb,
lib/omnitest/command/generators/code2doc.rb,
lib/omnitest/reporters/markdown_reporter.rb,
lib/omnitest/command/generators/dashboard.rb,
lib/omnitest/command/generators/documentation.rb

Overview

Common module to execute a Omnitest action such as create, converge, etc.

Defined Under Namespace

Modules: CLI, Command, Core, Delegators, Reporters, RunAction Classes: Configuration, DocumentationGenerator, Project, ProjectLogger, ProjectSet, Workflow

Constant Summary collapse

SUPPORTED_EXTENSIONS =

File extensions that Omnitest can automatically detect/execute

%w(py rb js)
DEFAULT_PROJECT_SET_FILE =
'omnitest.yaml'
DEFAULT_TEST_MANIFEST_FILE =
'skeptic.yaml'
VERSION =
'0.2.2'
RESOURCES_DIR =
File.expand_path '../../../resources', __FILE__

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from RunAction

run_action

Methods included from Delegators

delegate_to_projects, delegate_to_psychic_class, delegate_to_psychic_instance, delegate_to_scenarios, delegate_to_skeptic_class, meth

Class Attribute Details

.loggerLogger

Returns the common Omnitest logger.

Returns:

  • (Logger)

    the common Omnitest logger



73
74
75
# File 'lib/omnitest.rb', line 73

def logger
  @logger
end

.psychicObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



188
189
190
# File 'lib/omnitest.rb', line 188

def psychic
  @psychic
end

.wants_to_quitObject

Returns the value of attribute wants_to_quit.



77
78
79
# File 'lib/omnitest.rb', line 77

def wants_to_quit
  @wants_to_quit
end

Class Method Details

.basedirObject



91
92
93
# File 'lib/omnitest.rb', line 91

def basedir
  @basedir ||= psychic.basedir
end

.default_file_loggerLogger

Returns a default file logger which emits on standard output and to a log file.

Returns:

  • (Logger)

    a logger



172
173
174
175
# File 'lib/omnitest.rb', line 172

def default_file_logger
  logfile = File.expand_path(File.join('.omnitest', 'logs', 'omnitest.log'))
  ProjectLogger.new(stdout: $stdout, logdev: logfile, level: Core::Util.to_logger_level(configuration.log_level))
end

.filter_projects(regexp = 'all', _options = {}) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/omnitest.rb', line 156

def filter_projects(regexp = 'all', _options = {})
  return Omnitest.projects if regexp.nil? || regexp == 'all'

  filtered_projects = Omnitest.projects.find { |s| s.name == regexp }
  return [filtered_projects] if filtered_projects

  filtered_projects ||= Omnitest.projects.select { |s| s.name =~ /#{regexp}/i }
  fail UserError, "No projects matching regex `#{regexp}', known projects: #{Omnitest.projects.map(&:name)}" if filtered_projects.empty?

  filtered_projects
end

.manifestObject

The TestManifest that describes the test scenarios known to Omnitest.



178
179
180
# File 'lib/omnitest.rb', line 178

def manifest
  configuration.skeptic.manifest
end

.new_logger(project) ⇒ Object

(test, project, index)



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/omnitest.rb', line 79

def new_logger(project) # (test, project, index)
  name = project.name # instance_name(test, project)
  index = Omnitest.projects.index(project) || 0
  ProjectLogger.new(
    stdout: STDOUT,
    color: Core::Color::COLORS[index % Core::Color::COLORS.size].to_sym,
    logdev: File.join(Omnitest.configuration.log_root, "#{name}.log"),
    level: Omnitest::Core::Util.to_logger_level(Omnitest.configuration.log_level),
    progname: name
  )
end

.projectsObject

The set of Projects registered with Omnitest.



183
184
185
# File 'lib/omnitest.rb', line 183

def projects
  configuration.project_set.projects.values
end

.scenarios(project_regexp = 'all', scenario_regexp = 'all', options = {}) ⇒ Object



146
147
148
149
150
151
152
153
154
# File 'lib/omnitest.rb', line 146

def scenarios(project_regexp = 'all', scenario_regexp = 'all', options = {})
  filtered_projects = filter_projects(project_regexp, options)
  filtered_scenarios = filtered_projects.map(&:skeptic).flat_map do | skeptic |
    skeptic.scenarios scenario_regexp, options
  end

  fail UserError, "No scenarios for regex `#{scenario_regexp}', try running `omnitest list'" if filtered_scenarios.empty?
  filtered_scenarios
end

.setupObject



141
142
143
144
# File 'lib/omnitest.rb', line 141

def setup
  # This autoload should probably be in Skeptic's initializer...
  autoload_omnitest_files(@test_dir) unless @test_dir.nil? || !File.directory?(@test_dir)
end

.tty?true, false

Returns whether or not standard output is associated with a terminal device (tty).

Returns:

  • (true, false)

    is there a tty?



196
197
198
# File 'lib/omnitest.rb', line 196

def tty?
  $stdout.tty?
end

.update_config!(options) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/omnitest.rb', line 104

def update_config!(options)
  trap_interrupt
  @logger = Omnitest.default_file_logger
  project_set_file = options.file || DEFAULT_PROJECT_SET_FILE
  @basedir = File.dirname project_set_file
  skeptic_file = options.skeptic || DEFAULT_TEST_MANIFEST_FILE

  Omnitest.configure do | config |
    config.concurrency = options.concurrency
    config.log_level = options.log_level || :info
    config.project_set = project_set_file
    config.skeptic.manifest_file = skeptic_file
    config.travis = options.travis if options.respond_to? :travis
  end
  @test_dir = options.test_dir || File.expand_path('tests/omnitest/', @basedir)
end