Rake / Rspec:如何使用--pattern来显示命令的第一个输出行?

时间:2014-10-10 10:56:12

标签: ruby rspec rake serverspec

问题:

如果我使用以下命令之一通过ServerSpec运行RSpec(基于Rake):

  • rake
  • rake spec
  • rake spec:all
  • rake spec:<host>
  • bundle exec rake
  • ...

Rake在serverspec输出之前将它执行的命令打印到stdout

/usr/bin/ruby1.9.1 
-I/var/lib/gems/1.9.1/gems/rspec-core-3.1.6/lib:/var/lib/gems/1.9.1/gems/rspec-support-3.1.2/lib 
/var/lib/gems/1.9.1/gems/rspec-core-3.1.6/exe/rspec 
--pattern spec/<host>/\*_spec.rb

如果我将目标主机手动传递给rspec,就像这样......

TARGET_HOST=<host> rspec

...该行 NOT 显示。

问题:

如何阻止Rake输出此行/命令?


我使用serverspec-init生成的默认Rakefile。

require 'rake'
require 'rspec/core/rake_task'

task :spec    => 'spec:all'
task :default => :spec

namespace :spec do
  targets = []
  Dir.glob('./spec/*').each do |dir|
    next unless File.directory?(dir)
    targets << File.basename(dir)
  end

  task :all     => targets
  task :default => :all

  targets.each do |target|
    desc "Run serverspec tests to #{target}"
    RSpec::Core::RakeTask.new(target.to_sym) do |t|
      ENV['TARGET_HOST'] = target
      t.pattern = "spec/#{target}/*_spec.rb"
    end
  end
end

1 个答案:

答案 0 :(得分:6)

尝试从

更改
RSpec::Core::RakeTask.new(target.to_sym) do |t|
  ENV['TARGET_HOST'] = target
  t.pattern = "spec/#{target}/*_spec.rb"
end

RSpec::Core::RakeTask.new(target.to_sym) do |t|
  ENV['TARGET_HOST'] = target
  t.pattern = "spec/#{target}/*_spec.rb"
  t.verbose = false
end