Ruby 如何使用RSpec::Core::RakeTask创建RSpec-Rake任务?

Ruby 如何使用RSpec::Core::RakeTask创建RSpec-Rake任务?,ruby,rspec,rake,Ruby,Rspec,Rake,如何使用RSpec::Core::RakeTask初始化RSpec-Rake任务 require 'rspec/core/rake_task' RSpec::Core::RakeTask.new do |t| # what do I put in here? end 需要“rspec/core/rake_任务” RSpec::Core::RakeTask.new do | t| #我在这里放什么? 结束 初始化函数记录在 没有很好的记录;它只是说: -(RakeTask)初始化(*参数和

如何使用RSpec::Core::RakeTask初始化RSpec-Rake任务

require 'rspec/core/rake_task' RSpec::Core::RakeTask.new do |t| # what do I put in here? end 需要“rspec/core/rake_任务” RSpec::Core::RakeTask.new do | t| #我在这里放什么? 结束 初始化函数记录在 没有很好的记录;它只是说:

-(RakeTask)初始化(*参数和任务块) 拉基塔斯克的一个新实例 我应该为*args和&task_块放置什么

我跟随的是一位已经开始使用RSpec和Rake为PHP项目构建一些ruby自动化的人。我习惯于在没有Rake的情况下使用RSpec,因此我不熟悉语法

谢谢,
-Kevin

以下是我的Rakefile的一个示例:

require 'rspec/core/rake_task'

task :default => [:spec]

desc "Run the specs."
RSpec::Core::RakeTask.new do |t|
  t.pattern = "spec.rb"
end

desc "Run the specs whenever a relevant file changes."
task :watch do
  system "watchr watch.rb"
end

这允许从Rake运行spec.rb文件中定义的spec

这就是我的rakefile的样子

gem 'rspec', '~>3'
require 'rspec/core/rake_task'

task :default => :spec

desc "run tests for this app"
RSpec::Core::RakeTask.new do |task|
  test_dir = Rake.application.original_dir
  task.pattern = "#{test_dir}/*_spec.rb"
  task.rspec_opts = [ "-I#{test_dir}", "-I#{test_dir}/source", '-f documentation', '-r ./rspec_config']
  task.verbose = false
end
您可以从您的测试目录中“rake”,它将运行名为[something]\u spec.rb的所有测试,并且它应该可以跨不同的测试目录(例如,不同的项目)工作;如果您的源代码位于单独的目录中(例如,在上面的代码中,一个名为“/source”的子目录),它将拾取它们。显然,您可以将该源代码目录更改为所需的目录

以下是我使用的rspec_配置文件-您可以在此处添加自己的设置:

RSpec.configure do |c|
  c.fail_fast = true
  c.color = true
end
我用了
t.pattern=“spec/***\u spec.rb”
。谢谢。
RSpec.configure do |c|
  c.fail_fast = true
  c.color = true
end