class Cucumber::Glue::RegistryAndMore
TODO: This class has too many responsibilities, split off
def self.cli_snippet_type_options
def self.cli_snippet_type_options registry = CucumberExpressions::ParameterTypeRegistry.new cucumber_expression_generator = CucumberExpressions::CucumberExpressionGenerator.new(registry) Snippet::SNIPPET_TYPES.keys.sort_by(&:to_s).map do |type| Snippet::SNIPPET_TYPES[type].cli_option_string(type, cucumber_expression_generator) end end
def add_hook(phase, hook)
def add_hook(phase, hook) hooks[phase.to_sym] << hook hook end
def after_all
def after_all hooks[:after_all].each do |hook| hook.invoke('AfterAll', []) end end
def available_step_definition(regexp_source, file_colon_line)
def available_step_definition(regexp_source, file_colon_line) available_step_definition_hash[StepDefinitionLight.new(regexp_source, file_colon_line)] = nil end
def available_step_definition_hash
def available_step_definition_hash @available_step_definition_hash ||= {} end
def before_all
def before_all hooks[:before_all].each do |hook| hook.invoke('BeforeAll', []) end end
def begin_scenario(test_case)
def begin_scenario(test_case) @current_world = WorldFactory.new(@world_proc).create_world @current_world.extend(ProtoWorld.for(@runtime, test_case.language)) MultiTest.extend_with_best_assertion_library(@current_world) @current_world.add_modules!(@world_modules || [], @namespaced_world_modules || {}) end
def build_rb_world_factory(world_modules, namespaced_world_modules, proc)
def build_rb_world_factory(world_modules, namespaced_world_modules, proc) if proc raise MultipleWorld.new(@world_proc, proc) if @world_proc @world_proc = proc end @world_modules ||= [] @world_modules += world_modules @namespaced_world_modules ||= Hash.new { |h, k| h[k] = [] } namespaced_world_modules.each do |namespace, world_module| @namespaced_world_modules[namespace] << world_module unless @namespaced_world_modules[namespace].include?(world_module) end end
def clear_hooks
def clear_hooks @hooks = nil end
def create_expression(string_or_regexp)
def create_expression(string_or_regexp) return CucumberExpressions::CucumberExpression.new(string_or_regexp, @parameter_type_registry) if string_or_regexp.is_a?(String) return CucumberExpressions::RegularExpression.new(string_or_regexp, @parameter_type_registry) if string_or_regexp.is_a?(Regexp) raise ArgumentError, 'Expression must be a String or Regexp' end
def define_parameter_type(parameter_type)
def define_parameter_type(parameter_type) @configuration.notify :envelope, parameter_type_envelope(parameter_type) @parameter_type_registry.define_parameter_type(parameter_type) end
def end_scenario
def end_scenario @current_world = nil end
def hooks
def hooks @hooks ||= Hash.new { |h, k| h[k] = [] } end
def hooks_for(phase, scenario) # :nodoc:
def hooks_for(phase, scenario) # :nodoc: hooks[phase.to_sym].select { |hook| scenario.accept_hook?(hook) } end
def initialize(runtime, configuration)
def initialize(runtime, configuration) @runtime = runtime @configuration = configuration @step_definitions = [] Glue::Dsl.rb_language = self @world_proc = @world_modules = nil @parameter_type_registry = CucumberExpressions::ParameterTypeRegistry.new cucumber_expression_generator = CucumberExpressions::CucumberExpressionGenerator.new(@parameter_type_registry) @configuration.register_snippet_generator(Snippet::Generator.new(cucumber_expression_generator)) end
def install_plugin(configuration, registry)
def install_plugin(configuration, registry) hooks[:install_plugin].each do |hook| hook.invoke('InstallPlugin', [configuration, registry]) end end
def invoked_step_definition(regexp_source, file_colon_line)
def invoked_step_definition(regexp_source, file_colon_line) invoked_step_definition_hash[StepDefinitionLight.new(regexp_source, file_colon_line)] = nil end
def invoked_step_definition_hash
def invoked_step_definition_hash @invoked_step_definition_hash ||= {} end
def load_code_file(code_file)
def load_code_file(code_file) return unless File.extname(code_file) == '.rb' # This will cause self.add_step_definition, self.add_hook, and self.define_parameter_type to be called from Glue::Dsl if Cucumber.use_legacy_autoloader load File.expand_path(code_file) else require File.expand_path(code_file) end end
def parameter_type_envelope(parameter_type)
def parameter_type_envelope(parameter_type) # TODO: should this be moved to Cucumber::Expression::ParameterType#to_envelope ?? # Note: that would mean that cucumber-expression would depend on cucumber-messages Cucumber::Messages::Envelope.new( parameter_type: Cucumber::Messages::ParameterType.new( id: @configuration.id_generator.new_id, name: parameter_type.name, regular_expressions: parameter_type.regexps.map(&:to_s), prefer_for_regular_expression_match: parameter_type.prefer_for_regexp_match, use_for_snippets: parameter_type.use_for_snippets, source_reference: Cucumber::Messages::SourceReference.new( uri: parameter_type.transformer.source_location[0], location: Cucumber::Messages::Location.new(line: parameter_type.transformer.source_location[1]) ) ) ) end
def register_rb_hook(phase, tag_expressions, proc, name: nil)
def register_rb_hook(phase, tag_expressions, proc, name: nil) hook = add_hook(phase, Hook.new(@configuration.id_generator.new_id, self, tag_expressions, proc, name: name)) @configuration.notify :envelope, hook.to_envelope hook end
def register_rb_step_definition(string_or_regexp, proc_or_sym, options)
def register_rb_step_definition(string_or_regexp, proc_or_sym, options) step_definition = StepDefinition.new(@configuration.id_generator.new_id, self, string_or_regexp, proc_or_sym, options) @step_definitions << step_definition @configuration.notify :step_definition_registered, step_definition @configuration.notify :envelope, step_definition.to_envelope step_definition rescue Cucumber::CucumberExpressions::UndefinedParameterTypeError => e # TODO: add a way to extract the parameter type directly from the error. type_name = e.message.match(/^Undefined parameter type ['|{](.*)['|}].?$/)[1] @configuration.notify :undefined_parameter_type, type_name, string_or_regexp end
def step_matches(name_to_match)
def step_matches(name_to_match) @step_definitions.each_with_object([]) do |step_definition, result| if (arguments = step_definition.arguments_from(name_to_match)) result << StepMatch.new(step_definition, name_to_match, arguments) end end end
def unmatched_step_definitions
def unmatched_step_definitions available_step_definition_hash.keys - invoked_step_definition_hash.keys end