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.

configuration_spec.rb 5.8 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # frozen_string_literal: true
  2. require 'spec_helper'
  3. module Cucumber
  4. describe Configuration do
  5. describe '.default' do
  6. subject { Configuration.default }
  7. it 'has an autoload_code_paths containing the standard support and step_definitions folders' do
  8. expect(subject.autoload_code_paths).to include('features/support')
  9. expect(subject.autoload_code_paths).to include('features/step_definitions')
  10. end
  11. end
  12. describe 'with custom user options' do
  13. let(:user_options) { { autoload_code_paths: ['foo/bar/baz'] } }
  14. subject { Configuration.new(user_options) }
  15. it 'allows you to override the defaults' do
  16. expect(subject.autoload_code_paths).to eq ['foo/bar/baz']
  17. end
  18. end
  19. context 'selecting files to load' do
  20. def given_the_following_files(*files)
  21. allow(File).to receive(:directory?) { true }
  22. allow(File).to receive(:file?) { true }
  23. allow(Dir).to receive(:[]) { files }
  24. end
  25. it 'requires env.rb files first' do
  26. configuration = Configuration.new
  27. given_the_following_files('/features/support/a_file.rb', '/features/support/env.rb')
  28. expect(configuration.support_to_load).to eq [
  29. '/features/support/env.rb',
  30. '/features/support/a_file.rb'
  31. ]
  32. end
  33. it 'features/support/env.rb is loaded before any other features/**/support/env.rb file' do
  34. configuration = Configuration.new
  35. given_the_following_files(
  36. '/features/foo/support/env.rb',
  37. '/features/foo/support/a_file.rb',
  38. '/features/foo/bar/support/env.rb',
  39. '/features/foo/bar/support/a_file.rb',
  40. '/features/support/a_file.rb',
  41. '/features/support/env.rb'
  42. )
  43. expect(configuration.support_to_load).to eq [
  44. '/features/support/env.rb',
  45. '/features/foo/support/env.rb',
  46. '/features/foo/bar/support/env.rb',
  47. '/features/support/a_file.rb',
  48. '/features/foo/support/a_file.rb',
  49. '/features/foo/bar/support/a_file.rb'
  50. ]
  51. end
  52. it 'requires step defs in vendor/{plugins,gems}/*/cucumber/*.rb' do
  53. given_the_following_files('/vendor/gems/gem_a/cucumber/bar.rb',
  54. '/vendor/plugins/plugin_a/cucumber/foo.rb')
  55. configuration = Configuration.new
  56. expect(configuration.step_defs_to_load).to eq [
  57. '/vendor/gems/gem_a/cucumber/bar.rb',
  58. '/vendor/plugins/plugin_a/cucumber/foo.rb'
  59. ]
  60. end
  61. describe '--exclude' do
  62. it 'excludes a ruby file from requiring when the name matches exactly' do
  63. given_the_following_files('/features/support/a_file.rb', '/features/support/env.rb')
  64. configuration = Configuration.new(excludes: [/a_file.rb/])
  65. expect(configuration.all_files_to_load).to eq [
  66. '/features/support/env.rb'
  67. ]
  68. end
  69. it 'excludes all ruby files that match the provided patterns from requiring' do
  70. given_the_following_files('/features/support/foof.rb', '/features/support/bar.rb',
  71. '/features/support/food.rb', '/features/blah.rb',
  72. '/features/support/fooz.rb')
  73. configuration = Configuration.new(excludes: [/foo[df]/, /blah/])
  74. expect(configuration.all_files_to_load).to eq [
  75. '/features/support/bar.rb',
  76. '/features/support/fooz.rb'
  77. ]
  78. end
  79. end
  80. end
  81. context 'selecting feature files' do
  82. it 'preserves the order of the feature files' do
  83. configuration = Configuration.new(paths: %w[b.feature c.feature a.feature])
  84. expect(configuration.feature_files).to eq ['b.feature', 'c.feature', 'a.feature']
  85. end
  86. it 'searchs for all features in the specified directory' do
  87. allow(File).to receive(:directory?) { true }
  88. allow(Dir).to receive(:[]).with('feature_directory/**/*.feature') { ['cucumber.feature'] }
  89. configuration = Configuration.new(paths: %w[feature_directory/])
  90. expect(configuration.feature_files).to eq ['cucumber.feature']
  91. end
  92. it 'defaults to the features directory when no feature file are provided' do
  93. allow(File).to receive(:directory?) { true }
  94. allow(Dir).to receive(:[]).with('features/**/*.feature') { ['cucumber.feature'] }
  95. configuration = Configuration.new(paths: [])
  96. expect(configuration.feature_files).to eq ['cucumber.feature']
  97. end
  98. it 'gets the feature files from the rerun file' do
  99. allow(File).to receive(:directory?).and_return(false)
  100. allow(File).to receive(:file?).and_return(true)
  101. allow(IO).to receive(:read).and_return(
  102. "cucumber.feature:1:3\ncucumber.feature:5 cucumber.feature:10\n"\
  103. "domain folder/different cuke.feature:134 domain folder/cuke.feature:1\n"\
  104. 'domain folder/different cuke.feature:4:5 bar.feature'
  105. )
  106. configuration = Configuration.new(paths: %w[@rerun.txt])
  107. expect(configuration.feature_files).to eq [
  108. 'cucumber.feature:1:3',
  109. 'cucumber.feature:5',
  110. 'cucumber.feature:10',
  111. 'domain folder/different cuke.feature:134',
  112. 'domain folder/cuke.feature:1',
  113. 'domain folder/different cuke.feature:4:5',
  114. 'bar.feature'
  115. ]
  116. end
  117. end
  118. describe '#with_options' do
  119. it 'returns a copy of the configuration with new options' do
  120. old_out_stream = double('Old out_stream')
  121. new_out_stream = double('New out_stream')
  122. config = Configuration.new(out_stream: old_out_stream).with_options(out_stream: new_out_stream)
  123. expect(config.out_stream).to eq new_out_stream
  124. end
  125. end
  126. end
  127. end

No Description

Contributors (1)