Class: Spinach::Runner::Feature

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
lib/spinach/runner/feature.rb

Overview

A feature runner handles a particular feature run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Feature

Returns a new instance of Feature.

Parameters:

  • filename (String)

    path to the feature file. Scenario line could be passed to run just that scenario. @example feature/a_cool_feature.feature:12



26
27
28
# File 'lib/spinach/runner/feature.rb', line 26

def initialize(filename)
  @filename, @scenario_line = filename.split(':')
end

Instance Attribute Details

#filenameObject (readonly)

The file taht describes the feature.



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

def filename
  @filename
end

#reporterObject (readonly)

The Spinach::Reporter used in this feature.



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

def reporter
  @reporter
end

Instance Method Details

#dataHash

Returns The parsed data for this feature.

Returns:

  • (Hash)

    The parsed data for this feature.



46
47
48
# File 'lib/spinach/runner/feature.rb', line 46

def data
  @data ||= Spinach::Parser.new(filename).parse
end

#featureFeature

Returns The feature object used to run this scenario.

Returns:

  • (Feature)

    The feature object used to run this scenario.



38
39
40
# File 'lib/spinach/runner/feature.rb', line 38

def feature
  @feature ||= Spinach.find_feature(feature_name).new
end

#feature_nameString

Returns This feature name.

Returns:

  • (String)

    This feature name.



54
55
56
# File 'lib/spinach/runner/feature.rb', line 54

def feature_name
  @feature_name ||= data['name']
end

#runtrue, false

Runs this feature.

Returns:

  • (true, false)

    Whether the run was successful or not.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/spinach/runner/feature.rb', line 72

def run
  run_hook :before_run, data
  feature.run_hook :before, data

  scenarios.each do |scenario|
    if !@scenario_line || scenario['line'].to_s == @scenario_line
      @success = Scenario.new(feature_name, feature, scenario).run
    end
  end

  feature.run_hook :after, data
  run_hook :after_run, data

rescue Spinach::FeatureStepsNotFoundException => e
  run_hook :when_not_found, data, e
ensure
  return !!@success
end

#scenariosHash

Returns The parsed scenarios for this runner’s feature.

Returns:

  • (Hash)

    The parsed scenarios for this runner’s feature.



62
63
64
# File 'lib/spinach/runner/feature.rb', line 62

def scenarios
  @scenarios ||= (data['elements'] || [])
end