diff --git a/.rspec b/.rspec new file mode 100644 index 0000000000..4e1e0d2f72 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color diff --git a/gem_tasks/rspec.rake b/gem_tasks/rspec.rake index 791781a4d2..477a404efd 100644 --- a/gem_tasks/rspec.rake +++ b/gem_tasks/rspec.rake @@ -1,20 +1,8 @@ -begin - require 'rspec/core/rake_task' +require 'rspec/core/rake_task' - desc "Run RSpec" - RSpec::Core::RakeTask.new do |t| - t.rcov = ENV['RCOV'] - t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/} - t.verbose = true - end -rescue LoadError => e - require 'spec/rake/spectask' - - desc "Run RSpec" - Spec::Rake::SpecTask.new do |t| - t.spec_opts = %w{--color --diff} - t.rcov = ENV['RCOV'] - t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/} - t.verbose = true - end +desc "Run RSpec" +RSpec::Core::RakeTask.new do |t| + t.rcov = ENV['RCOV'] + t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/} + t.verbose = true end diff --git a/lib/cucumber/ast/comment.rb b/lib/cucumber/ast/comment.rb index 79e392a0cc..d5f660439e 100644 --- a/lib/cucumber/ast/comment.rb +++ b/lib/cucumber/ast/comment.rb @@ -9,6 +9,7 @@ module Ast # class Comment #:nodoc: def initialize(value) + raise "?????" if Array === value @value = value end diff --git a/lib/cucumber/ast/table.rb b/lib/cucumber/ast/table.rb index 10bbf00940..679d100793 100644 --- a/lib/cucumber/ast/table.rb +++ b/lib/cucumber/ast/table.rb @@ -39,6 +39,9 @@ def initialize @rows = [] end + def uri(uri) + end + def row(row, line_number) @rows << row end @@ -58,10 +61,10 @@ def self.default_arg_name #:nodoc: "table" end - def self.parse(text) + def self.parse(text, uri) builder = Builder.new lexer = Gherkin::I18nLexer.new(builder) - lexer.scan(text) + lexer.scan(text, uri) new(builder.rows) end diff --git a/lib/cucumber/feature_file.rb b/lib/cucumber/feature_file.rb index 3da23a1951..f33013c55b 100644 --- a/lib/cucumber/feature_file.rb +++ b/lib/cucumber/feature_file.rb @@ -1,5 +1,6 @@ require 'cucumber/parser/gherkin_builder' require 'gherkin/parser/filter_listener' +require 'gherkin/parser/formatter_listener' require 'gherkin/parser/parser' require 'gherkin/i18n_lexer' @@ -26,14 +27,15 @@ def initialize(uri, source=nil) def parse(step_mother, options) filters = @lines || options.filters - builder = Cucumber::Parser::GherkinBuilder.new - filter_listener = Gherkin::Parser::FilterListener.new(builder, filters) - parser = Gherkin::Parser::Parser.new(filter_listener, true, "root") - lexer = Gherkin::I18nLexer.new(parser, false) + builder = Cucumber::Parser::GherkinBuilder.new + formatter_listener = Gherkin::Parser::FormatterListener.new(builder) + filter_listener = Gherkin::Parser::FilterListener.new(formatter_listener, filters) + parser = Gherkin::Parser::Parser.new(filter_listener, true, "root") + lexer = Gherkin::I18nLexer.new(parser, false) begin s = ENV['FILTER_PML_CALLOUT'] ? source.gsub(C_CALLOUT, '') : source - lexer.scan(s) + lexer.scan(s, @path) ast = builder.ast return nil if ast.nil? # Filter caused nothing to match ast.language = lexer.i18n_language diff --git a/lib/cucumber/parser/gherkin_builder.rb b/lib/cucumber/parser/gherkin_builder.rb index a093b8765d..db516d5b1f 100644 --- a/lib/cucumber/parser/gherkin_builder.rb +++ b/lib/cucumber/parser/gherkin_builder.rb @@ -11,33 +11,23 @@ def ast @feature || @multiline_arg end - def tag(name, line) - @tags ||= [] - @tags << name - end - - def comment(content, line) - @comments ||= [] - @comments << content - end - - def feature(keyword, name, line) + def feature(comments, tags, keyword, name, description, uri) @feature = Ast::Feature.new( nil, - Ast::Comment.new(grab_comments!('')), - Ast::Tags.new(nil, grab_tags!('')), + Ast::Comment.new(comments.join("\n")), + Ast::Tags.new(nil, tags), keyword, - name, + legacy_name_for(name, description), [] ) end - def background(keyword, name, line) + def background(comments, keyword, name, description, line) @background = Ast::Background.new( - Ast::Comment.new(grab_comments!('')), + Ast::Comment.new(comments.join("\n")), line, keyword, - name, + legacy_name_for(name, description), steps=[] ) @feature.background = @background @@ -45,15 +35,14 @@ def background(keyword, name, line) @step_container = @background end - def scenario(keyword, name, line) - grab_table! + def scenario(comments, tags, keyword, name, description, line) scenario = Ast::Scenario.new( @background, - Ast::Comment.new(grab_comments!('')), - Ast::Tags.new(nil, grab_tags!('')), + Ast::Comment.new(comments.join("\n")), + Ast::Tags.new(nil, tags), line, keyword, - name, + legacy_name_for(name, description), steps=[] ) @feature.add_feature_element(scenario) @@ -61,15 +50,14 @@ def scenario(keyword, name, line) @step_container = scenario end - def scenario_outline(keyword, name, line) - grab_table! + def scenario_outline(comments, tags, keyword, name, description, line) scenario_outline = Ast::ScenarioOutline.new( @background, - Ast::Comment.new(grab_comments!('')), - Ast::Tags.new(nil, grab_tags!('')), + Ast::Comment.new(comments.join("\n")), + Ast::Tags.new(nil, tags), line, keyword, - name, + legacy_name_for(name, description), steps=[], example_sections=[] ) @@ -81,64 +69,35 @@ def scenario_outline(keyword, name, line) @step_container = scenario_outline end - def examples(keyword, name, line) - grab_table! - @examples_fields = [Ast::Comment.new(grab_comments!('')), line, keyword, name] + def examples(comments, tags, keyword, name, description, line, examples_table) + examples_fields = [Ast::Comment.new(comments.join("\n")), line, keyword, name, examples_table] + @step_container.add_examples(examples_fields) end - def step(keyword, name, line) - grab_table! + def step(comments, keyword, name, line, multiline_arg, status, exception, arguments, stepdef_location) @table_owner = Ast::Step.new(line, keyword, name) - @step_container.add_step(@table_owner) - end - - def row(row, line) - @rows ||= [] - @rows << row - class << row - attr_accessor :line + case(multiline_arg) + when String + @table_owner.multiline_arg = Ast::PyString.new(multiline_arg) + when Array + @table_owner.multiline_arg = Ast::Table.new(multiline_arg) end - row.line = line - end - - def py_string(string, line) - @multiline_arg = Ast::PyString.new(string) - @table_owner.multiline_arg = @multiline_arg if @table_owner + @step_container.add_step(@table_owner) end def eof - grab_table! end def syntax_error(state, event, legal_events, line) # raise "SYNTAX ERROR" end - + private - - def grab_table! - return if @rows.nil? - if @examples_fields - @examples_fields << @rows - @step_container.add_examples(@examples_fields) - @examples_fields = nil - else - @multiline_arg = Ast::Table.new(@rows) - @table_owner.multiline_arg = @multiline_arg if @table_owner - end - @rows = nil - end - - def grab_tags!(indent) - tags = @tags ? @tags : [] - @tags = nil - tags - end - - def grab_comments!(indent) - comments = @comments ? indent + @comments.join("\n#{indent}") : '' - @comments = nil - comments + + def legacy_name_for(name, description) + s = name + s += "\n#{description}" if description != "" + s end end end diff --git a/spec/cucumber/ast/table_spec.rb b/spec/cucumber/ast/table_spec.rb index 0f016b5df7..ba81400711 100644 --- a/spec/cucumber/ast/table_spec.rb +++ b/spec/cucumber/ast/table_spec.rb @@ -416,7 +416,7 @@ def @table.columns; super; end end def table(text, file=nil, line_offset=0) - Table.parse(text) + Table.parse(text, __FILE__) end end