【问题标题】:Cleaning up Rake cucumber tasks清理耙黄瓜任务
【发布时间】:2011-03-23 23:37:34
【问题描述】:

我通过 rake 使用 Cucumber,发现自己在为 Cucumber 执行额外任务时重复代码。有没有办法简化/缩小以下内容:

...
  namespace :cucumber do
    Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
      t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
      t.fork = true # You may get faster startup if you set this to false
      t.profile = 'default'
    end

    Cucumber::Rake::Task.new({:report => 'db:test:prepare'}, 'Run features that should pass') do |t|
      t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
      t.fork = true # You may get faster startup if you set this to false
      t.profile = 'report'
    end

    Cucumber::Rake::Task.new({:report_pdf => 'db:test:prepare'}, 'Run features that should pass') do |t|
      t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
      t.fork = true # You may get faster startup if you set this to false
      t.profile = 'report_pdf'
    end

    Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
      t.binary = vendored_cucumber_bin
      t.fork = true # You may get faster startup if you set this to false
      t.profile = 'wip'
    end

    Cucumber::Rake::Task.new({:new => 'db:test:prepare'}, 'Run all new features that are being worked on') do |t|
      t.binary = vendored_cucumber_bin
      t.fork = true # You may get faster startup if you set this to false
      t.profile = 'new'
    end

    Cucumber::Rake::Task.new({:new_report => 'db:test:prepare'}, 'Run all new features that are being worked on') do |t|
      t.binary = vendored_cucumber_bin
      t.fork = true # You may get faster startup if you set this to false
      t.profile = 'new_report'
    end

    Cucumber::Rake::Task.new({:new_report_pdf => 'db:test:prepare'}, 'Run all new features that are being worked on') do |t|
      t.binary = vendored_cucumber_bin
      t.fork = true # You may get faster startup if you set this to false
      t.profile = 'new_report_pdf'
    end

    Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
      t.binary = vendored_cucumber_bin
      t.fork = true # You may get faster startup if you set this to false
      t.profile = 'rerun'
    end
...

【问题讨论】:

    标签: ruby-on-rails cucumber rake task


    【解决方案1】:

    这应该可以工作

    namespace :cucumber do
      [[:ok, 'default'], :report, :report_pdf, :wip, :new, :new_report, :new_report_pdf, :rerun].each do |key|
        if key.is_a?(Array)
          profile = key[1]
          key = key[0]
        else
          profile = key.to_s
        end
    
        Cucumber::Rake::Task.new({key => 'db:test:prepare'}, 'Run features that should pass') do |t|
          t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
          t.fork = true # You may get faster startup if you set this to false
          t.profile = profile
        end
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-21
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多