Module: Testify::Runner
- Defined in:
- lib/runner.rb
Overview
Runner is a Testify app intended to sit at the top of a Testify stack and provide a simple mechanism for running a set of tests. If you’re writing an autotest-like application, Runner is what you would use. Runner uses Templatable from the Classy gem, so you can either subclass Runner and use DSL-like class methods to define its behavior, or instantiate it directly and configure the instance.
For example,
class SampleRunner
include Testify::Runner
framework :rspec
middleware :growl, :red_green
end
@runner = SampleRunner.new
would be equivalent to
@runner = Testify::Runner::Base.new
@runner.framework = Testify::Framework::RspecAdaptor
@runner.middleware = [Testify::Middleware::Growl, Testify::Middleware::RedGreen]
Which approach is best depends on your needs, or you can use a mixture of the two.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#construct_app_stack ⇒ Object
Constructs the stack of middleware and framework.
-
#framework=(fw) ⇒ Object
Allows the framework to be specified on an instance of Runner.
-
#middleware=(middleware) ⇒ Object
Allows the middleware array to be specified for an instance of Runner.
-
#run(options = {}) ⇒ Object
Run the tests.
Class Method Details
.included(klass) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/runner.rb', line 31 def self.included( klass ) klass.class_eval do extend Templatable extend Testify::Runner::ClassMethods attr_accessor :status, :framework_instance, :test_results templatable_attr :framework, :middleware @@middleware = [] end super end |
Instance Method Details
#construct_app_stack ⇒ Object
Constructs the stack of middleware and framework. If you are doing something unconventional (eg, creating middleware that requires additional initialization parameters), you may need to override this method.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/runner.rb', line 68 def construct_app_stack @framework_instance ||= framework.new top_app = @framework_instance middleware.each do |mw_class| top_app = mw_class.new(top_app) end top_app end |
#framework=(fw) ⇒ Object
Allows the framework to be specified on an instance of Runner. See .framework
.
46 47 48 |
# File 'lib/runner.rb', line 46 def framework= (fw) @framework = Testify::Framework::Base.find(fw) end |
#middleware=(middleware) ⇒ Object
Allows the middleware array to be specified for an instance of Runner. See .middleware
.
Note: The class method accepts a list, but the instance method must be passed an actual array.
Example:
runner = YourRunner.new
runner.middleware = [:dots, :colorize]
59 60 61 |
# File 'lib/runner.rb', line 59 def middleware=( middleware ) @middleware = middleware.map { |mw| Testify::Middleware.find(mw) } end |
#run(options = {}) ⇒ Object
Run the tests. Accepts a hash that will be merged in to the default env and passed to the Testify app stack.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/runner.rb', line 82 def run( = {} ) top_app = construct_app_stack env = Testify.env_defaults.merge @test_results = top_app.call(env) @status = @test_results.collect(&:status).max # XXX: Optimize? @test_results end |