class Cucumber::Formatter::AstLookup
Constants
- KeywordSearchNode
- ScenarioOutlineSource
- ScenarioSource
- StepSource
Public Class Methods
new(config)
click to toggle source
# File lib/cucumber/formatter/ast_lookup.rb, line 6 def initialize(config) @gherkin_documents = {} @test_case_lookups = {} @test_step_lookups = {} @step_keyword_lookups = {} config.on_event :gherkin_source_parsed, &method(:on_gherkin_source_parsed) end
Public Instance Methods
gherkin_document(uri)
click to toggle source
# File lib/cucumber/formatter/ast_lookup.rb, line 18 def gherkin_document(uri) @gherkin_documents[uri] end
on_gherkin_source_parsed(event)
click to toggle source
# File lib/cucumber/formatter/ast_lookup.rb, line 14 def on_gherkin_source_parsed(event) @gherkin_documents[event.gherkin_document.uri] = event.gherkin_document end
scenario_source(test_case)
click to toggle source
# File lib/cucumber/formatter/ast_lookup.rb, line 22 def scenario_source(test_case) uri = test_case.location.file @test_case_lookups[uri] ||= TestCaseLookupBuilder.new(gherkin_document(uri)).lookup_hash @test_case_lookups[uri][test_case.location.lines.max] end
snippet_step_keyword(test_step)
click to toggle source
# File lib/cucumber/formatter/ast_lookup.rb, line 34 def snippet_step_keyword(test_step) uri = test_step.location.file document = gherkin_document(uri) dialect = ::Gherkin::Dialect.for(document.feature.language) given_when_then_keywords = [dialect.given_keywords, dialect.when_keywords, dialect.then_keywords].flatten.uniq.reject { |kw| kw == '* ' } keyword_lookup = step_keyword_lookup(uri) keyword = nil node = keyword_lookup[test_step.location.lines.min] while keyword.nil? if given_when_then_keywords.include?(node.keyword) keyword = node.keyword break end break if node.previous_node.nil? node = node.previous_node end keyword = dialect.given_keywords.reject { |kw| kw == '* ' }[0] if keyword.nil? keyword = Cucumber::Gherkin::I18n.code_keyword_for(keyword) keyword end
step_source(test_step)
click to toggle source
# File lib/cucumber/formatter/ast_lookup.rb, line 28 def step_source(test_step) uri = test_step.location.file @test_step_lookups[uri] ||= TestStepLookupBuilder.new(gherkin_document(uri)).lookup_hash @test_step_lookups[uri][test_step.location.lines.min] end
Private Instance Methods
step_keyword_lookup(uri)
click to toggle source
# File lib/cucumber/formatter/ast_lookup.rb, line 63 def step_keyword_lookup(uri) @step_keyword_lookups[uri] ||= KeywordLookupBuilder.new(gherkin_document(uri)).lookup_hash end