Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Fix Ruby 2.0 warnings. Closes #265
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Oct 12, 2013
1 parent 0c0087f commit f172c76
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 26 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions gherkin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
6 changes: 5 additions & 1 deletion lib/gherkin/formatter/filter_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/gherkin/formatter/pretty_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/gherkin/tag_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions ragel/lexer.rb.rl.erb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ module Gherkin

def initialize(listener)
@listener = listener

# Initialize ivars to avoid warnings
@keyword = nil
%% write data;
end

Expand Down
10 changes: 7 additions & 3 deletions spec/gherkin/lexer/i18n_lexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/gherkin/parser/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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+"))
Expand Down
2 changes: 1 addition & 1 deletion spec/gherkin/rubify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions spec/gherkin/shared/doc_string_group.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8
require 'spec_helper'

module Gherkin
module Lexer
shared_examples_for "a Gherkin lexer lexing doc_strings" do
Expand Down
2 changes: 0 additions & 2 deletions spec/gherkin/shared/encoding_group.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#encoding: utf-8
require 'spec_helper'

module Gherkin
module Lexer
shared_examples_for "encoding" do
Expand Down
2 changes: 0 additions & 2 deletions spec/gherkin/shared/lexer_group.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#encoding: utf-8
require 'spec_helper'

module Gherkin
module Lexer
shared_examples_for "a Gherkin lexer" do
Expand Down
2 changes: 0 additions & 2 deletions spec/gherkin/shared/row_group.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8
require 'spec_helper'

module Gherkin
module Lexer
shared_examples_for "a Gherkin lexer lexing rows" do
Expand Down
2 changes: 0 additions & 2 deletions spec/gherkin/shared/tags_group.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8
require 'spec_helper'

module Gherkin
module Lexer
shared_examples_for "a Gherkin lexer lexing tags" do
Expand Down
28 changes: 21 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -51,17 +61,21 @@ 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
end

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
Expand Down
8 changes: 8 additions & 0 deletions tasks/ragel_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tasks/rspec.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ require 'rspec/core/rake_task'

desc "Run RSpec"
task :spec do
sh "rspec spec"
sh "rspec spec --color --warnings"
end

0 comments on commit f172c76

Please sign in to comment.