Class: Spinach::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/spinach/runner.rb,
lib/spinach/runner/feature_runner.rb,
lib/spinach/runner/scenario_runner.rb

Overview

Runner gets the parsed data from the feature and performs the actual calls to the feature classes.

Defined Under Namespace

Classes: FeatureRunner, ScenarioRunner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filenames, options = {}) ⇒ Runner

Initializes the runner with a parsed feature

Parameters:

  • filenames (Array<String>)

    A list of feature filenames to run

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :step_definitions_path (String)

    The path in which step definitions are found.

  • :support_path (String)

    The path with the support ruby files.



30
31
32
33
34
35
36
37
38
# File 'lib/spinach/runner.rb', line 30

def initialize(filenames, options = {})
  @filenames = filenames

  @step_definitions_path = options.delete(:step_definitions_path ) ||
    Spinach.config.step_definitions_path

  @support_path = options.delete(:support_path ) ||
    Spinach.config.support_path
end

Instance Attribute Details

#filenamesObject (readonly)

The feature files to run



8
9
10
# File 'lib/spinach/runner.rb', line 8

def filenames
  @filenames
end

#step_definitions_pathObject (readonly)

The default path where the steps are located



11
12
13
# File 'lib/spinach/runner.rb', line 11

def step_definitions_path
  @step_definitions_path
end

#support_pathObject (readonly)

The default path where the support files are located



14
15
16
# File 'lib/spinach/runner.rb', line 14

def support_path
  @support_path
end

Instance Method Details

#require_dependenciesObject

Loads support files and step definitions, ensuring that env.rb is loaded first.



80
81
82
83
84
# File 'lib/spinach/runner.rb', line 80

def require_dependencies
  required_files.each do |file|
    require file
  end
end

#require_frameworksObject

Requires the test framework support



88
89
90
# File 'lib/spinach/runner.rb', line 88

def require_frameworks
  require_relative 'frameworks'
end

#required_filesArray<String>

Returns files All support files with env.rb ordered first, followed by the step definitions.

Returns:

  • (Array<String>)

    files All support files with env.rb ordered first, followed by the step definitions.



124
125
126
# File 'lib/spinach/runner.rb', line 124

def required_files
  support_files + step_definition_files
end

#runtrue, false

Runs this runner and outputs the results in a colorful manner.

Returns:

  • (true, false)

    Whether the run was succesful.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/spinach/runner.rb', line 55

def run
  require_dependencies
  require_frameworks

  Spinach.hooks.run_before_run

  successful = true

  filenames.map do |filename|
    filename.split(':')
  end.each do |filename, line|
    feature = Parser.open_file(filename).parse
    success = FeatureRunner.new(feature, line).run
    successful = false unless success
  end

  Spinach.hooks.run_after_run(successful)

  successful
end

#step_definition_filesArray<String>

Returns files The step definition files.

Returns:

  • (Array<String>)

    files The step definition files.



96
97
98
99
100
# File 'lib/spinach/runner.rb', line 96

def step_definition_files
  Dir.glob(
    File.expand_path File.join(step_definitions_path, '**', '*.rb')
  )
end

#support_filesArray<String>

Returns an array of support files inside the support_path. Will put “env.rb” in the beginning

Returns:

  • (Array<String>)

    files The support files.



109
110
111
112
113
114
115
116
117
# File 'lib/spinach/runner.rb', line 109

def support_files
  support_files = Dir.glob(
    File.expand_path File.join(support_path, '**', '*.rb')
  )
  environment_file = support_files.find do |f|
    f.include?(File.join support_path, 'env.rb')
  end
  support_files.unshift(environment_file).compact.uniq
end