Class: RSpecGherkin::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-gherkin/builder.rb

Defined Under Namespace

Modules: Name, Tags Classes: Background, Feature, Scenario, Step

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



83
84
85
# File 'lib/rspec-gherkin/builder.rb', line 83

def initialize
  @features = []
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



72
73
74
# File 'lib/rspec-gherkin/builder.rb', line 72

def features
  @features
end

Class Method Details

.build(feature_file) ⇒ Object



75
76
77
78
79
80
# File 'lib/rspec-gherkin/builder.rb', line 75

def build(feature_file)
  RSpecGherkin::Builder.new.tap do |builder|
    parser = Gherkin::Parser::Parser.new(builder, true)
    parser.parse(File.read(feature_file), feature_file, 0)
  end
end

Instance Method Details

#background(background) ⇒ Object



87
88
89
90
# File 'lib/rspec-gherkin/builder.rb', line 87

def background(background)
  @current_step_context = Background.new(background)
  @current_feature.backgrounds << @current_step_context
end

#eofObject



129
130
# File 'lib/rspec-gherkin/builder.rb', line 129

def eof
end

#examples(examples) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rspec-gherkin/builder.rb', line 106

def examples(examples)
  rows_to_array(examples.rows).each do |arguments|
    scenario = Scenario.new(@current_scenario_template)
    scenario.arguments = arguments.map do |argument|
      if numeric?(argument)
        integer?(argument) ? argument.to_i : argument.to_f
      elsif boolean?(argument)
        to_bool(argument)
      else
        argument
      end
    end

    @current_feature.scenarios << scenario
  end
end

#feature(feature) ⇒ Object



92
93
94
95
# File 'lib/rspec-gherkin/builder.rb', line 92

def feature(feature)
  @current_feature = Feature.new(feature)
  @features << @current_feature
end

#scenario(scenario) ⇒ Object



97
98
99
100
# File 'lib/rspec-gherkin/builder.rb', line 97

def scenario(scenario)
  @current_step_context = Scenario.new(scenario)
  @current_feature.scenarios << @current_step_context
end

#scenario_outline(outline) ⇒ Object



102
103
104
# File 'lib/rspec-gherkin/builder.rb', line 102

def scenario_outline(outline)
  @current_scenario_template = outline
end

#stepObject



123
124
# File 'lib/rspec-gherkin/builder.rb', line 123

def step(*)
end

#uriObject



126
127
# File 'lib/rspec-gherkin/builder.rb', line 126

def uri(*)
end