You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

spec_helper.rb 2.3 kB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # frozen_string_literal: true
  2. module Cucumber
  3. module Formatter
  4. module SpecHelperDsl
  5. attr_reader :feature_content, :step_defs, :feature_filename
  6. def define_feature(string, feature_file = 'spec.feature')
  7. @feature_content = string
  8. @feature_filename = feature_file
  9. end
  10. def define_steps(&block)
  11. @step_defs = block
  12. end
  13. end
  14. require 'cucumber/core'
  15. module SpecHelper
  16. include Core
  17. def run_defined_feature
  18. define_steps
  19. actual_runtime.visitor = Fanout.new([@formatter])
  20. receiver = Test::Runner.new(event_bus)
  21. event_bus.gherkin_source_read(gherkin_doc.uri, gherkin_doc.body)
  22. compile [gherkin_doc], receiver, filters, event_bus
  23. event_bus.test_run_finished
  24. end
  25. def filters
  26. # TODO: Remove duplication with runtime.rb#filters
  27. [
  28. Filters::ActivateSteps.new(
  29. StepMatchSearch.new(actual_runtime.support_code.registry.method(:step_matches), actual_runtime.configuration),
  30. actual_runtime.configuration
  31. ),
  32. Filters::ApplyAfterStepHooks.new(actual_runtime.support_code),
  33. Filters::ApplyBeforeHooks.new(actual_runtime.support_code),
  34. Filters::ApplyAfterHooks.new(actual_runtime.support_code),
  35. Filters::ApplyAroundHooks.new(actual_runtime.support_code),
  36. Filters::BroadcastTestCaseReadyEvent.new(actual_runtime.configuration),
  37. Filters::BroadcastTestRunStartedEvent.new(actual_runtime.configuration),
  38. Filters::PrepareWorld.new(actual_runtime)
  39. ]
  40. end
  41. require 'cucumber/core/gherkin/document'
  42. def gherkin_doc
  43. Core::Gherkin::Document.new(self.class.feature_filename, gherkin)
  44. end
  45. def gherkin
  46. self.class.feature_content || raise('No feature content defined!')
  47. end
  48. def actual_runtime
  49. @actual_runtime ||= Runtime.new(options)
  50. end
  51. def event_bus
  52. actual_runtime.configuration.event_bus
  53. end
  54. def define_steps
  55. step_defs = self.class.step_defs
  56. return unless step_defs
  57. dsl = Object.new
  58. dsl.extend Glue::Dsl
  59. dsl.instance_exec &step_defs
  60. end
  61. def options
  62. {}
  63. end
  64. end
  65. end
  66. end

No Description

Contributors (1)