Class: Testify::Framework::Base

Inherits:
Object
  • Object
show all
Extended by:
Aliasable, SubclassAware
Defined in:
lib/framework/base.rb

Overview

The class from which all Framework classes should inherit. Keeps track of all known frameworks and any aliases they're known by. 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).

Direct Known Subclasses

RSpecAdaptor

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_pattern(pattern) ⇒ Object

Accepts a glob pattern that limits the paths returned by `#files`. Only paths with filenames that match this pattern will be returned by .files.



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

def self.file_pattern( pattern )
  self.class_eval { @file_pattern = pattern }
end

.inherited(sub) ⇒ Object

:nodoc:



24
25
26
27
# File 'lib/framework/base.rb', line 24

def self.inherited( sub ) #:nodoc:
  old_inherited(sub)
  sub.class_eval { @statuses = Testify::Framework::DEFAULT_STATUSES.dup }
end

.old_inheritedObject



23
# File 'lib/framework/base.rb', line 23

alias :old_inherited :inherited

.statuses(*new_statuses) ⇒ Object

Gets and sets an array of symbols corresponding to the possible TestResult statuses that might be set by this Framework.

For example, a framework with tests that can only pass or fail might like like this:

class SomeFramework < Testify::Framework::Base
  statuses :passed, :failed
  ...
end

SomeFramework.statuses  # => [ :passed, :failed ]


42
43
44
45
46
47
# File 'lib/framework/base.rb', line 42

def self.statuses( *new_statuses )
  if new_statuses.any?
    @statuses = new_statuses
  end
  @statuses
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)


67
68
69
70
71
72
73
# File 'lib/framework/base.rb', line 67

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



89
90
91
# File 'lib/framework/base.rb', line 89

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



95
96
97
98
99
# File 'lib/framework/base.rb', line 95

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.



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

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.



83
84
85
# File 'lib/framework/base.rb', line 83

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