我正在使用rspec练习Rails4中的TDD内容,并打算通过命令创建多个文件夹,例如factories
,model
,requests
,controller
。所以我将这一行添加到config/application.rb
:
config.generators do |g|
g.test_framework :rspec,
:model_specs => true,
:view_specs => false,
:helper_specs => false,
:routing_specs => false,
:controller_specs => true,
:request_specs => true
g.fixture_replacement :factory_girl, :dir => "spec/factories"
end
然而。当我在命令行中运行rails g rspec:install
时。系统返回错误:
/home/rayvonmice/workspace/kulu/config/application.rb:14:in `<top (required)>': undefined local variable or method `config' for main:Object (NameError)
from /home/rayvonmice/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/commands.rb:44:in `require'
from /home/rayvonmice/.rvm/gems/ruby-2.0.0-p247@global/gems/railties-4.0.0/lib/rails/commands.rb:44:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
所以我不明白config/application.rb
文件有什么问题。这是否意味着我只能手动生成这些文件夹?
答案 0 :(得分:0)
看起来你在config
之外的地方调用了它。
尝试将代码移动到以:
开头的块中module Kulu
class Application < Rails::Application
...
config.generators do |g|
g.test_framework :rspec,
:model_specs => true,
:view_specs => false,
:helper_specs => false,
:routing_specs => false,
:controller_specs => true,
:request_specs => true
g.fixture_replacement :factory_girl, :dir => "spec/factories"
end
...
end