Skip to content

Commit

Permalink
Move StepInvocation to Ast module
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Mar 15, 2009
1 parent dbe40ef commit 495d537
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 121 deletions.
8 changes: 4 additions & 4 deletions History.txt
Expand Up @@ -57,10 +57,10 @@ Scenario Outlines, the rich command line, the nice output format and everything
pure Ruby users have been enjoying for a while.

== TODO Before 0.2 release
* Newlines between backgrounds and feature elements with pretty formatter
* OK Newlines between backgrounds and feature elements with pretty formatter
* Make sure all features and specs pass on Windows, JRuby and Ruby 1.9
* Tighten up and simplify the grammar. More edge case features/specs.
* Reintroduce StepInvocation. Reduce some of the redundant calls to StepDefinition/StepMother. Align with JBehave.
* OK Tighten up and simplify the grammar. More edge case features/specs.
* OK Reintroduce StepInvocation. Reduce some of the redundant calls to StepDefinition/StepMother. Align with JBehave.
* Make some class diagrams.
* Implement at least a basic HTML formatter
* Run a single cucumber feature from rake "rake features FEATURE=/path/to/feature:line"
Expand Down Expand Up @@ -138,7 +138,7 @@ pure Ruby users have been enjoying for a while.
* Pure Ruby features are no longer supported.
* Remove --color option in autotest. Can be added manually in cucumber.yml (#215 Jean-Michel Garnier)

== (0.16.4 aslakhellesoy-webrat gem on GitHub)
== (0.16.4 aslakhellesoy-cucumber gem on GitHub)

Bugfix release.

Expand Down
1 change: 0 additions & 1 deletion lib/cucumber.rb
Expand Up @@ -6,7 +6,6 @@
require 'cucumber/parser'
require 'cucumber/version'
require 'cucumber/step_mother'
require 'cucumber/step_invocation'
require 'cucumber/cli/main'
require 'cucumber/broadcaster'
require 'cucumber/core_ext/exception'
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/ast.rb
Expand Up @@ -5,6 +5,7 @@
require 'cucumber/ast/background'
require 'cucumber/ast/scenario'
require 'cucumber/ast/scenario_outline'
require 'cucumber/ast/step_invocation'
require 'cucumber/ast/step_collection'
require 'cucumber/ast/step'
require 'cucumber/ast/table'
Expand Down
102 changes: 102 additions & 0 deletions lib/cucumber/ast/step_invocation.rb
@@ -0,0 +1,102 @@
module Cucumber
module Ast
class StepInvocation
attr_writer :step_collection, :background
attr_reader :name, :matched_cells, :status
attr_accessor :exception

def initialize(step, name, multiline_arg, matched_cells)
@step, @name, @multiline_arg, @matched_cells = step, name, multiline_arg, matched_cells
status!(:skipped)
end

def background?
@background
end

def skip_invoke!
@skip_invoke = true
end

def accept(visitor)
invoke(visitor.step_mother, visitor.options)
@step.visit_step_details(visitor, @step_match, @multiline_arg, @status, @exception, @background)
end

def invoke(step_mother, options)
find_step_match!(step_mother)
unless @skip_invoke || options[:dry_run] || exception || previous.exception
@skip_invoke = true
begin
step_mother.current_world.__cucumber_current_step = self
@step.invoke(@step_match, step_mother.current_world)
status!(:passed)
rescue Pending => e
failed(e, false)
status!(:pending)
rescue Undefined => e
failed(e, false)
status!(:undefined)
rescue Exception => e
failed(e, false)
status!(:failed)
end
end
end

def find_step_match!(step_mother)
return if @step_match
begin
@step_match = step_mother.step_match(@name)
rescue Undefined => e
failed(e, true)
status!(:undefined)
@step_match = NoStepMatch.new(@step)
rescue Ambiguous => e
failed(e, false)
status!(:failed)
@step_match = NoStepMatch.new(@step)
end
step_mother.step_visited(self)
end

def failed(exception, clear_backtrace)
@exception = exception
@exception.set_backtrace([]) if clear_backtrace
@exception.backtrace << @step.backtrace_line unless @step.backtrace_line.nil?
end

def status!(status)
@status = status
@multiline_arg.status = status if @multiline_arg
@matched_cells.each do |cell|
cell.status = status
end
end

def previous
@step_collection.previous_step(self)
end

def actual_keyword
if [Cucumber.keyword_hash['and'], Cucumber.keyword_hash['but']].index(@keyword) && previous
previous.actual_keyword
else
@step.keyword
end
end

def matches_lines?(lines)
@step.matches_lines?(lines)
end

def text_length
@step.text_length
end

def to_sexp
[:step_invocation, @step.line, @step.keyword, @name, (@multiline_arg.nil? ? nil : @multiline_arg.to_sexp)].compact
end
end
end
end
4 changes: 2 additions & 2 deletions lib/cucumber/parser/feature.tt
Expand Up @@ -43,7 +43,7 @@ module Cucumber
end

rule tag
'@' tag_name:([^@\n\t ])+
'@' tag_name:([^@\r\n\t ])+
end

rule comment
Expand Down Expand Up @@ -80,7 +80,7 @@ module Cucumber
end

rule scenario
comment tags white scenario_keyword space* name:line_to_eol (white / eof) steps white {
comment tags white scenario_keyword space* name:line_to_eol white steps white {
def build(background)
Ast::Scenario.new(
background,
Expand Down
22 changes: 11 additions & 11 deletions lib/cucumber/parser/treetop_ext.rb
Expand Up @@ -35,6 +35,17 @@ def parse_file(file)
feature.lines = lines
feature
end

def parse_or_fail(s, file=nil, line_offset=0)
parse_tree = parse(s)
if parse_tree.nil?
raise Cucumber::Parser::SyntaxError.new(self, file, line_offset)
else
ast = parse_tree.build
ast.file = file
ast
end
end
end

class SyntaxError < StandardError
Expand All @@ -59,17 +70,6 @@ def line

class CompiledParser
include Cucumber::Parser::TreetopExt

def parse_or_fail(s, file=nil, line=0)
parse_tree = parse(s)
if parse_tree.nil?
raise Cucumber::Parser::SyntaxError.new(self, file, line)
else
ast = parse_tree.build
ast.file = file
ast
end
end
end
end
end
100 changes: 0 additions & 100 deletions lib/cucumber/step_invocation.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/cucumber/world.rb
Expand Up @@ -25,9 +25,9 @@ def __cucumber_invoke(name, *multiline_arguments) #:nodoc:
end
end

def table(text, file=nil, line=0)
def table(text, file=nil, line_offset=0)
@table_parser ||= Parser::TableParser.new
@table_parser.parse_or_fail(text.strip, file, line)
@table_parser.parse_or_fail(text.strip, file, line_offset)
end

def pending(message = "TODO")
Expand Down
2 changes: 1 addition & 1 deletion spec/cucumber/parser/feature_parser_spec.rb
Expand Up @@ -94,7 +94,7 @@ def parse_example_file(file)
Given Pepper
@st3
@st4 @ST5 @#^%&ST6**!
@st4 @ST5 @#^%&ST6**!
Scenario: Second}).to_sexp.should ==
[:feature, "Feature: hi",
[:comment, "# FC\n "],
Expand Down

0 comments on commit 495d537

Please sign in to comment.