From 5799f5e5f01542f719290cea649cad62a40951cc Mon Sep 17 00:00:00 2001 From: John Voloski Date: Wed, 21 May 2014 12:49:16 -0300 Subject: [PATCH 1/8] doing update from formatter's rspec's syntax --- spec/gherkin/formatter/ansi_escapes_spec.rb | 16 ++-- .../formatter/filter_formatter_spec.rb | 74 +++++++++---------- spec/gherkin/formatter/json_formatter_spec.rb | 6 +- spec/gherkin/formatter/model_spec.rb | 14 ++-- .../formatter/pretty_formatter_spec.rb | 24 +++--- spec/gherkin/formatter/step_printer_spec.rb | 28 +++---- .../formatter/tag_count_formatter_spec.rb | 8 +- 7 files changed, 85 insertions(+), 85 deletions(-) diff --git a/spec/gherkin/formatter/ansi_escapes_spec.rb b/spec/gherkin/formatter/ansi_escapes_spec.rb index 6922baea..6642e1b2 100644 --- a/spec/gherkin/formatter/ansi_escapes_spec.rb +++ b/spec/gherkin/formatter/ansi_escapes_spec.rb @@ -7,24 +7,24 @@ module Formatter describe "instance methods" do include AnsiEscapes - it "failed should be red" do - failed.should == "\e[31m" + it "failed is red" do + expect(failed).to eq("\e[31m") end - it "failed_arg should be red bold" do - failed_arg.should == "\e[31m\e[1m" + it "failed_arg is red bold" do + expect(failed_arg).to eq("\e[31m\e[1m") end end describe "class methods" do subject { AnsiEscapes } - it "failed should be red" do - subject.failed.should == "\e[31m" + it "failed is red" do + expect(subject.failed).to eq("\e[31m") end - it "failed_arg should be red bold" do - subject.failed_arg.should == "\e[31m\e[1m" + it "failed_arg is red bold" do + expect(subject.failed_arg).to eq("\e[31m\e[1m") end end end diff --git a/spec/gherkin/formatter/filter_formatter_spec.rb b/spec/gherkin/formatter/filter_formatter_spec.rb index 402613f2..ca9bf731 100644 --- a/spec/gherkin/formatter/filter_formatter_spec.rb +++ b/spec/gherkin/formatter/filter_formatter_spec.rb @@ -23,91 +23,91 @@ def verify_filter(filters, *line_ranges) path = File.dirname(__FILE__) + "/../fixtures/" + file source = File.new(path).read + "# __EOF__" parser.parse(source, path, 0) - + source_lines = source.split("\n") expected = (line_ranges.map do |line_range| source_lines[(line_range.first-1..line_range.last-1)] end.flatten).join("\n").gsub(/# __EOF__/, '') - io.string.strip.should == expected.strip + expect(io.string.strip).to eq(expected.strip) end context "invalid mix" do - it "should throw exception on different filters" do - lambda do + it "throws exception on different filters" do + expect do verify_filter(['@tag1', /regexp/, 88], 1..61) - end.should raise_exception(/Inconsistent filters/) + end.to raise_exception(/Inconsistent filters/) end end context "tags" do - it "should filter on feature tag" do + it "filters on feature tag" do verify_filter(['@tag1'], 1..61) end - it "should filter on scenario tag" do + it "filters on scenario tag" do verify_filter(['@tag4'], 1..19) end - it "should filter on abother scenario tag" do + it "filters on abother scenario tag" do verify_filter(['@tag3'], 1..37) end - it "should filter on scenario outline tag" do + it "filters on scenario outline tag" do verify_filter(['@more'], 1..14, 46..61) end - it "should filter on first examples tag" do + it "filters on first examples tag" do verify_filter(['@neat'], 1..14, 46..55) end - it "should filter on second examples tag" do + it "filters on second examples tag" do verify_filter(['@hamster'], 1..14, 46..49, 56..61) end - it "should not replay examples from ignored scenario outline" do + it "does not replay examples from ignored scenario outline" do self.file = 'scenario_outline_with_tags.feature' verify_filter(['~@wip'], 1..2, 12..14) end - it "should not replay examples from ignored scenario outline" do + it "does not replay examples from ignored scenario outline" do self.file = 'scenario_outline_with_tags.feature' verify_filter(['~@wip'], 1..2, 12..14) end - it "should not choke on examples with only header" do + it "does not choke on examples with only header" do self.file = 'examples_with_only_header.feature' verify_filter(['@failing'], 1..7, 12..15) end end context "names" do - it "should filter on scenario name" do + it "filters on scenario name" do verify_filter([/Reading a Scenario/], 1..19) end - it "should filter on scenario outline name" do + it "filters on scenario outline name" do verify_filter([/More/], 1..14, 46..61) end - it "should filter on first examples name" do + it "filters on first examples name" do verify_filter([/Neato/], 1..14, 46..55) end - it "should filter on second examples name" do + it "filters on second examples name" do verify_filter([/Rodents/], 1..14, 46..49, 56..61) end - it "should filter on various names" do + it "filters on various names" do self.file = 'hantu_pisang.feature' verify_filter([/Pisang/], 1..8, 19..32) end - it "should filter on background name" do + it "filters on background name" do self.file = 'hantu_pisang.feature' verify_filter([/The background/], 1..5) end - it "should not choke on examples with only header" do + it "does not choke on examples with only header" do self.file = 'examples_with_only_header.feature' verify_filter([/B/], 1..7, 12..15) end @@ -115,28 +115,28 @@ def verify_filter(filters, *line_ranges) context "lines" do context "on the same line as feature element keyword" do - it "should filter on scenario without line" do + it "filters on scenario without line" do self.file = 'scenario_without_steps.feature' verify_filter([3], 1..4) end - it "should filter on scenario line" do + it "filters on scenario line" do verify_filter([16], 1..19) end - it "should filter on scenario outline line" do + it "filters on scenario outline line" do verify_filter([47], 1..14, 46..61) end - it "should filter on first examples line" do + it "filters on first examples line" do verify_filter([51], 1..14, 46..55) end - it "should filter on second examples line" do + it "filters on second examples line" do verify_filter([57], 1..14, 46..49, 56..61) end - it "should not choke on examples with only header" do + it "does not choke on examples with only header" do self.file = 'examples_with_only_header.feature' verify_filter([13], 1..7, 12..15) verify_filter([14], 1..7, 12..15) @@ -147,54 +147,54 @@ def verify_filter(filters, *line_ranges) verify_filter([14], 1..2, 6..12, 14..14) end - it "should fix issue 145 more tests" do + it "fixes issue 145 more tests" do self.file = 'issue_145.feature' verify_filter([13,15,18], 1..2, 6..13, 15..15, 16..18) end end context "on the same line as step keyword" do - it "should filter on step line" do + it "filters on step line" do verify_filter([17], 1..19) end - it "should filter on scenario outline line" do + it "filters on scenario outline line" do verify_filter([48], 1..14, 46..61) end end context "on examples header line" do - it "should filter on first table" do + it "filters on first table" do verify_filter([52], 1..14, 46..55) end - it "should filter on second table" do + it "filters on second table" do verify_filter([58], 1..14, 46..49, 56..61) end end context "on examples example line" do - it "should filter on first table" do + it "filters on first table" do verify_filter([53], 1..14, 46..53, 55..55) end end context "on tag line" do - it "should filter on first tag" do + it "filters on first tag" do verify_filter([15], 1..19) end end context "multiline argument" do - it "should filter on table line" do + it "filters on table line" do verify_filter([36], 1..14, 20..37) end - it "should filter on first pystring quote" do + it "filters on first pystring quote" do verify_filter([41], 1..14, 38..45) end - it "should filter on last pystring quote" do + it "filters on last pystring quote" do verify_filter([44], 1..14, 38..45) end end diff --git a/spec/gherkin/formatter/json_formatter_spec.rb b/spec/gherkin/formatter/json_formatter_spec.rb index a66a5fd5..5cc7c7f6 100644 --- a/spec/gherkin/formatter/json_formatter_spec.rb +++ b/spec/gherkin/formatter/json_formatter_spec.rb @@ -102,7 +102,7 @@ module Formatter } ] } - MultiJson.load(io.string).should == MultiJson.load(expected) + expect(MultiJson.load(io.string)).to eq(MultiJson.load(expected)) end it "renders results as pretty json" do @@ -121,7 +121,7 @@ module Formatter } ] } - io.string.should == MultiJson.dump(MultiJson.load(expected), :pretty => true) + expect(io.string).to eq(MultiJson.dump(MultiJson.load(expected), :pretty => true)) end it 'supports append_duration' do @@ -172,7 +172,7 @@ module Formatter } ] } - MultiJson.load(io.string).should == MultiJson.load(expected) + expect(MultiJson.load(io.string)).to eq(MultiJson.load(expected)) end end end diff --git a/spec/gherkin/formatter/model_spec.rb b/spec/gherkin/formatter/model_spec.rb index 624dd2b7..30165c83 100644 --- a/spec/gherkin/formatter/model_spec.rb +++ b/spec/gherkin/formatter/model_spec.rb @@ -6,23 +6,23 @@ module Gherkin module Formatter module Model describe Tag do - it "should be equal when name is equal" do + it "is equal when name is equal" do tags = [Tag.new('@x', 1), Tag.new('@y', 2), Tag.new('@x', 3)] - tags.to_a.uniq.length.should == 2 + expect(tags.to_a.uniq.length).to eq(2) end end describe Step do - it "should provide arguments for outline tokens" do + it "provides arguments for outline tokens" do step = Step.new([], 'Given ', "I have cukes in belly", 10, nil, nil) - step.outline_args.map{|arg| [arg.offset, arg.val]}.should == [[7, ""], [25, ""]] + expect(step.outline_args.map{|arg| [arg.offset, arg.val]}).to eq([[7, ""], [25, ""]]) end - it "should provide no arguments when there are no outline tokens" do + it "provides no arguments when there are no outline tokens" do step = Step.new([], 'Given ', "I have 33 cukes in my belly", 10, nil, nil) - step.outline_args.to_a.should == [] + expect(step.outline_args.to_a).to eq([]) end end end end -end \ No newline at end of file +end diff --git a/spec/gherkin/formatter/pretty_formatter_spec.rb b/spec/gherkin/formatter/pretty_formatter_spec.rb index 55d68734..168a4b97 100644 --- a/spec/gherkin/formatter/pretty_formatter_spec.rb +++ b/spec/gherkin/formatter/pretty_formatter_spec.rb @@ -15,9 +15,9 @@ module Formatter def assert_io_include(s) actual = @io.string actual.gsub!(/\e\[m/, "\e[0m") # JANSI resets without the 0. - actual.should include(s) + expect(actual).to include(s) end - + def assert_pretty(input, expected_output=input) [true, false].each do |force_ruby| io = StringIO.new @@ -25,7 +25,7 @@ def assert_pretty(input, expected_output=input) parser = Gherkin::Parser::Parser.new(pf, true, "root", force_ruby) parser.parse(input, "test.feature", 0) output = io.string - output.should == expected_output + expect(output).to eq(expected_output) end end @@ -34,7 +34,7 @@ def assert_pretty(input, expected_output=input) @f = Gherkin::Formatter::PrettyFormatter.new(@io, false, true) end - it "should print comments when scenario is longer" do + it "prints comments when scenario is longer" do @f.uri("features/foo.feature") @f.feature(Model::Feature.new([], [], "Feature", "Hello", "World", 1, "hello")) @@ -61,7 +61,7 @@ def assert_pretty(input, expected_output=input) }) end - it "should print comments when step is longer" do + it "prints comments when step is longer" do @f.uri("features/foo.feature") @f.feature(Model::Feature.new([], [], "Feature", "Hello", "World", 1, "hello")) step = Model::Step.new([], "Given ", "some stuff that is longer", 5, nil, nil) @@ -84,7 +84,7 @@ def assert_pretty(input, expected_output=input) }) end - it "should highlight arguments for regular steps" do + it "highlights arguments for regular steps" do @f.uri("foo.feature") @f.scenario(Model::Scenario.new([], [], "Scenario", "Lots of cukes", "", 3, "lots-of-cukes")) @f.step(Model::Step.new([], "Given ", "I have 999 cukes in my belly", 3, nil, nil)) @@ -101,7 +101,7 @@ def assert_pretty(input, expected_output=input) end # See https://github.com/cucumber/gherkin/pull/171 - it "should highlight arguments when there are optional arguments" do + it "highlights arguments when there are optional arguments" do @f.uri("foo.feature") @f.scenario(Model::Scenario.new([], [], "Scenario", "Lots of cukes", "", 3, "lots-of-cukes")) @f.step(Model::Step.new([], "Given ", "I have 999 cukes in my belly", 3, nil, nil)) @@ -121,7 +121,7 @@ def assert_pretty(input, expected_output=input) ) end - it "should prettify scenario" do + it "prettifies scenario" do assert_pretty(%{Feature: Feature Description Some preamble @@ -141,7 +141,7 @@ def assert_pretty(input, expected_output=input) end - it "should prettify scenario outline with table" do + it "prettifies scenario outline with table" do assert_pretty(%{# A feature comment @foo Feature: Feature Description @@ -169,15 +169,15 @@ def assert_pretty(input, expected_output=input) }) end - it "should preserve tabs" do + it "preserves tabs" do assert_pretty(IO.read(File.dirname(__FILE__) + '/tabs.feature'), IO.read(File.dirname(__FILE__) + '/spaces.feature')) end - it "should escape backslashes and pipes" do + it "escapes backslashes and pipes" do io = StringIO.new f = Gherkin::Formatter::PrettyFormatter.new(io, true, false) f.__send__(:table, [Gherkin::Formatter::Model::DataTableRow.new([], ['|', '\\'], 1)]) - io.string.should == ' | \\| | \\\\ |' + "\n" + expect(io.string).to eq(' | \\| | \\\\ |' + "\n") end end end diff --git a/spec/gherkin/formatter/step_printer_spec.rb b/spec/gherkin/formatter/step_printer_spec.rb index 83038cc3..a76795d1 100644 --- a/spec/gherkin/formatter/step_printer_spec.rb +++ b/spec/gherkin/formatter/step_printer_spec.rb @@ -11,13 +11,13 @@ def text(text) "(#{text})" end end - + class BracketFormat def text(text) "[#{text}]" end end - + describe StepPrinter do before do @io = StringIO.new @@ -26,29 +26,29 @@ def text(text) @bf = BracketFormat.new end - it "should replace 0 args" do + it "replaces 0 args" do @p.write_step(@io, @pf, @bf, "I have 10 cukes", []) - @io.string.should == "(I have 10 cukes)" + expect(@io.string).to eq("(I have 10 cukes)") end - it "should replace 1 arg" do + it "replaces 1 arg" do @p.write_step(@io, @pf, @bf, "I have 10 cukes", [Argument.new(7, '10')]) - @io.string.should == "(I have )[10]( cukes)" + expect(@io.string).to eq("(I have )[10]( cukes)") end - - it "should replace 1 unicode arg" do + + it "replaces 1 unicode arg" do @p.write_step(@io, @pf, @bf, "I hæve øæ cåkes", [Argument.new(7, 'øæ')]) - @io.string.should == "(I hæve )[øæ]( cåkes)" + expect(@io.string).to eq("(I hæve )[øæ]( cåkes)") end - - it "should replace 2 args" do + + it "replaces 2 args" do @p.write_step(@io, @pf, @bf, "I have 10 yellow cukes in my belly", [Argument.new(7, '10'), Argument.new(17, 'cukes')]) - @io.string.should == "(I have )[10]( yellow )[cukes]( in my belly)" + expect(@io.string).to eq("(I have )[10]( yellow )[cukes]( in my belly)") end - it "should replace 2 unicode args" do + it "replaces 2 unicode args" do @p.write_step(@io, @pf, @bf, "Æslåk likes æøå", [Argument.new(0, 'Æslåk'), Argument.new(12, 'æøå')]) - @io.string.should == "[Æslåk]( likes )[æøå]" + expect(@io.string).to eq("[Æslåk]( likes )[æøå]") end end end diff --git a/spec/gherkin/formatter/tag_count_formatter_spec.rb b/spec/gherkin/formatter/tag_count_formatter_spec.rb index f9eb7dd5..19a50abd 100644 --- a/spec/gherkin/formatter/tag_count_formatter_spec.rb +++ b/spec/gherkin/formatter/tag_count_formatter_spec.rb @@ -6,7 +6,7 @@ module Gherkin module Formatter describe TagCountFormatter do - it "should count tags" do + it "counts tags" do tag_counts = {} dummy = Gherkin::SexpRecorder.new formatter = Gherkin::Formatter::TagCountFormatter.new(dummy, tag_counts) @@ -14,8 +14,8 @@ module Formatter f = File.new(File.dirname(__FILE__) + "/../fixtures/complex_with_tags.feature").read parser.parse(f, 'f.feature', 0) - - tag_counts.should == { + + expect(tag_counts).to eq({ "@hamster" => ["f.feature:58"], "@tag1" => ["f.feature:18","f.feature:23","f.feature:39","f.feature:52","f.feature:58"], "@tag2" => ["f.feature:18","f.feature:23","f.feature:39","f.feature:52","f.feature:58"], @@ -23,7 +23,7 @@ module Formatter "@tag4" => ["f.feature:18"], "@neat" => ["f.feature:52"], "@more" => ["f.feature:52", "f.feature:58"] - } + }) end end end From e26ccc883e6b2298f3718e66cd5685009f631610 Mon Sep 17 00:00:00 2001 From: John Voloski Date: Wed, 21 May 2014 12:49:32 -0300 Subject: [PATCH 2/8] doing update from shared's rspec's syntax --- spec/gherkin/shared/doc_string_group.rb | 90 +++---- spec/gherkin/shared/encoding_group.rb | 22 +- spec/gherkin/shared/lexer_group.rb | 323 ++++++++++++------------ spec/gherkin/shared/row_group.rb | 118 ++++----- spec/gherkin/shared/tags_group.rb | 50 ++-- 5 files changed, 301 insertions(+), 302 deletions(-) diff --git a/spec/gherkin/shared/doc_string_group.rb b/spec/gherkin/shared/doc_string_group.rb index cd5ddfba..f73f8188 100644 --- a/spec/gherkin/shared/doc_string_group.rb +++ b/spec/gherkin/shared/doc_string_group.rb @@ -9,8 +9,8 @@ def scan(gherkin) def ps(content) '"""%s"""' % ("\n" + content + "\n") end - - it "should provide the amount of indentation of the triple quotes to the listener" do + + it "provides the amount of indentation of the triple quotes to the listener" do str = < cucumber", 3], [:examples, "Examples", "With a name", "and a description", 4], [:row, ["what"], 6], [:row, ["green"], 7], [:eof] - ] + ]) end - it "should parse with no steps or examples" do + it "parses with no steps or examples" do scan(%{Scenario Outline: Hello Scenario: My Scenario }) - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:scenario_outline, "Scenario Outline", "Hello", "", 1], [:scenario, "Scenario", "My Scenario", "", 3], [:eof] - ] + ]) end - it "should allow multiline description" do + it "allows multiline description" do scan(<<-HERE) Scenario Outline: It is my ambition to say in ten sentences @@ -230,182 +230,181 @@ def scan(gherkin) in a whole book. Given I am a step HERE - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:scenario_outline, "Scenario Outline", "It is my ambition to say", "in ten sentences\n what others say \nin a whole book.", 1], [:step, "Given ", "I am a step", 5], [:eof] - ] - end + ]) + end end describe "Examples" do - it "should be parsed" do + it "is parsed" do scan(%{Examples: |x|y| |5|6| }) - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:examples, "Examples", "", "", 1], [:row, ["x","y"], 2], [:row, ["5","6"], 3], [:eof] - ] + ]) end - - it "should parse multiline example names" do + + it "parses multiline example names" do scan(%{Examples: I'm a multiline name and I'm ok f'real |x| |5| }) - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:examples, "Examples", "I'm a multiline name", "and I'm ok\nf'real", 1], [:row, ["x"], 4], [:row, ["5"], 5], [:eof] - ] + ]) end end - + describe "Steps" do - it "should parse steps with inline table" do - scan(%{Given I have a table + it "parses steps with inline table" do + scan(%{Given I have a table |a|b| }) - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:step, "Given ", "I have a table", 1], [:row, ['a','b'], 2], [:eof] - ] + ]) end - - it "should parse steps with inline doc_string" do + + it "parses steps with inline doc_string" do scan("Given I have a string\n\"\"\"\nhello\nworld\n\"\"\"") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:step, "Given ", "I have a string", 1], [:doc_string, '', "hello\nworld", 2], [:eof] - ] + ]) end - it "should parse steps with an empty name" do + it "parses steps with an empty name" do scan("Given ") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:step, "Given ", "", 1], [:eof] - ] + ]) end end - + describe "A single feature, single scenario, single step" do - it "should find the feature, scenario, and step" do + it "finds the feature, scenario, and step" do scan("Feature: Feature Text\n Scenario: Reading a Scenario\n Given there is a step\n") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "Feature Text", "", 1], [:scenario, "Scenario", "Reading a Scenario", "", 2], [:step, "Given ", "there is a step", 3], [:eof] - ] + ]) end end describe "A feature ending in whitespace" do - it "should not raise an error when whitespace follows the Feature, Scenario, and Steps" do + it "does not raise an error when whitespace follows the Feature, Scenario, and Steps" do scan("Feature: Feature Text\n Scenario: Reading a Scenario\n Given there is a step\n ") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "Feature Text", "", 1], [:scenario, "Scenario", "Reading a Scenario", "", 2], [:step, "Given ", "there is a step", 3], [:eof] - ] + ]) end end describe "A single feature, single scenario, three steps" do - - it "should find the feature, scenario, and three steps" do + it "finds the feature, scenario, and three steps" do scan("Feature: Feature Text\n Scenario: Reading a Scenario\n Given there is a step\n And another step\n And a third step\n") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "Feature Text", "", 1], [:scenario, "Scenario", "Reading a Scenario", "", 2], [:step, "Given ", "there is a step", 3], [:step, "And ", "another step", 4], [:step, "And ", "a third step", 5], [:eof] - ] + ]) end end describe "A single feature with no scenario" do - it "should find the feature" do + it "finds the feature" do scan("Feature: Feature Text\n") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "Feature Text", "", 1], [:eof] - ] + ]) end - it "should parse a one line feature with no newline" do + it "parses an one line feature with no newline" do scan("Feature: hi") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "hi", "", 1], [:eof] - ] + ]) end end - + describe "A multi-line feature with no scenario" do - it "should find the feature" do + it "finds the feature" do scan("Feature: Feature Text\n And some more text") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "Feature Text", "And some more text", 1], [:eof] - ] + ]) end end describe "A feature with a scenario but no steps" do - it "should find the feature and scenario" do + it "finds the feature and scenario" do scan("Feature: Feature Text\nScenario: Reading a Scenario\n") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "Feature Text", "", 1], [:scenario, "Scenario", "Reading a Scenario", "", 2], [:eof] - ] + ]) end end describe "A feature with two scenarios" do - it "should find the feature and two scenarios" do + it "finds the feature and two scenarios" do scan("Feature: Feature Text\nScenario: Reading a Scenario\n Given a step\n\nScenario: A second scenario\n Given another step\n") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "Feature Text", "", 1], [:scenario, "Scenario", "Reading a Scenario", "", 2], [:step, "Given ", "a step", 3], [:scenario, "Scenario", "A second scenario", "", 5], [:step, "Given ", "another step", 6], [:eof] - ] + ]) end - - it "should find the feature and two scenarios without indentation" do + + it "finds the feature and two scenarios without indentation" do scan("Feature: Feature Text\nScenario: Reading a Scenario\nGiven a step\nScenario: A second scenario\nGiven another step\n") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "Feature Text", "", 1], [:scenario, "Scenario", "Reading a Scenario", "", 2], [:step, "Given ", "a step", 3], [:scenario, "Scenario", "A second scenario", "", 4], [:step, "Given ", "another step", 5], [:eof] - ] + ]) end end describe "A simple feature with comments" do - it "should find the feature, scenarios, steps, and comments in the proper order" do + it "finds the feature, scenarios, steps, and comments in the proper order" do scan_file("simple_with_comments.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "# Here is a comment", 1], [:feature, "Feature", "Feature Text", "", 2], [:comment, "# Here is another # comment", 3], @@ -414,28 +413,28 @@ def scan(gherkin) [:step, "Given ", "there is a step", 6], [:comment, "# Here is a fourth comment", 7], [:eof] - ] + ]) end - it "should support comments in tables" do + it "supports comments in tables" do scan_file("comments_in_table.feature") - @listener.to_sexp.should == [ - [:feature, "Feature", "x", "", 1], - [:scenario_outline, "Scenario Outline", "x", "", 3], - [:step, "Then ", "x is ", 4], - [:examples, "Examples", "", "", 6], - [:row, ["state"], 7], - [:comment, "# comment", 8], + expect(@listener.to_sexp).to eq([ + [:feature, "Feature", "x", "", 1], + [:scenario_outline, "Scenario Outline", "x", "", 3], + [:step, "Then ", "x is ", 4], + [:examples, "Examples", "", "", 6], + [:row, ["state"], 7], + [:comment, "# comment", 8], [:row, ["1"], 9], [:eof] - ] + ]) end end - + describe "A feature with tags everywhere" do - it "should find the feature, scenario, step, and tags in the proper order" do + it "finds the feature, scenario, step, and tags in the proper order" do scan_file("simple_with_tags.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "# FC", 1], [:tag, "@ft",2], [:feature, "Feature", "hi", "", 3], @@ -449,28 +448,28 @@ def scan(gherkin) [:tag, "@#^%&ST6**!", 10], [:scenario, "Scenario", "Second", "", 11], [:eof] - ] - end + ]) + end end describe "Comment or tag between Feature elements where previous narrative starts with same letter as a keyword" do - it "should lex this feature properly" do + it "lexs this feature properly" do scan_file("1.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "Logging in", "So that I can be myself", 1], [:comment, "# Comment", 3], [:scenario, "Scenario", "Anonymous user can get a login form.", "Scenery here", 4], [:tag, "@tag", 7], [:scenario, "Scenario", "Another one", "", 8], [:eof] - ] + ]) end - end + end describe "A complex feature with tags, comments, multiple scenarios, and multiple steps and tables" do - it "should find things in the right order" do + it "finds things in the right order" do scan_file("complex.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "#Comment on line 1", 1], [:comment, "#Comment on line 2", 2], [:tag, "@tag1", 3], @@ -497,7 +496,7 @@ def scan(gherkin) [:row, %w{g h}, 31], [:row, %w{e r}, 32], [:row, %w{k i}, 33], - [:row, ['n', ''], 34], + [:row, ['n', ''], 34], [:step, "And ", "I am done testing these tables", 35], [:comment, "#Comment on line 29", 36], [:step, "Then ", "I am happy", 37], @@ -506,14 +505,14 @@ def scan(gherkin) [:doc_string, '', "Makes Homer something something\nAnd something else", 41 ], [:step, "Then ", "crazy", 45], [:eof] - ] - end + ]) + end end - + describe "Windows stuff" do - it "should find things in the right order for CRLF features" do + it "finds things in the right order for CRLF features" do scan_file("dos_line_endings.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "#Comment on line 1", 1], [:comment, "#Comment on line 2", 2], [:tag, "@tag1", 3], @@ -540,7 +539,7 @@ def scan(gherkin) [:row, %w{g h}, 31], [:row, %w{e r}, 32], [:row, %w{k i}, 33], - [:row, ['n', ''], 34], + [:row, ['n', ''], 34], [:step, "And ", "I am done testing these tables", 35], [:comment, "#Comment on line 29", 36], [:step, "Then ", "I am happy", 37], @@ -549,28 +548,28 @@ def scan(gherkin) [:doc_string, '', "Makes Homer something something\r\nAnd something else", 41], [:step, "Then ", "crazy", 45], [:eof] - ] + ]) end end describe "errors" do - it "should raise a Lexing error if an unparseable token is found" do - ["Some text\nFeature: Hi", + it "raises a Lexing error if an unparseable token is found" do + ["Some text\nFeature: Hi", "Feature: Hi\nBackground:\nGiven something\nScenario A scenario", "Scenario: My scenario\nGiven foo\nAand bar\nScenario: another one\nGiven blah"].each do |text| - lambda { scan(text) }.should raise_error(/Lexing error on line/) + expect { scan(text) }.to raise_error(/Lexing error on line/) end end - - it "should include the line number and context of the error" do - lambda { + + it "includes the line number and context of the error" do + expect do scan("Feature: hello\nScenario: My scenario\nGiven foo\nAand blah\nHmmm wrong\nThen something something") - }.should raise_error(/Lexing error on line 4/) + end.to raise_error(/Lexing error on line 4/) end - it "Feature keyword should terminate narratives for multiline capable tokens" do + it "Feature keyword terminates narratives for multiline capable tokens" do scan("Feature:\nBackground:\nFeature:\nScenario Outline:\nFeature:\nScenario:\nFeature:\nExamples:\nFeature:\n") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:feature, "Feature", "", "", 1], [:background, "Background", "", "", 2], [:feature, "Feature", "", "", 3], @@ -581,7 +580,7 @@ def scan(gherkin) [:examples, "Examples", "","", 8], [:feature, "Feature", "", "", 9], [:eof] - ] + ]) end end end diff --git a/spec/gherkin/shared/row_group.rb b/spec/gherkin/shared/row_group.rb index c9372cf8..626c56a0 100644 --- a/spec/gherkin/shared/row_group.rb +++ b/spec/gherkin/shared/row_group.rb @@ -10,113 +10,113 @@ def scan(gherkin) "|a|b|\n" => %w{a b}, "|a|b|c|\n" => %w{a b c}, } - + rows.each do |text, expected| - it "should parse #{text}" do - @listener.should_receive(:row).with(r(expected), 1) + it "is parse #{text}" do + expect(@listener).to receive(:row).with(r(expected), 1) scan(text.dup) end end - it "should parse a row with many cells" do - @listener.should_receive(:row).with(r(%w{a b c d e f g h i j k l m n o p}), 1) + it "parses a row with many cells" do + expect(@listener).to receive(:row).with(r(%w{a b c d e f g h i j k l m n o p}), 1) scan("|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|\n") end - - it "should parse multicharacter cell content" do - @listener.should_receive(:row).with(r(%w{foo bar}), 1) + + it "parses multicharacter cell content" do + expect(@listener).to receive(:row).with(r(%w{foo bar}), 1) scan("| foo | bar |\n") end - it "should escape backslashed pipes" do - @listener.should_receive(:row).with(r(['|', 'the', '\a', '\\', '|\\|']), 1) + it "escapes backslashed pipes" do + expect(@listener).to receive(:row).with(r(['|', 'the', '\a', '\\', '|\\|']), 1) scan('| \| | the | \a | \\ | \|\\\| |' + "\n") end - it "should parse cells with newlines" do - @listener.should_receive(:row).with(r(["\n"]), 1) + it "parses cells with newlines" do + expect(@listener).to receive(:row).with(r(["\n"]), 1) scan("|\\n|" + "\n") end - - it "should parse cells with spaces within the content" do - @listener.should_receive(:row).with(r(["Dill pickle", "Valencia orange"]), 1) + + it "parses cells with spaces within the content" do + expect(@listener).to receive(:row).with(r(["Dill pickle", "Valencia orange"]), 1) scan("| Dill pickle | Valencia orange |\n") end - - it "should allow utf-8" do + + it "allows utf-8" do scan(" | ůﻚ | 2 | \n") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:row, ["ůﻚ", "2"], 1], [:eof] - ] - end + ]) + end - it "should allow utf-8 using should_receive" do - @listener.should_receive(:row).with(r(['繁體中文 而且','並且','繁體中文 而且','並且']), 1) + it "allows utf-8 using should_receive" do + expect(@listener).to receive(:row).with(r(['繁體中文 而且','並且','繁體中文 而且','並且']), 1) scan("| 繁體中文 而且|並且| 繁體中文 而且|並且|\n") end - it "should parse a 2x2 table" do - @listener.should_receive(:row).with(r(%w{1 2}), 1) - @listener.should_receive(:row).with(r(%w{3 4}), 2) + it "parses a 2x2 table" do + expect(@listener).to receive(:row).with(r(%w{1 2}), 1) + expect(@listener).to receive(:row).with(r(%w{3 4}), 2) scan("| 1 | 2 |\n| 3 | 4 |\n") end - it "should parse a 2x2 table with empty cells" do - @listener.should_receive(:row).with(r(['1', '']), 1) - @listener.should_receive(:row).with(r(['', '4']), 2) + it "parses a 2x2 table with empty cells" do + expect(@listener).to receive(:row).with(r(['1', '']), 1) + expect(@listener).to receive(:row).with(r(['', '4']), 2) scan("| 1 | |\n|| 4 |\n") end - it "should parse a row with empty cells" do - @listener.should_receive(:row).with(r(['1', '']), 1).twice + it "parses a row with empty cells" do + expect(@listener).to receive(:row).with(r(['1', '']), 1).twice scan("| 1 | |\n") scan("|1||\n") end - - it "should parse a 1x2 table that does not end in a newline" do - @listener.should_receive(:row).with(r(%w{1 2}), 1) + + it "parses a 1x2 table that does not end in a newline" do + expect(@listener).to receive(:row).with(r(%w{1 2}), 1) scan("| 1 | 2 |") end - it "should parse a row without spaces and with a newline" do - @listener.should_receive(:row).with(r(%w{1 2}), 1) + it "parses a row without spaces and with a newline" do + expect(@listener).to receive(:row).with(r(%w{1 2}), 1) scan("|1|2|\n") end - - it "should parse a row with whitespace after the rows" do - @listener.should_receive(:row).with(r(%w{1 2}), 1) + + it "parses a row with whitespace after the rows" do + expect(@listener).to receive(:row).with(r(%w{1 2}), 1) scan("| 1 | 2 | \n ") end - - it "should parse a row with lots of whitespace" do - @listener.should_receive(:row).with(r(["abc", "123"]), 1) + + it "parses a row with lots of whitespace" do + expect(@listener).to receive(:row).with(r(["abc", "123"]), 1) scan(" \t| \t abc\t| \t123\t \t\t| \t\t \t \t\n ") end - it "should parse a table with a commented-out row" do - @listener.should_receive(:row).with(r(["abc"]), 1) - @listener.should_receive(:comment).with("#|123|", 2) - @listener.should_receive(:row).with(r(["def"]), 3) - scan("|abc|\n#|123|\n|def|\n") + it "parses a table with a commented-out row" do + expect(@listener).to receive(:row).with(r(["abc"]), 1) + expect(@listener).to receive(:comment).with("#|123|", 2) + expect(@listener).to receive(:row).with(r(["def"]), 3) + scan("|abc|\n#|123|\n|def|\n") end - - it "should raise LexingError for rows that aren't closed" do - lambda { - scan("|| oh hello \n") - }.should raise_error(/Lexing error on line 1: '\|\| oh hello/) + + it "raises LexingError for rows that aren't closed" do + expect do + scan("|| oh hello \n") + end.to raise_error(/Lexing error on line 1: '\|\| oh hello/) end - it "should raise LexingError for rows that are followed by a comment" do - lambda { - scan("|hi| # oh hello \n") - }.should raise_error(/Lexing error on line 1: '\|hi\| # oh hello/) + it "raises LexingError for rows that are followed by a comment" do + expect do + scan("|hi| # oh hello \n") + end.to raise_error(/Lexing error on line 1: '\|hi\| # oh hello/) end - it "should raise LexingError for rows that aren't closed" do - lambda { - scan("|| oh hello \n |Shoudn't Get|Here|") - }.should raise_error(/Lexing error on line 1: '\|\| oh hello/) + it "raises LexingError for rows that aren't closed" do + expect do + scan("|| oh hello \n |Shoudn't Get|Here|") + end.to raise_error(/Lexing error on line 1: '\|\| oh hello/) end end end diff --git a/spec/gherkin/shared/tags_group.rb b/spec/gherkin/shared/tags_group.rb index 2d41c358..cf9edc9f 100644 --- a/spec/gherkin/shared/tags_group.rb +++ b/spec/gherkin/shared/tags_group.rb @@ -6,46 +6,46 @@ def scan(gherkin) @lexer.scan(gherkin) end - it "should lex a single tag" do - @listener.should_receive(:tag).with("@dog", 1) + it "lexs a single tag" do + expect(@listener).to receive(:tag).with("@dog", 1) scan("@dog\n") end - - it "should lex multiple tags" do - @listener.should_receive(:tag).twice + + it "lexs multiple tags" do + expect(@listener).to receive(:tag).twice scan("@dog @cat\n") end - - it "should lex UTF-8 tags" do - @listener.should_receive(:tag).with("@シナリオテンプレート", 1) + + it "lexs UTF-8 tags" do + expect(@listener).to receive(:tag).with("@シナリオテンプレート", 1) scan("@シナリオテンプレート\n") end - - it "should lex mixed tags" do - @listener.should_receive(:tag).with("@wip", 1).ordered - @listener.should_receive(:tag).with("@Значения", 1).ordered + + it "lexs mixed tags" do + expect(@listener).to receive(:tag).with("@wip", 1).ordered + expect(@listener).to receive(:tag).with("@Значения", 1).ordered scan("@wip @Значения\n") end - - it "should lex wacky identifiers" do - @listener.should_receive(:tag).exactly(4).times + + it "lexs wacky identifiers" do + expect(@listener).to receive(:tag).exactly(4).times scan("@BJ-x98.77 @BJ-z12.33 @O_o" "@#not_a_comment\n") end # TODO: Ask on ML for opinions about this one - it "should lex tags without spaces between them?" do - @listener.should_receive(:tag).twice + it "lexs tags without spaces between them?" do + expect(@listener).to receive(:tag).twice scan("@one@two\n") end - - it "should not lex tags beginning with two @@ signs" do - @listener.should_not_receive(:tag) - lambda { scan("@@test\n") }.should raise_error(/Lexing error on line 1/) + + it "does not lex tags beginning with two @@ signs" do + expect(@listener).not_to receive(:tag) + expect { scan("@@test\n") }.to raise_error(/Lexing error on line 1/) end - - it "should not lex a lone @ sign" do - @listener.should_not_receive(:tag) - lambda { scan("@\n") }.should raise_error(/Lexing error on line 1/) + + it "does not lex a lone @ sign" do + expect(@listener).not_to receive(:tag) + expect { scan("@\n") }.to raise_error(/Lexing error on line 1/) end end end From 2d1bcd48b0dfb6a123722871f2dd684681fd8535 Mon Sep 17 00:00:00 2001 From: John Voloski Date: Wed, 21 May 2014 12:49:48 -0300 Subject: [PATCH 3/8] doing update from parser's rspec's syntax --- spec/gherkin/parser/parser_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/gherkin/parser/parser_spec.rb b/spec/gherkin/parser/parser_spec.rb index 3550093f..a0070d09 100644 --- a/spec/gherkin/parser/parser_spec.rb +++ b/spec/gherkin/parser/parser_spec.rb @@ -4,11 +4,11 @@ module Gherkin module Parser describe Parser do unless defined?(JRUBY_VERSION) - it "should raise when feature doesn't parse" do + it "raises when feature doesn't parse" do p = Parser.new(double('formatter').as_null_object) - lambda do + expect do p.parse("Feature: f\nFeature: f", __FILE__, __LINE__-1) - end.should raise_error(Regexp.new("Parse error at #{__FILE__}:\\d+")) + end.to raise_error(Regexp.new("Parse error at #{__FILE__}:\\d+")) end end end From 8ca2e44672a6b1ec2e5a1cc7cffbbee62538308e Mon Sep 17 00:00:00 2001 From: John Voloski Date: Wed, 21 May 2014 12:50:05 -0300 Subject: [PATCH 4/8] doing update from lexer's rspec's syntax --- spec/gherkin/lexer/i18n_lexer_spec.rb | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/gherkin/lexer/i18n_lexer_spec.rb b/spec/gherkin/lexer/i18n_lexer_spec.rb index 5f37c0ec..a95ab2a5 100644 --- a/spec/gherkin/lexer/i18n_lexer_spec.rb +++ b/spec/gherkin/lexer/i18n_lexer_spec.rb @@ -9,39 +9,39 @@ module Lexer @lexer = Gherkin::Lexer::I18nLexer.new(Gherkin::SexpRecorder.new, false) end - it "should store the i18n language of the last scanned feature" do + it "stores the i18n language of the last scanned feature" do @lexer.scan("# language: fr\n") # This if is kind of dumb - it's just to avoid warnings from ruby - if(@lexer.i18n_language.iso_code.should == "fr") + if(expect(@lexer.i18n_language.iso_code).to eq("fr")) @lexer.scan("# language: no\n") - @lexer.i18n_language.iso_code.should == "no" + expect(@lexer.i18n_language.iso_code).to eq("no") else fail end end - it "should detect language when there are spaces and CRLF" do + it "detects language when there are spaces and CRLF" do @lexer.scan("# language: da \r\n") - @lexer.i18n_language.iso_code.should == "da" + expect(@lexer.i18n_language.iso_code).to eq("da") end - it "should detect language when the language comment is not the first line" do + it "detects language when the language comment is not the first line" do @lexer.scan("# hello\n# language: no\n") - @lexer.i18n_language.iso_code.should == "no" + expect(@lexer.i18n_language.iso_code).to eq("no") end - it "should detect language when the language is on the third line, and there are empty lines above" do + it "detects language when the language is on the third line, and there are empty lines above" do @lexer.scan("# hello\n\n# language: no\n") - @lexer.i18n_language.iso_code.should == "no" + expect(@lexer.i18n_language.iso_code).to eq("no") end - it "should use English i18n by default" do + it "uses English i18n by default" do @lexer.scan("Feature: foo\n") - @lexer.i18n_language.iso_code.should == "en" + expect(@lexer.i18n_language.iso_code).to eq("en") end - it "should === its ruby class, even when the impl is Java" do - Gherkin::Lexer::I18nLexer.should === Gherkin::Lexer::I18nLexer.new(Gherkin::SexpRecorder.new, true) + it "is === its ruby class, even when the impl is Java" do + expect(Gherkin::Lexer::I18nLexer).to be === Gherkin::Lexer::I18nLexer.new(Gherkin::SexpRecorder.new, true) end end @@ -50,14 +50,14 @@ module Lexer @lexer = Gherkin::Lexer::I18nLexer.new(Gherkin::SexpRecorder.new, false, 'ja') end - it "should store the i18n language of the last scanned feature" do + it "stores the i18n language of the last scanned feature" do @lexer.scan("# language: en") - @lexer.i18n_language.iso_code.should == "en" + expect(@lexer.i18n_language.iso_code).to eq("en") end - it "should use Japanese" do + it "uses Japanese" do @lexer.scan("機能: foo\n") - @lexer.i18n_language.iso_code.should == "ja" + expect(@lexer.i18n_language.iso_code).to eq("ja") end end end From 391ad7780d12473344c6de25acb1a6882e5bff00 Mon Sep 17 00:00:00 2001 From: John Voloski Date: Wed, 21 May 2014 12:50:23 -0300 Subject: [PATCH 5/8] doing update from gherkin's rspec's syntax --- spec/gherkin/c_lexer_spec.rb | 30 ++++----- spec/gherkin/i18n_spec.rb | 98 ++++++++++++++--------------- spec/gherkin/java_lexer_spec.rb | 26 ++++---- spec/gherkin/json_parser_spec.rb | 10 +-- spec/gherkin/rubify_spec.rb | 12 ++-- spec/gherkin/sexp_recorder.rb | 4 +- spec/gherkin/tag_expression_spec.rb | 86 ++++++++++++------------- spec/spec_helper.rb | 2 +- 8 files changed, 134 insertions(+), 134 deletions(-) diff --git a/spec/gherkin/c_lexer_spec.rb b/spec/gherkin/c_lexer_spec.rb index 919c7789..71952cfb 100644 --- a/spec/gherkin/c_lexer_spec.rb +++ b/spec/gherkin/c_lexer_spec.rb @@ -1,22 +1,22 @@ #encoding: utf-8 unless defined?(JRUBY_VERSION) -require 'spec_helper' -require 'gherkin_lexer_en' + require 'spec_helper' + require 'gherkin_lexer_en' -module Gherkin - module Lexer - describe "C Lexer" do - before do - @listener = Gherkin::SexpRecorder.new - @lexer = Gherkin::CLexer::En.new(@listener) - end + module Gherkin + module Lexer + describe "C Lexer" do + before do + @listener = Gherkin::SexpRecorder.new + @lexer = Gherkin::CLexer::En.new(@listener) + end - it_should_behave_like "a Gherkin lexer" - it_should_behave_like "a Gherkin lexer lexing tags" - it_should_behave_like "a Gherkin lexer lexing doc_strings" - it_should_behave_like "a Gherkin lexer lexing rows" - it_should_behave_like "encoding" + it_should_behave_like "a Gherkin lexer" + it_should_behave_like "a Gherkin lexer lexing tags" + it_should_behave_like "a Gherkin lexer lexing doc_strings" + it_should_behave_like "a Gherkin lexer lexing rows" + it_should_behave_like "encoding" + end end end end -end diff --git a/spec/gherkin/i18n_spec.rb b/spec/gherkin/i18n_spec.rb index 9488f679..e8e9a45d 100644 --- a/spec/gherkin/i18n_spec.rb +++ b/spec/gherkin/i18n_spec.rb @@ -13,10 +13,10 @@ def scan_file(lexer, file) lexer.scan(File.new(File.dirname(__FILE__) + "/fixtures/" + file).read) end - it "should recognize keywords in the language of the lexer" do + it "recognizes keywords in the language of the lexer" do lexer = Gherkin::Lexer::I18nLexer.new(@listener, false) scan_file(lexer, "i18n_no.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "#language:no", 1], [:feature, "Egenskap", "i18n support", "", 2], [:scenario, "Scenario", "Parsing many languages", "", 4], @@ -24,13 +24,13 @@ def scan_file(lexer, file) [:step, "Når ", "Norwegian keywords are parsed", 6], [:step, "Så ", "they should be recognized", 7], [:eof] - ] + ]) end - it "should recognize keywords that are a little ambiguous" do + it "recognizes keywords that are a little ambiguous" do lexer = Gherkin::Lexer::I18nLexer.new(@listener, false) scan_file(lexer, "i18n_fr2.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "#language:fr", 1], [:feature, "Fonctionnalité", "i18n", "", 2], [:scenario, "Scénario", "Le French", "", 4], @@ -39,13 +39,13 @@ def scan_file(lexer, file) [:step, "Etant donnés ", "qqch", 7], [:step, "Etant données ", "qqch", 8], [:eof] - ] + ]) end - it "should parse languages without a space after keywords" do + it "parses languages without a space after keywords" do lexer = Gherkin::Lexer::I18nLexer.new(@listener, false) scan_file(lexer, "i18n_zh-CN.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "#language:zh-CN", 1], [:feature, "功能", "加法", "", 2], [:scenario, "场景", "两个数相加", "", 4], @@ -54,13 +54,13 @@ def scan_file(lexer, file) [:step, "当", "我按相加按钮", 7], [:step, "那么", "我应该在屏幕上看到的结果是13", 8], [:eof] - ] + ]) end - it "should parse languages with spaces after some keywords but not others" do + it "parses languages with spaces after some keywords but not others" do lexer = Gherkin::Lexer::I18nLexer.new(@listener, false) scan_file(lexer, "i18n_fr.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "#language:fr", 1], [:feature, "Fonctionnalité", "Addition", "", 2], [:scenario_outline, "Plan du scénario", "Addition de produits dérivés", "", 3], @@ -74,13 +74,13 @@ def scan_file(lexer, file) [:row, %w{2 2 4}, 12], [:row, %w{2 3 5}, 13], [:eof] - ] + ]) end - it "should recognize keywords in Portuguese (1st variant)" do + it "recognizes keywords in Portuguese (1st variant)" do lexer = Gherkin::Lexer::I18nLexer.new(@listener, false) scan_file(lexer, "i18n_pt1.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "# language: pt", 1], [:feature, "Funcionalidade", "Reconhece \"Funcionalidade\"", "", 2], [:background, "Contexto", "Reconhece \"Contexto\"", "", 4], @@ -115,46 +115,46 @@ def scan_file(lexer, file) [:row, ["Valor"], 43], [:row, ["1"], 44], [:eof] - ] + ]) end - it "should recognize keywords in Portuguese (2nd variant)" do + it "recognizes keywords in Portuguese (2nd variant)" do lexer = Gherkin::Lexer::I18nLexer.new(@listener, false) scan_file(lexer, "i18n_pt2.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "# language: pt", 1], [:feature, "Característica", "Reconhece \"Característica\" com acento", "", 2], [:background, "Cenário de Fundo", "Reconhece \"Cenário de Fundo\" com acento", "", 4], [:eof] - ] + ]) end - it "should recognize keywords in Portuguese (3rd variant)" do + it "recognizes keywords in Portuguese (3rd variant)" do lexer = Gherkin::Lexer::I18nLexer.new(@listener, false) scan_file(lexer, "i18n_pt3.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "# language: pt", 1], [:feature, "Caracteristica", "Reconhece \"Característica\" sem acento", "", 2], [:background, "Cenario de Fundo", "Reconhece \"Cenário de Fundo\" sem acento", "", 4], [:eof] - ] + ]) end - it "should recognize keywords in Portuguese (4th variant)" do + it "recognizes keywords in Portuguese (4th variant)" do lexer = Gherkin::Lexer::I18nLexer.new(@listener, false) scan_file(lexer, "i18n_pt4.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "# language: pt", 1], [:feature, "Característica", "Reconhece \"Característica\" com acento", "", 2], [:background, "Fundo", "Reconhece \"Fundo\"", "", 4], [:eof] - ] + ]) end - it "should recognize keywords in Klingon" do + it "recognizes keywords in Klingon" do lexer = Gherkin::Lexer::I18nLexer.new(@listener, false) scan_file(lexer, "i18n_tlh.feature") - @listener.to_sexp.should == [ + expect(@listener.to_sexp).to eq([ [:comment, "#language:tlh", 1], [:feature, "poQbogh malja'", "tlhIngan Hol", "tlhIngan Hol ghItlhmeH\nghunbogh qaD lo'wI'.", 2], [:scenario_outline, "lut chovnatlh", "SuvwI'", "", 6], @@ -167,48 +167,48 @@ def scan_file(lexer, file) [:row, ["3", "2"], 14], [:row, ["5", "3"], 15], [:eof] - ] + ]) end describe 'keywords' do - it "should have code keywords without space, comma, exclamation or apostrophe" do + it "has code keywords without space, comma, exclamation or apostrophe" do ['Avast', 'Akkor', 'Etantdonné', 'Lorsque', '假設'].each do |code_keyword| - Gherkin::I18n.code_keywords.should include(code_keyword) + expect(Gherkin::I18n.code_keywords).to include(code_keyword) end end - it "should reject the bullet stars" do - Gherkin::I18n.code_keywords.should_not include('*') + it "rejects the bullet stars" do + expect(Gherkin::I18n.code_keywords).not_to include('*') end - it "should report keyword regexp" do - Gherkin::I18n.keyword_regexp(:step).should =~ /\|Quando \|Quand \|Quan \|Pryd \|/ + it "reports keyword regexp" do + expect(Gherkin::I18n.keyword_regexp(:step)).to match(/\|Quando \|Quand \|Quan \|Pryd \|/) end - it "should include Arabic, English and Chinese traditional in the language table" do + it "includes Arabic, English and Chinese traditional in the language table" do language_table = "\n" + Gherkin::I18n.language_table - language_table.should include(%{ + expect(language_table).to include(%{ | ar | Arabic | العربية | }) - language_table.should include(%{ + expect(language_table).to include(%{ | en | English | English | }) - language_table.should include(%{ + expect(language_table).to include(%{ | zh-TW | Chinese traditional | 繁體中文 | }) end - it "should print available languages" do + it "prints available languages" do languages = MultiJson.load(File.open(File.dirname(__FILE__) + '/../../lib/gherkin/i18n.json', 'r:utf-8').read).keys language_table = Gherkin::I18n.language_table - language_table.lines.count.should == languages.count + expect(language_table.lines.count).to eq(languages.count) for language in languages do - ("\n" + language_table).should include("\n | " + language + " ") + expect("\n" + language_table).to include("\n | " + language + " ") end end - it "should print keywords for a given language" do - ("\n" + Gherkin::I18n.get('fr').keyword_table).should == %{ + it "prints keywords for a given language" do + expect("\n" + Gherkin::I18n.get('fr').keyword_table).to eq(%{ | feature | "Fonctionnalité" | | background | "Contexte" | | scenario | "Scénario" | @@ -224,11 +224,11 @@ def scan_file(lexer, file) | then (code) | "Alors" | | and (code) | "Et" | | but (code) | "Mais" | -} +}) end - it "should print keywords in Klingon" do - ("\n" + Gherkin::I18n.get('tlh').keyword_table).should == %{ + it "prints keywords in Klingon" do + expect("\n" + Gherkin::I18n.get('tlh').keyword_table).to eq(%{ | feature | "Qap", "Qu'meH 'ut", "perbogh", "poQbogh malja'", "laH" | | background | "mo'" | | scenario | "lut" | @@ -244,13 +244,13 @@ def scan_file(lexer, file) | then (code) | "vaj" | | and (code) | "ej", "latlh" | | but (code) | "ach", "a" | -} +}) end - it "should not list keywords that start with a number" do - Gherkin::I18n.get('en-old').code_keywords.should include("Ðaðe") - Gherkin::I18n.get('en-old').code_keywords.should_not include("7") + it "does not list keywords that start with a number" do + expect(Gherkin::I18n.get('en-old').code_keywords).to include("Ðaðe") + expect(Gherkin::I18n.get('en-old').code_keywords).not_to include("7") end end end diff --git a/spec/gherkin/java_lexer_spec.rb b/spec/gherkin/java_lexer_spec.rb index caed3464..7a14a97f 100644 --- a/spec/gherkin/java_lexer_spec.rb +++ b/spec/gherkin/java_lexer_spec.rb @@ -1,20 +1,20 @@ #encoding: utf-8 if defined?(JRUBY_VERSION) -require 'spec_helper' + require 'spec_helper' -module Gherkin - module JavaLexer - describe "Java Lexer" do - before do - @listener = Gherkin::SexpRecorder.new - @lexer = Java::GherkinLexer::I18nLexer.new(@listener) - end + module Gherkin + module JavaLexer + describe "Java Lexer" do + before do + @listener = Gherkin::SexpRecorder.new + @lexer = Java::GherkinLexer::I18nLexer.new(@listener) + end - it_should_behave_like "a Gherkin lexer" - it_should_behave_like "a Gherkin lexer lexing tags" - it_should_behave_like "a Gherkin lexer lexing doc_strings" - it_should_behave_like "a Gherkin lexer lexing rows" + it_should_behave_like "a Gherkin lexer" + it_should_behave_like "a Gherkin lexer lexing tags" + it_should_behave_like "a Gherkin lexer lexing doc_strings" + it_should_behave_like "a Gherkin lexer lexing rows" + end end end end -end diff --git a/spec/gherkin/json_parser_spec.rb b/spec/gherkin/json_parser_spec.rb index 6b4758d4..f43abc4a 100644 --- a/spec/gherkin/json_parser_spec.rb +++ b/spec/gherkin/json_parser_spec.rb @@ -18,7 +18,7 @@ def check_json(json) actual = MultiJson.load(io.string) begin - actual.should == expected + expect(actual).to eq(expected) rescue puts "EXPECTED" puts json @@ -30,7 +30,7 @@ def check_json(json) end end - it "should parse a barely empty feature" do + it "parses a barely empty feature" do check_json(%{[ { "id": "one", @@ -43,7 +43,7 @@ def check_json(json) ]}) end - it "should parse feature with tags and one scenario" do + it "parses feature with tags and one scenario" do check_json(%{[ { "id": "one", @@ -78,7 +78,7 @@ def check_json(json) ]}) end - it "should parse feature with match, result and embedding" do + it "parses feature with match, result and embedding" do check_json(%{ [ { @@ -158,7 +158,7 @@ def check_json(json) }) end - it "shoud parse a complex feature" do + it "parses a complex feature" do check_json('[' + fixture("complex.json") + ']') end end diff --git a/spec/gherkin/rubify_spec.rb b/spec/gherkin/rubify_spec.rb index a18876d2..58396f3a 100644 --- a/spec/gherkin/rubify_spec.rb +++ b/spec/gherkin/rubify_spec.rb @@ -8,16 +8,16 @@ module Rubify describe "rubify" do before do @java_collection = [double("Java.java.util.ArrayList")] - @java_collection.stub(:===).and_return(Java.java.util.Collection) - @java_collection.stub(:line).and_return(15) + allow(@java_collection).to receive(:===).and_return(Java.java.util.Collection) + allow(@java_collection).to receive(:line).and_return(15) @rubified_array = rubify(@java_collection) end - it "should keep the line number attribute from Java object" do - @rubified_array.should respond_to(:line) - @rubified_array.line.should == 15 + it "keeps the line number attribute from Java object" do + expect(@rubified_array).to respond_to(:line) + expect(@rubified_array.line).to eq(15) end end end end -end \ No newline at end of file +end diff --git a/spec/gherkin/sexp_recorder.rb b/spec/gherkin/sexp_recorder.rb index 9a6133ce..213a5cc4 100644 --- a/spec/gherkin/sexp_recorder.rb +++ b/spec/gherkin/sexp_recorder.rb @@ -4,7 +4,7 @@ module Gherkin class SexpRecorder include Rubify - + def initialize @sexps = [] end @@ -36,7 +36,7 @@ def line(number) end def sexpify(o) - array = (defined?(JRUBY_VERSION) && Java.java.util.Collection === o) || + array = (defined?(JRUBY_VERSION) && Java.java.util.Collection === o) || (defined?(V8) && V8::Array === o) || Array === o if array diff --git a/spec/gherkin/tag_expression_spec.rb b/spec/gherkin/tag_expression_spec.rb index 9289a09d..40a9e0bd 100644 --- a/spec/gherkin/tag_expression_spec.rb +++ b/spec/gherkin/tag_expression_spec.rb @@ -13,16 +13,16 @@ def tag(name) @e = Gherkin::TagExpression.new([]) end - it 'should be empty' do - @e.should be_empty + it 'is empty' do + expect(@e).to be_empty end - it "should match @foo" do - @e.evaluate([tag('@foo')]).should == true + it "matchs @foo" do + expect(@e.evaluate([tag('@foo')])).to be_true end - it "should match empty tags" do - @e.evaluate([]).should == true + it "matchs empty tags" do + expect(@e.evaluate([])).to be_true end end @@ -31,16 +31,16 @@ def tag(name) @e = Gherkin::TagExpression.new(['@foo']) end - it "should match @foo" do - @e.evaluate([tag('@foo')]).should == true + it "matchs @foo" do + expect(@e.evaluate([tag('@foo')])).to be_true end - it "should not match @bar" do - @e.evaluate([tag('@bar')]).should == false + it "does not match @bar" do + expect(@e.evaluate([tag('@bar')])).to be_false end - it "should not match no tags" do - @e.evaluate([]).should == false + it "does not match no tags" do + expect(@e.evaluate([])).to be_false end end @@ -49,12 +49,12 @@ def tag(name) @e = Gherkin::TagExpression.new(['~@foo']) end - it "should match @bar" do - @e.evaluate([tag('@bar')]).should == true + it "matchs @bar" do + expect(@e.evaluate([tag('@bar')])).to be_true end - it "should not match @foo" do - @e.evaluate([tag('@foo')]).should == false + it "does not match @foo" do + expect(@e.evaluate([tag('@foo')])).to be_false end end @@ -63,16 +63,16 @@ def tag(name) @e = Gherkin::TagExpression.new(['@foo,@bar']) end - it "should match @foo" do - @e.evaluate([tag('@foo')]).should == true + it "matchs @foo" do + expect(@e.evaluate([tag('@foo')])).to be_true end - it "should match @bar" do - @e.evaluate([tag('@bar')]).should == true + it "matchs @bar" do + expect(@e.evaluate([tag('@bar')])).to be_true end - it "should not match @zap" do - @e.evaluate([tag('@zap')]).should == false + it "does not match @zap" do + expect(@e.evaluate([tag('@zap')])).to be_false end end @@ -81,12 +81,12 @@ def tag(name) @e = Gherkin::TagExpression.new(['@foo,@bar', '~@zap']) end - it "should match @foo" do - @e.evaluate([tag('@foo')]).should == true + it "matchs @foo" do + expect(@e.evaluate([tag('@foo')])).to be_true end - it "should not match @foo @zap" do - @e.evaluate([tag('@foo'), tag('@zap')]).should == false + it "does not match @foo @zap" do + expect(@e.evaluate([tag('@foo'), tag('@zap')])).to be_false end end @@ -95,12 +95,12 @@ def tag(name) @e = Gherkin::TagExpression.new(['@foo:3,~@bar','@zap:5']) end - it "should count tags for positive tags" do - rubify_hash(@e.limits).should == {'@foo' => 3, '@zap' => 5} + it "counts tags for positive tags" do + expect(rubify_hash(@e.limits)).to eq({ '@foo' => 3, '@zap' => 5 }) end - it "should match @foo @zap" do - @e.evaluate([tag('@foo'), tag('@zap')]).should == true + it "matchs @foo @zap" do + expect(@e.evaluate([tag('@foo'), tag('@zap')])).to be_true end end @@ -110,36 +110,36 @@ def tag(name) end unless defined?(JRUBY_VERSION) - it "should split and trim (ruby implementation detail)" do - @e.__send__(:ruby_expression).should == "(!vars['@bar']||vars['@foo'])&&(vars['@zap'])" + it "splits and trim (ruby implementation detail)" do + expect(@e.__send__(:ruby_expression)).to eq("(!vars['@bar']||vars['@foo'])&&(vars['@zap'])") end end - it "should have limits" do - rubify_hash(@e.limits).should == {"@zap"=>5, "@foo"=>3} + it "has limits" do + expect(rubify_hash(@e.limits)).to eq({ "@zap" => 5, "@foo" => 3 }) end end context "Tag limits" do - it "should be counted for negative tags" do + it "is counted for negative tags" do @e = Gherkin::TagExpression.new(['~@todo:3']) - rubify_hash(@e.limits).should == {"@todo"=>3} + expect(rubify_hash(@e.limits)).to eq({ "@todo" => 3 }) end - it "should be counted for positive tags" do + it "is counted for positive tags" do @e = Gherkin::TagExpression.new(['@todo:3']) - rubify_hash(@e.limits).should == {"@todo"=>3} + expect(rubify_hash(@e.limits)).to eq({ "@todo" => 3 }) end - it "should raise an error for inconsistent limits" do - lambda do + it "raises an error for inconsistent limits" do + expect do @e = Gherkin::TagExpression.new(['@todo:3', '~@todo:4']) - end.should raise_error(/Inconsistent tag limits for @todo: 3 and 4/) + end.to raise_error(/Inconsistent tag limits for @todo: 3 and 4/) end - it "should allow duplicate consistent limits" do + it "allows duplicate consistent limits" do @e = Gherkin::TagExpression.new(['@todo:3', '~@todo:3']) - rubify_hash(@e.limits).should == {"@todo"=>3} + expect(rubify_hash(@e.limits)).to eq({ "@todo" => 3 }) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0f6e3ae0..89977c5a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -66,7 +66,7 @@ def row.inspect "r " + self.map{|cell| cell}.inspect end end - row.map{|cell| cell}.should == expected + expect(row.map{|cell| cell}).to eq(expected) end end From 8ff0b4097d1676b6125edc30cebabead1975fe73 Mon Sep 17 00:00:00 2001 From: John Voloski Date: Wed, 21 May 2014 12:52:46 -0300 Subject: [PATCH 6/8] doing update from step_definition's rspec's syntax --- features/step_definitions/gherkin_steps.rb | 2 +- features/step_definitions/json_formatter_steps.rb | 5 +---- features/step_definitions/json_parser_steps.rb | 2 +- features/step_definitions/pretty_formatter_steps.rb | 8 ++++---- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/features/step_definitions/gherkin_steps.rb b/features/step_definitions/gherkin_steps.rb index 0dbedd0b..7d8128f5 100644 --- a/features/step_definitions/gherkin_steps.rb +++ b/features/step_definitions/gherkin_steps.rb @@ -7,7 +7,7 @@ end Then "there should be no parse errors" do - @formatter.errors.should == [] + expect(@formatter.errors).to eq [] end Then /^there should be a parse error on (line \d+)$/ do |line| diff --git a/features/step_definitions/json_formatter_steps.rb b/features/step_definitions/json_formatter_steps.rb index 3df5f825..fc23c18d 100644 --- a/features/step_definitions/json_formatter_steps.rb +++ b/features/step_definitions/json_formatter_steps.rb @@ -23,8 +23,5 @@ def keys puts MultiJson.dump(MultiJson.load(actual_json), :pretty => true) expected = MultiJson.load(expected_json) actual = MultiJson.load(actual_json) - actual.should == expected + expect(actual).to eq expected end - - - diff --git a/features/step_definitions/json_parser_steps.rb b/features/step_definitions/json_parser_steps.rb index eb748c75..3a0ab9b6 100644 --- a/features/step_definitions/json_parser_steps.rb +++ b/features/step_definitions/json_parser_steps.rb @@ -17,5 +17,5 @@ end Then /^the outputted text should be:$/ do |expected_text| - @io.string.strip.should == expected_text + expect(@io.string.strip).to eq expected_text end diff --git a/features/step_definitions/pretty_formatter_steps.rb b/features/step_definitions/pretty_formatter_steps.rb index ec8d9f95..608ccb4e 100644 --- a/features/step_definitions/pretty_formatter_steps.rb +++ b/features/step_definitions/pretty_formatter_steps.rb @@ -6,7 +6,7 @@ require 'gherkin/json_parser' module PrettyPlease - + def pretty_machinery(gherkin, feature_path) io = StringIO.new formatter = Gherkin::Formatter::PrettyFormatter.new(io, true, false) @@ -26,10 +26,10 @@ def json_machinery(gherkin, feature_path) pretty_formatter = Gherkin::Formatter::PrettyFormatter.new(io, true, false) json_parser = Gherkin::JSONParser.new(pretty_formatter, pretty_formatter) json_parser.parse(json.string) - + io.string end - + def parse(parser, gherkin, feature_path) begin parser.parse(gherkin, feature_path, 0) @@ -63,7 +63,7 @@ def parse(parser, gherkin, feature_path) next if feature_path =~ /iso-8859-1\.feature/ original = pretty_machinery(IO.read(feature_path), feature_path) via_machinery = self.__send__("#{machinery}_machinery", original, feature_path) - via_machinery.should == original + expect(via_machinery).to eq original rescue RSpec::Expectations::ExpectationNotMetError => e announce "==========" announce feature_path From 67473d510274ad2b191c20d8c39781fabb9a5172 Mon Sep 17 00:00:00 2001 From: John Voloski Date: Thu, 22 May 2014 15:35:31 -0300 Subject: [PATCH 7/8] adding travis-ci support to ruby 2.1.*, adding badges for gem version, dependecies and tests's coverage --- .travis.yml | 3 +++ README.md | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d5b7d1fd..809c0712 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ before_install: gem install bundler -v 1.3.5 rvm: + - 2.1.2 + - 2.1.1 + - 2.1.0 - 2.0.0 - 1.9.3 - jruby diff --git a/README.md b/README.md index fd9dafe5..1b65acad 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ [![Build Status](https://secure.travis-ci.org/cucumber/gherkin.png)](http://travis-ci.org/cucumber/gherkin) +[![Gem Version](https://badge.fury.io/rb/gherkin.svg)](http://badge.fury.io/rb/gherkin) +[![Dependency Status](https://gemnasium.com/cucumber/gherkin.png)](https://gemnasium.com/cucumber/gherkin) +[![Code Climate](https://codeclimate.com/github/cucumber/gherkin.png)](https://codeclimate.com/github/cucumber/gherkin) A fast lexer and parser for the Gherkin language based on Ragel. Gherkin is two things: @@ -7,7 +10,7 @@ A fast lexer and parser for the Gherkin language based on Ragel. Gherkin is two Supported platforms: -* [Ruby](https://rubygems.org/gems/gherkin) 1.9.3-2.0.0 (MRI, JRuby, REE, Rubinius) +* [Ruby](https://rubygems.org/gems/gherkin) 1.9.3, 2.0.0, 2.1.* (MRI, JRuby, REE, Rubinius) * [Pure Java](http://search.maven.org/#search%7Cga%7C1%7Cgherkin) (jar file) * [JavaScript](http://search.npmjs.org/#/gherkin) (Tested with V8/node.js/Chrome, but might work on other JavaScript engines) * [.NET](http://nuget.org/List/Packages/gherkin) (dll file) From c573b4e963f9e0b066b8111e467eb6d5b1cf6d62 Mon Sep 17 00:00:00 2001 From: John Voloski Date: Thu, 22 May 2014 17:06:20 -0300 Subject: [PATCH 8/8] fix ruby 2.1.0 support --- .travis.yml | 2 -- README.md | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 809c0712..11c68ddd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ before_install: gem install bundler -v 1.3.5 rvm: - - 2.1.2 - - 2.1.1 - 2.1.0 - 2.0.0 - 1.9.3 diff --git a/README.md b/README.md index 1b65acad..31eb6cc7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A fast lexer and parser for the Gherkin language based on Ragel. Gherkin is two Supported platforms: -* [Ruby](https://rubygems.org/gems/gherkin) 1.9.3, 2.0.0, 2.1.* (MRI, JRuby, REE, Rubinius) +* [Ruby](https://rubygems.org/gems/gherkin) 1.9.3, 2.0.0, 2.1.0 (MRI, JRuby, REE, Rubinius) * [Pure Java](http://search.maven.org/#search%7Cga%7C1%7Cgherkin) (jar file) * [JavaScript](http://search.npmjs.org/#/gherkin) (Tested with V8/node.js/Chrome, but might work on other JavaScript engines) * [.NET](http://nuget.org/List/Packages/gherkin) (dll file)