Rake / Rspec: How to suppress / quiet / silent the first output line showing the command with --pattern ?

牧云@^-^@ 提交于 2019-12-10 14:55:16

问题


Problem:

If I run ServerSpec (based on RSpec) through Rake with one of the following commands:

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

Rake prints the command it executes to stdout before the serverspec output:

/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

If I pass the target host manually to rspec like this ...

TARGET_HOST=<host> rspec

... the line does NOT show up.

Question:

How can I prevent Rake from outputting this line / the command?


I'm using the default Rakefile generated by serverspec-init.

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:


Try changing from

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

to

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


来源:https://stackoverflow.com/questions/26297823/rake-rspec-how-to-suppress-quiet-silent-the-first-output-line-showing-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!