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.

env.rb 1.8 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. require 'cucumber/formatter/ansicolor'
  2. CUCUMBER_FEATURES_PATH = 'features/lib'.freeze
  3. Before do |scenario|
  4. @original_cwd = Dir.pwd
  5. # We limit the length to avoid issues on Windows where sometimes the creation
  6. # of the temporary directory fails due to the length of the scenario name.
  7. scenario_name = scenario.name.downcase.gsub(/[^a-z0-9]+/, '-')[0..100]
  8. @tmp_working_directory = File.join('tmp', "scenario-#{scenario_name}-#{SecureRandom.uuid}")
  9. FileUtils.rm_rf(@tmp_working_directory)
  10. FileUtils.mkdir_p(@tmp_working_directory)
  11. Dir.chdir(@tmp_working_directory)
  12. end
  13. After do |scenario|
  14. command_line&.destroy_mocks
  15. Dir.chdir(@original_cwd)
  16. FileUtils.rm_rf(@tmp_working_directory) unless scenario.failed?
  17. end
  18. Around do |_, block|
  19. original_publish_token = ENV.delete('CUCUMBER_PUBLISH_TOKEN')
  20. original_coloring = Cucumber::Term::ANSIColor.coloring?
  21. block.call
  22. Cucumber::Term::ANSIColor.coloring = original_coloring
  23. ENV['CUCUMBER_PUBLISH_TOKEN'] = original_publish_token
  24. end
  25. Around('@force_legacy_loader') do |_, block|
  26. original_loader = Cucumber.use_legacy_autoloader
  27. Cucumber.use_legacy_autoloader = true
  28. block.call
  29. Cucumber.use_legacy_autoloader = original_loader
  30. end
  31. Before('@global_state') do
  32. # Ok, this one is tricky but kinda make sense.
  33. # So, we need to share state between some sub-scenarios (the ones executed by
  34. # CucumberCommand). But we don't want those to leak between the "real" scenarios
  35. # (the ones ran by Cucumber itself).
  36. # This should reset data hopefully (and make clear why we do that)
  37. # rubocop:disable Style/GlobalVars
  38. $global_state = nil
  39. $global_cukes = 0
  40. $scenario_runs = 0
  41. # rubocop:enable Style/GlobalVars
  42. end
  43. After('@disable_fail_fast') do
  44. Cucumber.wants_to_quit = false
  45. end

No Description

Contributors (1)