【问题标题】:Running multiple specs defined by input file运行由输入文件定义的多个规范
【发布时间】:2013-03-25 17:05:39
【问题描述】:

鉴于我有一个外部文件可以控制正在运行的规范。

control.xls
test_id|description|file_path           |run
1      |Test 1     |./spec/test1_spec.rb|yes
2      |Test 2     |./spec/test2_spec.rb|no

我有一个读取文件并返回文件路径数组的方法。

我想使用该文件数组来运行规范,可以通过 rake 或命令行。

这可能吗?

【问题讨论】:

    标签: ruby rspec rake


    【解决方案1】:

    这是可能的。您可以简单地编写一个自定义 rake 任务,其中包含读取文件的代码。然后,您可以为每个文件 (RSpec::Core::RakeTask) 调用 RSpec Rake 任务,如下所示(对于结构,这是未经测试的代码!):

    require 'rake/testtask'
    
    namespace :test do
      task :spec do
        test_files = ...
        test_files.each do |test_file|
          RSpec::Core::RakeTask.new do |task|
            task.rspec_opts = test_file
          end
      end
    end
    

    你也有一个例子:how to write a custom rake task for RSpec?

    【讨论】:

    • 感谢您的回答,您的解释我明白了,但还不行。
    【解决方案2】:

    在 stackoverflow 的另一个地方找到:Whats is the replacement for spec_files in RSpec::Core::RakeTask ? Does pattern accept array of files?

    所以它接受一个文件数组,我使用 FileList 来传递文件并且只运行最后一个规范。

    感谢马丁的意见

    【讨论】:

      猜你喜欢
      • 2022-10-13
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多