我想从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
我有两个问题:
用exlude_pattern
配置config.exclude_pattern = 'shared/**/*_spec.rb'
似乎没有从要运行的测试中排除共享文件夹。但是,当我运行rspec --exclude-pattern shared/**/*_spec.rb
时,共享文件夹将从测试套件中排除
如何从代码中的命令行获取传递给rspec的参数?
我能够通过以下配置实现此目标:
# .rspec
--require spec_helper
# spec_helper.rb
RSpec.configure do |config|
config.exclude_pattern = 'shared/**/*_spec.rb'
end