在railstutorial.com第3章中编辑Guardfile错误

时间:2012-08-07 09:13:49

标签: ruby-on-rails ruby-on-rails-3

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" }

...

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

3 个答案:

答案 0 :(得分:6)

Listing 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's Guardfile复制并粘贴。

答案 1 :(得分:0)

guard'rspec',:version => 2,:all_after_pass =>假做

并添加代码

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

答案 2 :(得分:0)

如果您正在使用本教程的最新版本

,请参阅以下内容
  

要求'active_support / inflector'

     

守护'rspec',all_after_pass:false,cli:' - drb'做
  watch('config / routes.rb')#Custom Rails教程规格
  看(%r {^ app / controllers /(。+)_(控制器).rb $})do | m |       [线 “spec /路由/#{M [1]} _ routing_spec.rb”,        线 “spec /#{M [2]} S /#{M [1]} _#{M [2]} _ spec.rb”,        线 “spec /接受/#{M [1]} _ spec.rb”,        (m [1] [/ _ pages /]?“spec / requests /#{m [1]} _ spec.rb”:                          “spec / requests /#{m [1] .singularize} _pages_spec.rb”)] end
  观看(%r {^ app / views /(.+)/})做| m |       (m [1] [/ _ pages /]?“spec / requests /#{m [1]} _ spec.rb”:                         “spec / requests /#{m [1] .singularize} _pages_spec.rb”)结束
  watch(%r {^ app / controllers / sessions_controller.rb $})执行| m |       “spec / requests / authentication_pages_spec.rb”结束

     

     

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

     

警卫'rspec'看守(%r {^ spec /.+_ spec.rb $})
  观看(%r {^ lib /(.+).rb $}){| m | “spec / lib /#{m [1]} _ spec.rb”}
  观看('spec / spec_helper.rb'){“spec”}

     

#Rails示例观看(%r {^ app /(.+).rb $})
  {| m | “spec /#{m [1]} _ spec.rb”}观看(%r {^ app /(.*)(.erb | .haml)$})
  {| m | “spec /#{m [1]}#{m [2]} spec.rb”}
  观看(%r {^ app / controllers /(.+)
(控制器).rb $}){| m |   [线 “spec /路由/#{M [1]} _ routing_spec.rb”,   线 “spec /#{M [2]} S /#{M [1]} _#{M [2]} _ spec.rb”,   “spec / acceptance /#{m [1]} _ spec.rb”]}
  观看(%r {^ spec / support /(.+).rb $}){“spec”}
  watch('config / routes.rb'){“spec / routing”}   watch('app / controllers / application_controller.rb'){   “spec / controllers”}

     

#Capybara的特色是规格   观看(%r {^ app / views /(。+)/.*。(erb | haml)$}){| m |   “spec / features /#{m [1]} _ spec.rb”}

     

#Turnip功能和步骤
  手表(%R {^规格/接受/(.+)功能$})
  观看(%r {^ spec / acceptance / steps /(.+)_ steps.rb $}){| m |   Dir [File.join(“** /#{m [1]}。feature”)] [0] || 'spec / acceptance'}结束