Module: Testify::Framework

Includes:
Aliasable
Defined in:
lib/framework.rb

Overview

The module which all Framework classes are recommended to inherit. Framework provides a few utility methods and a means to keep track of all Framework classes (via Aliasable). Framework objects are Testify apps, so subclasses must implement a call method as described in the README.rdoc file. It is also good practice to declare at least one alias (see the Aliasable module in the Classy gem for more details).

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_STATUSES =

The default set of statuses

[ :passed, :pending, :failed, :error ]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Extend the ClassMethods module and set the default statuses.

:nodoc:



20
21
22
23
24
# File 'lib/framework.rb', line 20

def self.included( klass )
  klass.extend Testify::Framework::ClassMethods
  klass.statuses *Testify::Framework::DEFAULT_STATUSES.dup
  super
end

Instance Method Details

#files(env) ⇒ Object

Returns an array of absolute paths to each file defined by an env hash. The default implementation either returns the array of files, if :files is defined in the hash, or returns every file found in a traversal of the path in the :path key. Raises an exception if neither is defined, since that is not a valid env hash.

If a particular framework should only process files with names matching a particular glob pattern (eg, RSpec only wants files that match ‘*_spec.rb`), it can specify this with file_pattern.

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
# File 'lib/framework.rb', line 36

def files( env )
  return env[:files] if env.include? :files
  raise(ArgumentError, "env hash must include either :files or :path") unless env.include? :path

  file_glob = self.class.class_eval { @file_pattern } || '*'
  Dir.glob(File.join(env[:path], '**', file_glob))
end

#run_after_all_hooks(env, results) ⇒ Object

Run all the appropriate hooks after running all the tests



58
59
60
# File 'lib/framework.rb', line 58

def run_after_all_hooks( env, results )
  env[:hooks][:after_all].each { |hook| hook.call(results) }
end

#run_after_each_hooks(env, result) ⇒ Object

Run all the appropriate hooks after running each test individually (including the hooks for a particular status).



65
66
67
68
69
# File 'lib/framework.rb', line 65

def run_after_each_hooks( env, result )
  hooks = env[:hooks][:after_each]
  hooks += env[:hooks][:after_status][result.status].to_a  # .to_a in case it's nil
  hooks.each { |hook| hook.call(result) }
end

#run_before_all_hooks(env) ⇒ Object

Run all the appropriate hooks before running any tests at all.



46
47
48
# File 'lib/framework.rb', line 46

def run_before_all_hooks( env )
  env[:hooks][:before_all].each { |hook| hook.call }
end

#run_before_each_hooks(env) ⇒ Object

Run all the appropriate hooks before running each test.



52
53
54
# File 'lib/framework.rb', line 52

def run_before_each_hooks( env )
  env[:hooks][:before_each].each { |hook| hook.call }
end