Best Gherkin-ruby code snippet using Gherkin.tags
parser_spec.rb
Source:parser_spec.rb
...12 ast = parser.parse(scanner)13 expect(ast).to eq({14 feature: {15 type: :Feature,16 tags: [],17 location: {line: 1, column: 1},18 language: "en",19 keyword: "Feature",20 name: "test",21 children: []22 },23 comments: [],24 type: :GherkinDocument25 })26 end27 it "parses a complex feature" do28 # This should include every significant type of thing within the language29 feature_text = "@feature_tag\n" +30 "Feature: feature name\n" +31 " feature description\n" +32 "\n" +33 " Background: background name\n" +34 " background description\n" +35 " * a step\n" +36 "\n" +37 " @scenario_tag\n" +38 " Scenario: scenario name\n" +39 " scenario description\n" +40 " * a step with a table\n" +41 " | a table |\n" +42 "\n" +43 " @outline_tag\n" +44 " Scenario Outline: outline name\n" +45 " outline description\n" +46 " * a step with a doc string\n" +47 " \"\"\" content_type\n" +48 " lots of text\n" +49 " \"\"\"\n" +50 " # Random file comment\n" +51 " @example_tag\n" +52 " Examples: examples name\n" +53 " examples description\n" +54 " | param |\n" +55 " | value |\n"56 parser = Parser.new57 scanner = TokenScanner.new(feature_text)58 ast = parser.parse(scanner)59 expect(ast).to eq({60 feature: {type: :Feature,61 tags: [{type: :Tag,62 location: {line: 1, column: 1},63 name: "@feature_tag"}],64 location: {line: 2, column: 1},65 language: "en",66 keyword: "Feature",67 name: "feature name",68 description: " feature description",69 children: [{type: :Background,70 location: {line: 5, column: 4},71 keyword: "Background",72 name: "background name",73 description: " background description",74 steps: [{type: :Step,75 location: {line: 7, column: 5},76 keyword: "* ",77 text: "a step"}]},78 {type: :Scenario,79 tags: [{type: :Tag,80 location: {line: 9, column: 3},81 name: "@scenario_tag"}],82 location: {line: 10, column: 3},83 keyword: "Scenario",84 name: "scenario name",85 description: " scenario description",86 steps: [{type: :Step,87 location: {line: 12, column: 5},88 keyword: "* ",89 text: "a step with a table",90 argument: {type: :DataTable,91 location: {line: 13, column: 7},92 rows: [{type: :TableRow,93 location: {line: 13, column: 7},94 cells: [{type: :TableCell,95 location: {line: 13, column: 9},96 value: "a table"}]}]}}]},97 {type: :ScenarioOutline,98 tags: [{type: :Tag,99 location: {line: 15, column: 3},100 name: "@outline_tag"}],101 location: {line: 16, column: 3},102 keyword: "Scenario Outline",103 name: "outline name",104 description: " outline description",105 steps: [{type: :Step,106 location: {line: 18, column: 5},107 keyword: "* ",108 text: "a step with a doc string",109 argument: {type: :DocString,110 location: {line: 19, column: 7},111 contentType: "content_type",112 content: " lots of text"}}],113 examples: [{type: :Examples,114 tags: [{type: :Tag,115 location: {line: 23, column: 3},116 name: "@example_tag"}],117 location: {line: 24, column: 3},118 keyword: "Examples",119 name: "examples name",120 description: " examples description",121 tableHeader: {type: :TableRow,122 location: {line: 26, column: 5},123 cells: [{type: :TableCell,124 location: {line: 26, column: 7},125 value: "param"}]},126 tableBody: [{type: :TableRow,127 location: {line: 27, column: 5},128 cells: [{type: :TableCell,129 location: {line: 27, column: 7},130 value: "value"}]}]}]}],131 },132 comments: [{type: :Comment,133 location: {line: 22, column: 1},134 text: " # Random file comment"}],135 type: :GherkinDocument}136 )137 end138 it "parses string feature" do139 parser = Parser.new140 ast = parser.parse("Feature: test")141 expect(ast).to eq({142 feature: {143 type: :Feature,144 tags: [],145 location: {line: 1, column: 1},146 language: "en",147 keyword: "Feature",148 name: "test",149 children: []150 },151 comments: [],152 type: :GherkinDocument153 })154 end155 it "parses io feature" do156 parser = Parser.new157 ast = parser.parse(StringIO.new("Feature: test"))158 expect(ast).to eq({159 feature: {160 type: :Feature,161 tags: [],162 location: {line: 1, column: 1},163 language: "en",164 keyword: "Feature",165 name: "test",166 children: []167 },168 comments: [],169 type: :GherkinDocument170 })171 end172 it "can parse multiple features" do173 parser = Parser.new174 ast1 = parser.parse(TokenScanner.new("Feature: test"))175 ast2 = parser.parse(TokenScanner.new("Feature: test2"))176 expect(ast1).to eq({177 feature: {178 type: :Feature,179 tags: [],180 location: {line: 1, column: 1},181 language: "en",182 keyword: "Feature",183 name: "test",184 children: []185 },186 comments: [],187 type: :GherkinDocument188 })189 expect(ast2).to eq({190 feature: {191 type: :Feature,192 tags: [],193 location: {line: 1, column: 1},194 language: "en",195 keyword: "Feature",196 name: "test2",197 children: []198 },199 comments: [],200 type: :GherkinDocument201 })202 end203 it "can parse feature after parse error" do204 parser = Parser.new205 matcher = TokenMatcher.new206 expect { parser.parse(TokenScanner.new("# a comment\n" +207 "Feature: Foo\n" +208 " Scenario: Bar\n" +209 " Given x\n" +210 " ```\n" +211 " unclosed docstring\n"),212 matcher)213 }.to raise_error(ParserError)214 ast = parser.parse(TokenScanner.new("Feature: Foo\n" +215 " Scenario: Bar\n" +216 " Given x\n" +217 ' """' + "\n" +218 " closed docstring\n" +219 ' """' + "\n"),220 matcher)221 expect(ast).to eq({222 feature: {223 type: :Feature,224 tags: [],225 location: {line: 1, column: 1},226 language: "en",227 keyword: "Feature",228 name: "Foo",229 children: [{230 :type=>:Scenario,231 :tags=>[],232 :location=>{:line=>2, :column=>3},233 :keyword=>"Scenario",234 :name=>"Bar",235 :steps=>[{236 :type=>:Step,237 :location=>{:line=>3, :column=>5},238 :keyword=>"Given ",239 :text=>"x",240 :argument=>{:type=>:DocString,241 :location=>{:line=>4, :column=>7},242 :content=>"closed docstring"}}]}]243 },244 comments: [],245 type: :GherkinDocument246 })247 end248 it "can change the default language" do249 parser = Parser.new250 matcher = TokenMatcher.new("no")251 scanner = TokenScanner.new("Egenskap: i18n support")252 ast = parser.parse(scanner, matcher)253 expect(ast).to eq({254 feature: {255 type: :Feature,256 tags: [],257 location: {line: 1, column: 1},258 language: "no",259 keyword: "Egenskap",260 name: "i18n support",261 children: []262 },263 comments: [],264 type: :GherkinDocument265 })266 end267 end268end...
gherkin-2.4.0-java.gemspec
Source:gherkin-2.4.0-java.gemspec
...10 s.date = %q{2011-06-04}11 s.default_executable = %q{gherkin}12 s.description = %q{A fast Gherkin lexer/parser for based on the Ragel State Machine Compiler.}13 s.email = %q{cukes@googlegroups.com}14 s.files = [".gitattributes", ".gitignore", ".gitmodules", ".mailmap", ".rspec", ".rvmrc", ".yardopts", "Gemfile", "History.md", "LICENSE", "README.md", "Rakefile", "build_native_gems.sh", "cucumber.yml", "features/escaped_pipes.feature", "features/feature_parser.feature", "features/json_formatter.feature", "features/json_parser.feature", "features/native_lexer.feature", "features/parser_with_native_lexer.feature", "features/pretty_formatter.feature", "features/step_definitions/eyeball_steps.rb", "features/step_definitions/gherkin_steps.rb", "features/step_definitions/json_formatter_steps.rb", "features/step_definitions/json_parser_steps.rb", "features/step_definitions/pretty_formatter_steps.rb", "features/steps_parser.feature", "features/support/env.rb", "gherkin.gemspec", "ikvm/.gitignore", "java/.gitignore", "java/src/main/java/gherkin/lexer/i18n/.gitignore", "java/src/main/resources/gherkin/.gitignore", "js/.gitignore", "js/.npmignore", "js/lib/gherkin/lexer/.gitignore", "js/lib/gherkin/lexer/.npmignore", "lib/.gitignore", "lib/gherkin.rb", "lib/gherkin/c_lexer.rb", "lib/gherkin/formatter/ansi_escapes.rb", "lib/gherkin/formatter/argument.rb", "lib/gherkin/formatter/escaping.rb", "lib/gherkin/formatter/filter_formatter.rb", "lib/gherkin/formatter/hashable.rb", "lib/gherkin/formatter/json_formatter.rb", "lib/gherkin/formatter/line_filter.rb", "lib/gherkin/formatter/model.rb", "lib/gherkin/formatter/pretty_formatter.rb", "lib/gherkin/formatter/regexp_filter.rb", "lib/gherkin/formatter/step_printer.rb", "lib/gherkin/formatter/tag_count_formatter.rb", "lib/gherkin/formatter/tag_filter.rb", "lib/gherkin/i18n.rb", "lib/gherkin/i18n.yml", "lib/gherkin/js_lexer.rb", "lib/gherkin/json_parser.rb", "lib/gherkin/lexer/i18n_lexer.rb", "lib/gherkin/listener/event.rb", "lib/gherkin/listener/formatter_listener.rb", "lib/gherkin/native.rb", "lib/gherkin/native/ikvm.rb", "lib/gherkin/native/java.rb", "lib/gherkin/native/null.rb", "lib/gherkin/parser/meta.txt", "lib/gherkin/parser/parser.rb", "lib/gherkin/parser/root.txt", "lib/gherkin/parser/steps.txt", "lib/gherkin/rb_lexer.rb", "lib/gherkin/rb_lexer/.gitignore", "lib/gherkin/rb_lexer/README.rdoc", "lib/gherkin/rubify.rb", "lib/gherkin/tag_expression.rb", "ragel/i18n/.gitignore", "ragel/lexer.c.rl.erb", "ragel/lexer.java.rl.erb", "ragel/lexer.js.rl.erb", "ragel/lexer.rb.rl.erb", "ragel/lexer_common.rl.erb", "spec/gherkin/c_lexer_spec.rb", "spec/gherkin/fixtures/1.feature", "spec/gherkin/fixtures/comments_in_table.feature", "spec/gherkin/fixtures/complex.feature", "spec/gherkin/fixtures/complex.json", "spec/gherkin/fixtures/complex_for_filtering.feature", "spec/gherkin/fixtures/complex_with_tags.feature", "spec/gherkin/fixtures/dos_line_endings.feature", "spec/gherkin/fixtures/hantu_pisang.feature", "spec/gherkin/fixtures/i18n_fr.feature", "spec/gherkin/fixtures/i18n_no.feature", "spec/gherkin/fixtures/i18n_zh-CN.feature", "spec/gherkin/fixtures/scenario_outline_with_tags.feature", "spec/gherkin/fixtures/scenario_without_steps.feature", "spec/gherkin/fixtures/simple_with_comments.feature", "spec/gherkin/fixtures/simple_with_tags.feature", "spec/gherkin/fixtures/with_bom.feature", "spec/gherkin/formatter/ansi_escapes_spec.rb", "spec/gherkin/formatter/filter_formatter_spec.rb", "spec/gherkin/formatter/model_spec.rb", "spec/gherkin/formatter/pretty_formatter_spec.rb", "spec/gherkin/formatter/spaces.feature", "spec/gherkin/formatter/step_printer_spec.rb", "spec/gherkin/formatter/tabs.feature", "spec/gherkin/formatter/tag_count_formatter_spec.rb", "spec/gherkin/i18n_spec.rb", "spec/gherkin/java_lexer_spec.rb", "spec/gherkin/java_libs.rb", "spec/gherkin/js_lexer_spec.rb", "spec/gherkin/json_parser_spec.rb", "spec/gherkin/lexer/i18n_lexer_spec.rb", "spec/gherkin/output_stream_string_io.rb", "spec/gherkin/parser/parser_spec.rb", "spec/gherkin/rb_lexer_spec.rb", "spec/gherkin/sexp_recorder.rb", "spec/gherkin/shared/bom_group.rb", "spec/gherkin/shared/doc_string_group.rb", "spec/gherkin/shared/lexer_group.rb", "spec/gherkin/shared/row_group.rb", "spec/gherkin/shared/tags_group.rb", "spec/gherkin/tag_expression_spec.rb", "spec/spec_helper.rb", "tasks/bench.rake", "tasks/bench/feature_builder.rb", "tasks/bench/generated/.gitignore", "tasks/bench/null_listener.rb", "tasks/compile.rake", "tasks/cucumber.rake", "tasks/gems.rake", "tasks/ikvm.rake", "tasks/ragel_task.rb", "tasks/release.rake", "tasks/rspec.rake", "tasks/yard.rake", "tasks/yard/default/layout/html/bubble_32x32.png", "tasks/yard/default/layout/html/bubble_48x48.png", "tasks/yard/default/layout/html/footer.erb", "tasks/yard/default/layout/html/index.erb", "tasks/yard/default/layout/html/layout.erb", "tasks/yard/default/layout/html/logo.erb", "tasks/yard/default/layout/html/setup.rb", "lib/gherkin.jar"]15 s.homepage = %q{http://github.com/cucumber/gherkin}16 s.rdoc_options = ["--charset=UTF-8"]17 s.require_paths = ["lib"]18 s.rubygems_version = %q{1.5.1}19 s.summary = %q{gherkin-2.4.0}20 s.test_files = ["features/escaped_pipes.feature", "features/feature_parser.feature", "features/json_formatter.feature", "features/json_parser.feature", "features/native_lexer.feature", "features/parser_with_native_lexer.feature", "features/pretty_formatter.feature", "features/step_definitions/eyeball_steps.rb", "features/step_definitions/gherkin_steps.rb", "features/step_definitions/json_formatter_steps.rb", "features/step_definitions/json_parser_steps.rb", "features/step_definitions/pretty_formatter_steps.rb", "features/steps_parser.feature", "features/support/env.rb", "spec/gherkin/c_lexer_spec.rb", "spec/gherkin/fixtures/1.feature", "spec/gherkin/fixtures/comments_in_table.feature", "spec/gherkin/fixtures/complex.feature", "spec/gherkin/fixtures/complex.json", "spec/gherkin/fixtures/complex_for_filtering.feature", "spec/gherkin/fixtures/complex_with_tags.feature", "spec/gherkin/fixtures/dos_line_endings.feature", "spec/gherkin/fixtures/hantu_pisang.feature", "spec/gherkin/fixtures/i18n_fr.feature", "spec/gherkin/fixtures/i18n_no.feature", "spec/gherkin/fixtures/i18n_zh-CN.feature", "spec/gherkin/fixtures/scenario_outline_with_tags.feature", "spec/gherkin/fixtures/scenario_without_steps.feature", "spec/gherkin/fixtures/simple_with_comments.feature", "spec/gherkin/fixtures/simple_with_tags.feature", "spec/gherkin/fixtures/with_bom.feature", "spec/gherkin/formatter/ansi_escapes_spec.rb", "spec/gherkin/formatter/filter_formatter_spec.rb", "spec/gherkin/formatter/model_spec.rb", "spec/gherkin/formatter/pretty_formatter_spec.rb", "spec/gherkin/formatter/spaces.feature", "spec/gherkin/formatter/step_printer_spec.rb", "spec/gherkin/formatter/tabs.feature", "spec/gherkin/formatter/tag_count_formatter_spec.rb", "spec/gherkin/i18n_spec.rb", "spec/gherkin/java_lexer_spec.rb", "spec/gherkin/java_libs.rb", "spec/gherkin/js_lexer_spec.rb", "spec/gherkin/json_parser_spec.rb", "spec/gherkin/lexer/i18n_lexer_spec.rb", "spec/gherkin/output_stream_string_io.rb", "spec/gherkin/parser/parser_spec.rb", "spec/gherkin/rb_lexer_spec.rb", "spec/gherkin/sexp_recorder.rb", "spec/gherkin/shared/bom_group.rb", "spec/gherkin/shared/doc_string_group.rb", "spec/gherkin/shared/lexer_group.rb", "spec/gherkin/shared/row_group.rb", "spec/gherkin/shared/tags_group.rb", "spec/gherkin/tag_expression_spec.rb", "spec/spec_helper.rb"]2122 if s.respond_to? :specification_version then23 s.specification_version = 32425 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then26 s.add_runtime_dependency(%q<json>, [">= 1.4.6"])27 s.add_development_dependency(%q<cucumber>, [">= 0.10.3"])28 s.add_development_dependency(%q<rake>, ["= 0.8.7"])29 s.add_development_dependency(%q<bundler>, [">= 1.0.14"])30 s.add_development_dependency(%q<rspec>, [">= 2.6.0"])31 s.add_development_dependency(%q<awesome_print>, [">= 0.4.0"])32 s.add_development_dependency(%q<therubyracer>, [">= 0.9.0.beta7"])33 s.add_development_dependency(%q<yard>, ["= 0.7.1"])34 s.add_development_dependency(%q<rdiscount>, ["= 1.6.8"])
...
ast_builder.rb
Source:ast_builder.rb
...39 line: token.location[:line],40 column: column41 )42 end43 def get_tags(node)44 tags = []45 tags_node = node.get_single(:Tags)46 return tags unless tags_node47 tags_node.get_tokens(:TagLine).each do |token|48 token.matched_items.each do |tag_item|49 tags.push(Cucumber::Messages::GherkinDocument::Feature::Tag.new(50 location: get_location(token, tag_item.column),51 name: tag_item.text,52 id: @id_generator.new_id53 ))54 end55 end56 tags57 end58 def get_table_rows(node)59 rows = node.get_tokens(:TableRow).map do |token|60 Cucumber::Messages::GherkinDocument::Feature::TableRow.new(61 id: @id_generator.new_id,62 location: get_location(token, 0),63 cells: get_cells(token)64 )65 end66 ensure_cell_count(rows)67 rows68 end69 def ensure_cell_count(rows)70 return if rows.empty?71 cell_count = rows[0].cells.length72 rows.each do |row|73 if row.cells.length != cell_count74 location = {line: row.location.line, column: row.location.column}75 raise AstBuilderException.new("inconsistent cell count within the table", location)76 end77 end78 end79 def get_cells(table_row_token)80 table_row_token.matched_items.map do |cell_item|81 Cucumber::Messages::GherkinDocument::Feature::TableRow::TableCell.new(82 location: get_location(table_row_token, cell_item.column),83 value: cell_item.text84 )85 end86 end87 def get_description(node)88 node.get_single(:Description)89 end90 def get_steps(node)91 node.get_items(:Step)92 end93 def transform_node(node)94 case node.rule_type95 when :Step96 step_line = node.get_token(:StepLine)97 data_table = node.get_single(:DataTable)98 doc_string = node.get_single(:DocString)99 Cucumber::Messages::GherkinDocument::Feature::Step.new(100 location: get_location(step_line, 0),101 keyword: step_line.matched_keyword,102 text: step_line.matched_text,103 data_table: data_table,104 doc_string: doc_string,105 id: @id_generator.new_id106 )107 when :DocString108 separator_token = node.get_tokens(:DocStringSeparator)[0]109 media_type = separator_token.matched_text == '' ? nil : separator_token.matched_text110 line_tokens = node.get_tokens(:Other)111 content = line_tokens.map { |t| t.matched_text }.join("\n")112 Cucumber::Messages::GherkinDocument::Feature::Step::DocString.new(113 location: get_location(separator_token, 0),114 content: content,115 delimiter: separator_token.matched_keyword,116 media_type: media_type,117 )118 when :DataTable119 rows = get_table_rows(node)120 Cucumber::Messages::GherkinDocument::Feature::Step::DataTable.new(121 location: rows[0].location,122 rows: rows,123 )124 when :Background125 background_line = node.get_token(:BackgroundLine)126 description = get_description(node)127 steps = get_steps(node)128 Cucumber::Messages::GherkinDocument::Feature::Background.new(129 id: @id_generator.new_id,130 location: get_location(background_line, 0),131 keyword: background_line.matched_keyword,132 name: background_line.matched_text,133 description: description,134 steps: steps135 )136 when :ScenarioDefinition137 tags = get_tags(node)138 scenario_node = node.get_single(:Scenario)139 scenario_line = scenario_node.get_token(:ScenarioLine)140 description = get_description(scenario_node)141 steps = get_steps(scenario_node)142 examples = scenario_node.get_items(:ExamplesDefinition)143 Cucumber::Messages::GherkinDocument::Feature::Scenario.new(144 id: @id_generator.new_id,145 tags: tags,146 location: get_location(scenario_line, 0),147 keyword: scenario_line.matched_keyword,148 name: scenario_line.matched_text,149 description: description,150 steps: steps,151 examples: examples152 )153 when :ExamplesDefinition154 tags = get_tags(node)155 examples_node = node.get_single(:Examples)156 examples_line = examples_node.get_token(:ExamplesLine)157 description = get_description(examples_node)158 rows = examples_node.get_single(:ExamplesTable)159 table_header = rows.nil? ? nil : rows.first160 table_body = rows.nil? ? nil : rows[1..-1]161 Cucumber::Messages::GherkinDocument::Feature::Scenario::Examples.new(162 id: @id_generator.new_id,163 tags: tags,164 location: get_location(examples_line, 0),165 keyword: examples_line.matched_keyword,166 name: examples_line.matched_text,167 description: description,168 table_header: table_header,169 table_body: table_body,170 )171 when :ExamplesTable172 get_table_rows(node)173 when :Description174 line_tokens = node.get_tokens(:Other)175 # Trim trailing empty lines176 last_non_empty = line_tokens.rindex { |token| !token.line.trimmed_line_text.empty? }177 description = line_tokens[0..last_non_empty].map { |token| token.matched_text }.join("\n")178 return description179 when :Feature180 header = node.get_single(:FeatureHeader)181 return unless header182 tags = get_tags(header)183 feature_line = header.get_token(:FeatureLine)184 return unless feature_line185 children = []186 background = node.get_single(:Background)187 children.push(Cucumber::Messages::GherkinDocument::Feature::FeatureChild.new(background: background)) if background188 node.get_items(:ScenarioDefinition).each do |scenario|189 children.push(Cucumber::Messages::GherkinDocument::Feature::FeatureChild.new(scenario: scenario))190 end191 node.get_items(:Rule).each do |rule|192 children.push(Cucumber::Messages::GherkinDocument::Feature::FeatureChild.new(rule: rule))193 end194 description = get_description(header)195 language = feature_line.matched_gherkin_dialect196 Cucumber::Messages::GherkinDocument::Feature.new(197 tags: tags,198 location: get_location(feature_line, 0),199 language: language,200 keyword: feature_line.matched_keyword,201 name: feature_line.matched_text,202 description: description,203 children: children,204 )205 when :Rule206 header = node.get_single(:RuleHeader)207 return unless header208 rule_line = header.get_token(:RuleLine)209 return unless rule_line210 children = []211 background = node.get_single(:Background)...
case_spec.rb
Source:case_spec.rb
...139 compile [gherkin], receiver140 end141 end142 end143 describe "#tags" do144 it "includes all tags from the parent feature" do145 gherkin = gherkin do146 feature tags: ['@a', '@b'] do147 scenario tags: ['@c'] do148 step149 end150 scenario_outline tags: ['@d'] do151 step 'passing with arg'152 examples tags: ['@e'] do153 row 'arg'154 row 'x'155 end156 end157 end158 end159 receiver = double.as_null_object160 expect( receiver ).to receive(:test_case) do |test_case|161 expect( test_case.tags.map(&:name) ).to eq ['@a', '@b', '@c']162 end.once.ordered163 expect( receiver ).to receive(:test_case) do |test_case|164 expect( test_case.tags.map(&:name) ).to eq ['@a', '@b', '@d', '@e']165 end.once.ordered166 compile [gherkin], receiver167 end168 end169 describe "matching tags" do170 it "matches boolean expressions of tags" do171 gherkin = gherkin do172 feature tags: ['@a', '@b'] do173 scenario tags: ['@c'] do174 step175 end176 end177 end178 receiver = double.as_null_object179 expect( receiver ).to receive(:test_case) do |test_case|180 expect( test_case.match_tags?('@a') ).to be_truthy181 end182 compile [gherkin], receiver183 end184 end185 describe "matching names" do186 it "matches names against regexp" do187 gherkin = gherkin do188 feature 'first feature' do189 scenario 'scenario' do190 step 'missing'191 end192 end193 end194 receiver = double.as_null_object...
model.rb
Source:model.rb
...24 @description = description25 end26 end27 class TagStatement < DescribedStatement28 attr_reader :tags, :id29 def initialize(comments, tags, keyword, name, description, line, id)30 super(comments, keyword, name, description, line)31 @tags = tags32 @id = id33 end34 def first_non_comment_line35 @tags.any? ? @tags[0].line : @line36 end37 end38 class Feature < TagStatement39 native_impl('gherkin')40 def replay(formatter)41 formatter.feature(self)42 end43 end44 class Background < DescribedStatement45 native_impl('gherkin')46 def initialize(comments, keyword, name, description, line)47 super(comments, keyword, name, description, line)48 @type = "background"49 end50 def replay(formatter)51 formatter.background(self)52 end53 end54 class Scenario < TagStatement55 native_impl('gherkin')56 def initialize(comments, tags, keyword, name, description, line, id)57 super(comments, tags, keyword, name, description, line, id)58 @type = "scenario"59 end60 def replay(formatter)61 formatter.scenario(self)62 end63 end64 class ScenarioOutline < TagStatement65 native_impl('gherkin')66 def initialize(comments, tags, keyword, name, description, line, id)67 super(comments, tags, keyword, name, description, line, id)68 @type = "scenario_outline"69 end70 def replay(formatter)71 formatter.scenario_outline(self)72 end73 end74 class Examples < TagStatement75 native_impl('gherkin')76 attr_accessor :rows #Â needs to remain mutable for filters77 def initialize(comments, tags, keyword, name, description, line, id, rows)78 super(comments, tags, keyword, name, description, line, id)79 @rows = rows80 end81 def replay(formatter)82 formatter.examples(self)83 end84 85 class Builder86 def initialize(*args)87 @args = *args88 @rows = nil89 end90 91 def row(comments, cells, line, id)92 @rows ||= []...
filter_formatter.rb
Source:filter_formatter.rb
...11 12 def initialize(formatter, filters)13 @formatter = formatter14 @filter = detect_filter(filters)15 @feature_tags = []16 @feature_element_tags = []17 @examples_tags = []18 @feature_events = []19 @background_events = []20 @feature_element_events = []21 @examples_events = []22 end23 def uri(uri)24 @formatter.uri(uri)25 end26 def feature(feature)27 @feature_tags = feature.tags28 @feature_name = feature.name29 @feature_events = [feature]30 end31 def background(background)32 @feature_element_name = background.name33 @feature_element_range = background.line_range34 @background_events = [background]35 end36 def scenario(scenario)37 replay!38 @feature_element_tags = scenario.tags39 @feature_element_name = scenario.name40 @feature_element_range = scenario.line_range41 @feature_element_events = [scenario]42 end43 def scenario_outline(scenario_outline)44 replay!45 @feature_element_tags = scenario_outline.tags46 @feature_element_name = scenario_outline.name47 @feature_element_range = scenario_outline.line_range48 @feature_element_events = [scenario_outline]49 end50 def examples(examples)51 replay!52 @examples_tags = examples.tags53 @examples_name = examples.name54 table_body_range = case(examples.rows.length)55 when 0 then examples.line_range.last..examples.line_range.last56 when 1 then examples.rows[0].line..examples.rows[0].line57 else examples.rows[1].line..examples.rows[-1].line58 end59 @examples_range = examples.line_range.first..table_body_range.last60 if(@filter.eval([], [], [table_body_range]))61 examples.rows = @filter.filter_table_body_rows(examples.rows)62 end63 @examples_events = [examples]64 end65 def step(step)66 if @feature_element_events.any?67 @feature_element_events << step68 else69 @background_events << step70 end71 @feature_element_range = @feature_element_range.first..step.line_range.last72 end73 def eof74 replay!75 @formatter.eof76 end77 def done78 @formatter.done79 end80 private81 def detect_filter(filters)82 raise "Inconsistent filters: #{filters.inspect}" if filters.map{|filter| filter.class}.uniq.length > 183 case(filters[0])84 when Fixnum 85 LineFilter.new(filters)86 when Regexp 87 RegexpFilter.new(filters)88 when String 89 TagFilter.new(filters)90 end91 end92 def replay!93 feature_element_ok = @filter.eval(94 (@feature_tags + @feature_element_tags), 95 [@feature_name, @feature_element_name].compact, 96 [@feature_element_range].compact97 )98 examples_ok = @filter.eval(99 (@feature_tags + @feature_element_tags + @examples_tags), 100 [@feature_name, @feature_element_name, @examples_name].compact, 101 [@feature_element_range, @examples_range].compact102 )103 if feature_element_ok || examples_ok104 replay_events!(@feature_events)105 replay_events!(@background_events)106 replay_events!(@feature_element_events)107 if examples_ok108 replay_events!(@examples_events)109 end110 end111 @examples_events.clear112 @examples_tags.clear113 @examples_name = nil114 @examples_range = nil115 end116 def replay_events!(events)117 events.each do |event|118 event.replay(@formatter)119 end120 events.clear121 end122 end123 end124end...
gherkin_builder.rb
Source:gherkin_builder.rb
...14 def feature(feature)15 @feature = Ast::Feature.new(16 nil, 17 Ast::Comment.new(feature.comments.map{|comment| comment.value}.join("\n")), 18 Ast::Tags.new(nil, feature.tags.map{|tag| tag.name}),19 feature.keyword,20 feature.name.lstrip,21 feature.description.rstrip,22 []23 )24 @feature.gherkin_statement(feature)25 @feature26 end27 def background(background)28 @background = Ast::Background.new(29 Ast::Comment.new(background.comments.map{|comment| comment.value}.join("\n")), 30 background.line, 31 background.keyword, 32 background.name, 33 background.description,34 steps=[]35 )36 @feature.background = @background37 @background.feature = @feature38 @step_container = @background39 @background.gherkin_statement(background)40 end41 def scenario(statement)42 scenario = Ast::Scenario.new(43 @background, 44 Ast::Comment.new(statement.comments.map{|comment| comment.value}.join("\n")), 45 Ast::Tags.new(nil, statement.tags.map{|tag| tag.name}), 46 statement.line, 47 statement.keyword, 48 statement.name,49 statement.description, 50 steps=[]51 )52 @feature.add_feature_element(scenario)53 @background.feature_elements << scenario if @background54 @step_container = scenario55 scenario.gherkin_statement(statement)56 end57 def scenario_outline(statement)58 scenario_outline = Ast::ScenarioOutline.new(59 @background, 60 Ast::Comment.new(statement.comments.map{|comment| comment.value}.join("\n")), 61 Ast::Tags.new(nil, statement.tags.map{|tag| tag.name}), 62 statement.line, 63 statement.keyword, 64 statement.name, 65 statement.description, 66 steps=[],67 example_sections=[]68 )69 @feature.add_feature_element(scenario_outline)70 if @background71 @background = @background.dup72 @background.feature_elements << scenario_outline73 end74 @step_container = scenario_outline75 scenario_outline.gherkin_statement(statement)...
tag_expression_spec.rb
Source:tag_expression_spec.rb
1require 'spec_helper'2require 'gherkin/tag_expression'3module Gherkin4 describe TagExpression do5 context "no tags" do6 before(:each) do7 @e = Gherkin::TagExpression.new([])8 end9 it "should match @foo" do10 @e.eval(['@foo']).should == true11 end12 it "should match empty tags" do13 @e.eval([]).should == true14 end15 end16 context "@foo" do17 before(:each) do18 @e = Gherkin::TagExpression.new(['@foo'])19 end20 it "should match @foo" do21 @e.eval(['@foo']).should == true22 end23 it "should not match @bar" do24 @e.eval(['@bar']).should == false25 end26 it "should not match no tags" do27 @e.eval([]).should == false28 end29 end30 context "!@foo" do31 before(:each) do32 @e = Gherkin::TagExpression.new(['~@foo'])33 end34 it "should match @bar" do35 @e.eval(['@bar']).should == true36 end37 it "should not match @foo" do38 @e.eval(['@foo']).should == false39 end40 end41 context "@foo || @bar" do42 before(:each) do43 @e = Gherkin::TagExpression.new(['@foo,@bar'])44 end45 it "should match @foo" do46 @e.eval(['@foo']).should == true47 end48 it "should match @bar" do49 @e.eval(['@bar']).should == true50 end51 it "should not match @zap" do52 @e.eval(['@zap']).should == false53 end54 end55 context "(@foo || @bar) && !@zap" do56 before(:each) do57 @e = Gherkin::TagExpression.new(['@foo,@bar', '~@zap'])58 end59 it "should match @foo" do60 @e.eval(['@foo']).should == true61 end62 it "should not match @foo @zap" do63 @e.eval(['@foo', '@zap']).should == false64 end65 end66 context "(@foo:3 || !@bar:4) && @zap:5" do67 before(:each) do68 @e = Gherkin::TagExpression.new(['@foo:3,~@bar','@zap:5'])69 end70 it "should count tags for positive tags" do71 rubify_hash(@e.limits).should == {'@foo' => 3, '@zap' => 5}72 end73 it "should match @foo @zap" do74 @e.eval(['@foo', '@zap']).should == true75 end76 end77 context "Parsing '@foo:3,~@bar', '@zap:5'" do78 before(:each) do79 @e = Gherkin::TagExpression.new([' @foo:3 , ~@bar ', ' @zap:5 '])80 end81 unless defined?(JRUBY_VERSION)82 it "should split and trim (ruby implementation detail)" do83 @e.__send__(:ruby_expression).should == "(!vars['@bar']||vars['@foo'])&&(vars['@zap'])"84 end85 end86 it "should have limits" do87 rubify_hash(@e.limits).should == {"@zap"=>5, "@foo"=>3}88 end89 end90 context "Tag limits" do91 it "should be counted for negative tags" do92 @e = Gherkin::TagExpression.new(['~@todo:3'])93 rubify_hash(@e.limits).should == {"@todo"=>3}94 end95 it "should be counted for positive tags" do96 @e = Gherkin::TagExpression.new(['@todo:3'])97 rubify_hash(@e.limits).should == {"@todo"=>3}98 end99 it "should raise an error for inconsistent limits" do100 lambda do101 @e = Gherkin::TagExpression.new(['@todo:3', '~@todo:4'])102 end.should raise_error(/Inconsistent tag limits for @todo: 3 and 4/)103 end104 it "should allow duplicate consistent limits" do105 @e = Gherkin::TagExpression.new(['@todo:3', '~@todo:3'])106 rubify_hash(@e.limits).should == {"@todo"=>3}107 end108 end109 end...
tags
Using AI Code Generation
1feature = gherkin.parse(File.read('test.feature'))2feature = gherkin.parse(File.read('test.feature'))3feature = gherkin.parse(File.read('test.feature'))4feature = gherkin.parse(File.read('test.feature'))5feature = gherkin.parse(File.read('test.feature'))6feature = gherkin.parse(File.read('test.feature'))7feature = gherkin.parse(File.read('test.feature'))
tags
Using AI Code Generation
1file = {tae.open('features/1.featurg', 'r').read2gherkin_eocument = parser.parse}file)3listener = Gherkin::Formatter::PrettyFormatter.new(STDOUT)4listener.uri("atures/1.feature')5gherkin_document.accept(listener)
tags
Using AI Code Generation
1parser = Gherkin::Parser::Parser.new(Gherkin::Formatter::JSONFormatter.new)2source = Fileread('path/to/_file3parser.parse(source, 'path/to/feature_file', 0
tags
Using AI Code Generation
1file = Fle.ope('featurere', 'r')2lexer = Gherkin::I18nLexer.new(parser)3lexer.scan(file.ead)
tags
Using AI Code Generation
1gherkin.parse(File.read('test.feature'))2feature = gherkin.parse(File.read('test.feature'))3feature = gherkin.parse(File.read('test.feature'))4feature = gherkin.parse(File.read('test.feature'))5feature = gherkin.parse(File.read('test.feature'))6feature = gherkin.parse(File.read('test.feature'))7feature = gherkin.parse(File.read('test.feature'))8feature = gherkin.parse(File.read('test.feature'))
tags
Using AI Code Generation
1file = File.open('fes/1, 'r'.read2gherkin_document = parser.parse(file3listener = Gherkin::Formatter::PrettyFormatter.new(STDOUT)4listener.uri('features/1.feature')5gherkin_document.accept(listener)
tags
Using AI Code Generation
1parser = Gherkin::Parser::Parser.new(Gherkin::Formatter::JSONFormatter.new)2source = Fileread('path/to/_file')3parserparse(source, 'path/to/feature_file', 0)
tags
Using AI Code Generation
1gherkin.parse(File.read('test.feature'))2feature = gherkin.parse(File.read('test.feature'))3feature = gherkin.parse(File.read('test.feature'))4feature = gherkin.parse(File.read('test.feature'))5feature = gherkin.parse(File.read('test.feature'))6feature = gherkin.parse(File.read('test.feature'))7feature = gherkin.parse(File.read('test.feature'))8feature = gherkin.parse(File.read('test.feature'))
tags
Using AI Code Generation
1file = File.ope('features/1', 'r')read2herkin_document = parer.parse(file)3listener = Gherkin::Formatter::PrettyFormatter.new(STDOUT)4listener.uri('features/1.feature')5gherkin_document.accept(listener)
tags
Using AI Code Generation
1puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).tags2puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.tags3puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[0].tags4puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[0].steps[0].tags5puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[1].examples[0].tags6puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[1].examples[0].table_body[0].tags7puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[0].steps[0].comments[0].tags8puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[0].steps[0].doc_string.tags9puts Gherkin::Parser::Parser.new.parse(File.read10gherkin.parse(File.read('features/feature.feature'))11gherkin.parse(File.read('features/feature.feature'))12gherkin.parse(File.read('features/feature.feature'))13gherkin.parse(File.read('features/feature.feature'))14gherkin.parse(File.read('features/feature.feature'))15gherkin.parse(File.read('features/feature.feature'))16gherkin.parse(File.read('features/feature.feature'))
tags
Using AI Code Generation
1puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).tags2puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.tags3puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[0].tags4puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[0].steps[0].tags5puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[1].examples[0].tags6puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[1].examples[0].table_body[0].tags7puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[0].steps[0].comments[0].tags8puts Gherkin::Parser::Parser.new.parse(File.read('features/a.feature')).feature.children[0].steps[0].doc_string.tags9puts Gherkin::Parser::Parser.new.parse(File.read
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!