diff --git a/History.md b/History.md index afa80e25..efda8fdc 100644 --- a/History.md +++ b/History.md @@ -1,5 +1,6 @@ ## [Git master](https://github.com/cucumber/gherkin/compare/v2.12.1...master) +* [Core] Fix Ruby 2.0 warnings ([#265](https://github.com/cucumber/gherkin/issues/265) Aslak Hellesøy) * [Java] Expose ID so that tools can differentiate between runs of scenario examples ([#279](https://github.com/cucumber/gherkin/pull/278) jtnord) * [Java] Ensure PrettyFormatter outputs whole lines and flushed in between ([#277](https://github.com/cucumber/gherkin/pull/277) Ramon Nogueira) * [Java] Durations are Longs not longs as they are optional ([#276](https://github.com/cucumber/gherkin/pull/276) jtnord) diff --git a/gherkin.gemspec b/gherkin.gemspec index af02c275..063573a7 100644 --- a/gherkin.gemspec +++ b/gherkin.gemspec @@ -66,6 +66,7 @@ Gem::Specification.new do |s| s.add_development_dependency('bundler', '>= 1.3.5') # Make sure it's in sync with /.travis.yml s.add_development_dependency('rspec', '~> 2.14.1') s.add_development_dependency('rubyzip', '>= 1.0.0') + s.add_development_dependency('ruby-beautify', '= 0.92.2') unless ENV['RUBY_CC_VERSION'] || Gherkin::JRUBY s.add_development_dependency('therubyracer', '>= 0.12.0') if ENV['GHERKIN_JS'] diff --git a/lib/gherkin/formatter/filter_formatter.rb b/lib/gherkin/formatter/filter_formatter.rb index 5a792e6d..a8f8dadc 100644 --- a/lib/gherkin/formatter/filter_formatter.rb +++ b/lib/gherkin/formatter/filter_formatter.rb @@ -17,11 +17,15 @@ def initialize(formatter, filters) @feature_tags = [] @feature_element_tags = [] @examples_tags = [] - + @examples_range = [] @feature_events = [] @background_events = [] @feature_element_events = [] @examples_events = [] + + @examples_name = nil + @feature_element_name = nil + @feature_element_range = nil end def uri(uri) diff --git a/lib/gherkin/formatter/pretty_formatter.rb b/lib/gherkin/formatter/pretty_formatter.rb index 620db953..28c8b546 100644 --- a/lib/gherkin/formatter/pretty_formatter.rb +++ b/lib/gherkin/formatter/pretty_formatter.rb @@ -19,9 +19,10 @@ def initialize(io, monochrome, executing) @step_printer = StepPrinter.new @monochrome = monochrome @executing = executing - @background = nil - @tag_statement = nil @steps = [] + + # Prevent warnings, initialize fields + @background = @tag_statement = @formats = @statement = nil end def uri(uri) diff --git a/lib/gherkin/tag_expression.rb b/lib/gherkin/tag_expression.rb index a0888bb1..17702c5e 100644 --- a/lib/gherkin/tag_expression.rb +++ b/lib/gherkin/tag_expression.rb @@ -21,6 +21,7 @@ def empty? def evaluate(tags) return true if @ands.flatten.empty? vars = Hash[*tags.map{|tag| [tag.name, true]}.flatten] + raise "No vars" if vars.nil? # Useless statement to prevent ruby warnings about unused var !!Kernel.eval(ruby_expression) end diff --git a/ragel/lexer.rb.rl.erb b/ragel/lexer.rb.rl.erb index 21358640..7fd85b41 100644 --- a/ragel/lexer.rb.rl.erb +++ b/ragel/lexer.rb.rl.erb @@ -126,6 +126,9 @@ module Gherkin def initialize(listener) @listener = listener + + # Initialize ivars to avoid warnings + @keyword = nil %% write data; end diff --git a/spec/gherkin/lexer/i18n_lexer_spec.rb b/spec/gherkin/lexer/i18n_lexer_spec.rb index 9fd11036..5f37c0ec 100644 --- a/spec/gherkin/lexer/i18n_lexer_spec.rb +++ b/spec/gherkin/lexer/i18n_lexer_spec.rb @@ -11,9 +11,13 @@ module Lexer it "should store the i18n language of the last scanned feature" do @lexer.scan("# language: fr\n") - @lexer.i18n_language.iso_code.should == "fr" - @lexer.scan("# language: no\n") - @lexer.i18n_language.iso_code.should == "no" + # This if is kind of dumb - it's just to avoid warnings from ruby + if(@lexer.i18n_language.iso_code.should == "fr") + @lexer.scan("# language: no\n") + @lexer.i18n_language.iso_code.should == "no" + else + fail + end end it "should detect language when there are spaces and CRLF" do diff --git a/spec/gherkin/parser/parser_spec.rb b/spec/gherkin/parser/parser_spec.rb index 8e6d7f3d..3550093f 100644 --- a/spec/gherkin/parser/parser_spec.rb +++ b/spec/gherkin/parser/parser_spec.rb @@ -5,7 +5,7 @@ module Parser describe Parser do unless defined?(JRUBY_VERSION) it "should raise when feature doesn't parse" do - p = Parser.new(mock('formatter').as_null_object) + p = Parser.new(double('formatter').as_null_object) lambda do p.parse("Feature: f\nFeature: f", __FILE__, __LINE__-1) end.should raise_error(Regexp.new("Parse error at #{__FILE__}:\\d+")) diff --git a/spec/gherkin/rubify_spec.rb b/spec/gherkin/rubify_spec.rb index 527c9724..a18876d2 100644 --- a/spec/gherkin/rubify_spec.rb +++ b/spec/gherkin/rubify_spec.rb @@ -7,7 +7,7 @@ module Gherkin module Rubify describe "rubify" do before do - @java_collection = [mock("Java.java.util.ArrayList")] + @java_collection = [double("Java.java.util.ArrayList")] @java_collection.stub(:===).and_return(Java.java.util.Collection) @java_collection.stub(:line).and_return(15) @rubified_array = rubify(@java_collection) diff --git a/spec/gherkin/shared/doc_string_group.rb b/spec/gherkin/shared/doc_string_group.rb index f53e4e64..cd5ddfba 100644 --- a/spec/gherkin/shared/doc_string_group.rb +++ b/spec/gherkin/shared/doc_string_group.rb @@ -1,6 +1,4 @@ # encoding: utf-8 -require 'spec_helper' - module Gherkin module Lexer shared_examples_for "a Gherkin lexer lexing doc_strings" do diff --git a/spec/gherkin/shared/encoding_group.rb b/spec/gherkin/shared/encoding_group.rb index f8932f85..99433501 100644 --- a/spec/gherkin/shared/encoding_group.rb +++ b/spec/gherkin/shared/encoding_group.rb @@ -1,6 +1,4 @@ #encoding: utf-8 -require 'spec_helper' - module Gherkin module Lexer shared_examples_for "encoding" do diff --git a/spec/gherkin/shared/lexer_group.rb b/spec/gherkin/shared/lexer_group.rb index c5c4b83e..b884075a 100644 --- a/spec/gherkin/shared/lexer_group.rb +++ b/spec/gherkin/shared/lexer_group.rb @@ -1,6 +1,4 @@ #encoding: utf-8 -require 'spec_helper' - module Gherkin module Lexer shared_examples_for "a Gherkin lexer" do diff --git a/spec/gherkin/shared/row_group.rb b/spec/gherkin/shared/row_group.rb index aa30a834..c9372cf8 100644 --- a/spec/gherkin/shared/row_group.rb +++ b/spec/gherkin/shared/row_group.rb @@ -1,6 +1,4 @@ # encoding: utf-8 -require 'spec_helper' - module Gherkin module Lexer shared_examples_for "a Gherkin lexer lexing rows" do diff --git a/spec/gherkin/shared/tags_group.rb b/spec/gherkin/shared/tags_group.rb index b44e0270..2d41c358 100644 --- a/spec/gherkin/shared/tags_group.rb +++ b/spec/gherkin/shared/tags_group.rb @@ -1,6 +1,4 @@ # encoding: utf-8 -require 'spec_helper' - module Gherkin module Lexer shared_examples_for "a Gherkin lexer lexing tags" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 27321e58..72333a7f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,16 @@ +def silence_warnings(&block) + warn_level = $VERBOSE + $VERBOSE = nil + result = block.call + $VERBOSE = warn_level + result +end + if RUBY_VERSION =~ /1\.9|2\.0/ - Encoding.default_external = Encoding::UTF_8 - Encoding.default_internal = Encoding::UTF_8 + silence_warnings do + Encoding.default_external = Encoding::UTF_8 + Encoding.default_internal = Encoding::UTF_8 + end end if defined?(JRUBY_VERSION) java_import java.util.ArrayList @@ -30,7 +40,7 @@ def scan_file(file) def fixture(file) encoding = Gherkin::Lexer::Encoding.new - source = encoding.read_file(File.dirname(__FILE__) + "/gherkin/fixtures/" + file) + encoding.read_file(File.dirname(__FILE__) + "/gherkin/fixtures/" + file) end def rubify_hash(hash) @@ -51,8 +61,10 @@ def rubify_hash(hash) # Allows comparison of Java List with Ruby Array (rows) RSpec::Matchers.define :r do |expected| match do |row| - def row.inspect - "r " + self.map{|cell| cell}.inspect + silence_warnings do + def row.inspect + "r " + self.map{|cell| cell}.inspect + end end row.map{|cell| cell}.should == expected end @@ -60,8 +72,10 @@ def row.inspect RSpec::Matchers.define :a do |expected| match do |array| - def array.inspect - "a " + self.map{|e| e.to_sym}.inspect + silence_warnings do + def array.inspect + "a " + self.map{|e| e.to_sym}.inspect + end end array.map{|e| e.to_sym}.should == expected end diff --git a/tasks/ragel_task.rb b/tasks/ragel_task.rb index 822441ba..ff05e95a 100755 --- a/tasks/ragel_task.rb +++ b/tasks/ragel_task.rb @@ -39,6 +39,14 @@ def define_tasks # Minify sh %{node #{UGLIFYJS} #{target} > #{min_target}} end + + if(@lang == 'rb') + # Prettify the code so we don't get indentation warnings + sh %{rbeautify #{target} > tmp.rb} + sh %{mv tmp.rb #{target}} + # rbeautify has a bug with class << self ... end alignment. Fix it. + sh %{perl -i -0pe 's/ end\n self._/ end\n self._/g' #{target}} + end end if(@lang != 'java') diff --git a/tasks/rspec.rake b/tasks/rspec.rake index a833ffe2..63620eb9 100644 --- a/tasks/rspec.rake +++ b/tasks/rspec.rake @@ -2,5 +2,5 @@ require 'rspec/core/rake_task' desc "Run RSpec" task :spec do - sh "rspec spec" + sh "rspec spec --color --warnings" end