0

在 3.6.2 使用 Guard 进行自动化测试

教程是..

require 'active_support/core_ext'

guard 'rspec', :version => 2, :all_after_pass => false do   .   .   .  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  do |m|
    ["spec/routing/#{m[1]}_routing_spec.rb",
     "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
     "spec/acceptance/#{m[1]}_spec.rb",
     (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : 
                       "spec/requests/#{m[1].singularize}_pages_spec.rb")]   end   watch(%r{^app/views/(.+)/}) do |m|
    (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : 
                       "spec/requests/#{m[1].singularize}_pages_spec.rb")   end   .   .   . end

但我不知道如何编辑我的 Guardfile

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'rspec', :version => 2 do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example

...

guard 'rspec', :version => 2 do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

...

请帮我。只是插入吗?但同样的错误..

4

3 回答 3

6

清单 3.3.4只是告诉您应该对默认Guardfile进行哪些更改和添加。所以:

换行

guard 'rspec', :version => 2 do

guard 'rspec', :version => 2, :all_after_pass => false do

并添加其余代码

watch(%r{^app/controllers/(.+)_(controller)\.rb$})  do |m|
  ["spec/routing/#{m[1]}_routing_spec.rb",
   "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
   "spec/acceptance/#{m[1]}_spec.rb",
   (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : 
                     "spec/requests/#{m[1].singularize}_pages_spec.rb")]
end
watch(%r{^app/views/(.+)/}) do |m|
  (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : 
                    "spec/requests/#{m[1].singularize}_pages_spec.rb")
end

Guardfile的末尾。

或者,您可以直接从sample_app Github repo 的Guardfile复制和粘贴。

于 2012-08-07T16:14:21.530 回答
0

守卫 'rspec', :version => 2, :all_after_pass => false 做

并添加代码

watch(%r{^app/controllers/(.+)_(controller)\.rb$})  do |m|
  ["spec/routing/#{m[1]}_routing_spec.rb",
   "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
   "spec/acceptance/#{m[1]}_spec.rb",
   (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : 
                     "spec/requests/#{m[1].singularize}_pages_spec.rb")]
end
watch(%r{^app/views/(.+)/}) do |m|
  (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : 
                    "spec/requests/#{m[1].singularize}_pages_spec.rb")
end
于 2012-08-16T07:11:42.977 回答
0

如果您正在执行本教程的最新版本,它应该是这样的

需要'active_support/inflector'

guard 'rspec', all_after_pass: false, cli: '--drb' do
watch('config/routes.rb') # 自定义 Rails 教程规范
watch(%r{^app/controllers/(.+)_(controller) .rb$}) 做 |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb", (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : "spec/requests/ #{m[1].singularize}_pages_spec.rb")] end
watch(%r{^app/views/(.+)/}) 做 |m| (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : "spec/requests/#{m[1].singularize}_pages_spec.rb") 结束
观察( %r{^app/controllers/sessions_controller.rb$}) 做 |m| "

结尾

守卫 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } 看('config/application.rb') 看('config/ environment.rb') watch('config/environments/test.rb') watch(%r{^config/initializers/.+.rb$}) watch('Gemfile')
watch('Gemfile.lock') watch( 'spec/spec_helper.rb') { :rspec }
watch('test/test_helper.rb') { :test_unit }
watch(%r{features/support/}) { :cucumber }
watch(%r{^spec/support /.+.rb$}) 结束

守卫 'rspec' 做 watch(%r{^spec/.+_spec.rb$})
watch(%r{^lib/(.+).rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails 示例 watch(%r{^app/(.+).rb$})
{ |m| "spec/#{m[1]}_spec.rb" } watch(%r{^app/(.*)(.erb|.haml)$})
{ |m| "spec/#{m[1]}#{m[2]} spec.rb" }
watch(%r{^app/controllers/(.+)
(controller).rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+).rb$}) { "spec" }
watch('config/routes.rb ') { "spec/routing" } watch('app/controllers/application_controller.rb') { "spec/controllers" }

# Capybara 功能规格
watch(%r{^app/views/(.+)/.*.(erb|haml)$}) { |m| “规格/功能/#{m[1]}_spec.rb”}

# 萝卜特征和步骤
watch(%r{^spec/acceptance/(.+).feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps.rb$}) { |m| 目录[File.join("**/#{m[1]}.feature")][0] || '规范/接受' } 结束

于 2014-01-18T01:12:28.857 回答