运行“rails generate rspec:install”时出现未定义的方法错误

时间:2014-07-05 17:19:01

标签: ruby-on-rails rspec

我正在完成Michael Hartl教程的第3章,我尝试了运行" rails generate rspec:install"我收到以下错误信息。

C:\Sites\sample_app>rails generate rspec:install
DL is deprecated, please use Fiddle
C:/Sites/sample_app/config/environments/development.rb:1:in `<top (required)>':
undefined method `configure' for #<SampleApp::Application:0x380cda8> (NoMethodEr
ror)
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-
4.0.8/lib/active_support/dependencies.rb:229:in `require'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-
4.0.8/lib/active_support/dependencies.rb:229:in `block in require'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-
4.0.8/lib/active_support/dependencies.rb:214:in `load_dependency'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-
4.0.8/lib/active_support/dependencies.rb:229:in `require'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/engine.rb:591:in `block (2 levels) in <class:Engine>'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/engine.rb:590:in `each'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/engine.rb:590:in `block in <class:Engine>'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/initializable.rb:30:in `instance_exec'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/initializable.rb:30:in `run'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/initializable.rb:55:in `block in run_initializers'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:150:in `block i
n tsort_each'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:183:in `block (
2 levels) in each_strongly_connected_component'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:210:in `block (
2 levels) in each_strongly_connected_component_from'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:219:in `each_st
rongly_connected_component_from'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:209:in `block i
n each_strongly_connected_component_from'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/initializable.rb:44:in `each'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/initializable.rb:44:in `tsort_each_child'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:203:in `each_st
rongly_connected_component_from'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:182:in `block i
n each_strongly_connected_component'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each_st
rongly_connected_component'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_e
ach'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/initializable.rb:54:in `run_initializers'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/application.rb:215:in `initialize!'
        from C:/Sites/sample_app/config/environment.rb:5:in `<top (required)>'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/application.rb:189:in `require'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/application.rb:189:in `require_environment!'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.8
/lib/rails/commands.rb:44:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

这是我的宝石文件

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.8'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

我的config / enivronments / development.rb文件的第一行

Rails.application.configure do

我查了一下这个问题的其他答案。他们建议将development.rb文件中的第一行更改为SampleApp:Application.configure.do;但这只会导致另一个错误&#39;单位化常数SampleApp&#39;。所以我把它改回了默认值。

编辑:将其修复为SampleApp :: Application,运行后得到此cmd行消息&#34; rails生成rspec:install&#34;

C:\Sites\sample_app>rails generate rspec:install
DL is deprecated, please use Fiddle
      create  .rspec
      create  spec
      create  spec/spec_helper.rb

1 个答案:

答案 0 :(得分:-1)

谢谢,确定将第一行更改为

SampleApp::Application.configure do

看起来你错过了双::

相信这个S.O. answer