配置rspec以排除文件夹,除非已明确将其指定给rspec运行

问题描述 投票:0回答:1

我想从rspec测试中排除一个文件夹,除非它被明确指定为要运行的命令行参数。例如

RSpec.configure do |config|

  unless rspec_args.any? { |arg| =~ /shared/ } # do not explicitly run shared folder
    config.exclude_pattern = 'shared/**/*_spec.rb' 
  end

end

我正在使用rspec v3.9

我有两个问题:

  1. exlude_pattern配置config.exclude_pattern = 'shared/**/*_spec.rb'似乎没有从要运行的测试中排除共享文件夹。但是,当我运行rspec --exclude-pattern shared/**/*_spec.rb时,共享文件夹将从测试套件中排除

  2. 如何从代码中的命令行获取传递给rspec的参数?

rspec configuration rspec3
1个回答
0
投票

我能够通过以下配置实现此目标:

# .rspec
--require spec_helper

# spec_helper.rb
RSpec.configure do |config|
  config.exclude_pattern = 'shared/**/*_spec.rb' 
end
© www.soinside.com 2019 - 2024. All rights reserved.