Stuck On Rails应用程序

时间:2016-04-28 07:20:03

标签: ruby-on-rails ruby ruby-on-rails-4 rspec

以下是终端中的问题:

    treehouse:~/projects/odot (master *) $ bin/rails generate model todo_item todo_list:references content:string -p
/home/treehouse/projects/odot/config/application.rb:23:in `<class:Application>': undefined method `configure' for RSpec:Module (NoMethodError)
    from /home/treehouse/projects/odot/config/application.rb:10:in `<module:Odot>'
    from /home/treehouse/projects/odot/config/application.rb:9:in `<top (required)>'
    from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/commands.rb:43:in `require'
    from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/commands.rb:43:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

这是odot / config / application.rb文件:

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module Odot
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    RSpec.configure do |c|
        c.expose_current_running_example_as :example
    end

    RSpec.configure do |c|
        c.expose_current_running_example_as :example
    end
  end
end

这是bin / rails文件:

#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application',  __FILE__)
require_relative '../config/boot'
require 'rails/commands'

我不知道如何访问.rbenv / ....文件。

我似乎无法绕过什么是错的。这些是启动rails todo list应用程序时文件夹中的默认文件。我在三个不同的文件中进行了几次rspec测试,在完成最后一次测试之后,我不会让任何其他任务继续执行。

这在运行bin / rake时继续进行:

rake aborted!
NoMethodError: undefined method `configure' for RSpec:Module
/home/treehouse/projects/odot/config/application.rb:23:in `<class:Application>'
/home/treehouse/projects/odot/config/application.rb:10:in `<module:Odot>'
/home/treehouse/projects/odot/config/application.rb:9:in `<top (required)>'
/home/treehouse/projects/odot/Rakefile:4:in `require'
/home/treehouse/projects/odot/Rakefile:4:in `<top (required)>'

然后是rakefile文件:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Odot::Application.load_tasks

我不知道发生了什么事。运气好的话?欢呼声。

1 个答案:

答案 0 :(得分:0)

不要将RSpec配置放在application.rb中。 application.rb用于rails app的核心配置,适用于所有环境。您可以使用它来设置时区等内容以及要在rails堆栈中使用的中间件。

RSpec应放在Gemfile的测试组中,以便在不需要时不加载 - 生产中的IE。

gem 'something'

group :test do
  gem 'rspec-rails'
end

application.rb还有一个非常重要的部分:

Bundler.require(:default, Rails.env)

告诉Bundler加载默认组和当前&#34;环境组中的所有宝石&#34; (开发,测试或生产)。因此,如果您在生产中启动服务器,它将会在RSpec.configure行上爆炸,因为RSpec gem不是必需的(也不应该)。

Rspec配置的正确位置为spec/spec_helper.rbspec/rails_helper.rb