我正在按照本教程http://apionrails.icalialabs.com/book/frontmatter使用 Rails 5.0 创建一个小 API
我正在尝试运行位于的测试,app/config/lib
但 RSpec 找不到该测试。
我已经尝试添加config.autoload_paths << Rails.root.join('lib')
or
config.autoload_paths += %W(#{config.root}/lib)
到app/config/application.rb
.
这是我的代码:
$ /app/config/application.rb
#required files go here, deleted for clarity.
Bundler.require(*Rails.groups)
module MarketPlaceApi
class Application < Rails::Application
# don't generate RSpec tests for views and helpers
config.generators do |g|
g.test_framework :rspec, fixture: true
g.fixture_replacement :factory_girl, dir: 'spec/factories'
g.view_specs false
g.helper_specs false
g.stylesheets = false
g.javascripts = false
g.helper = false
end
config.autoload_paths += %W(#{config.root}/lib)
end
end
测试
$ app/config/lib/spec/test_spec.rb
require 'spec_helper'
describe ApiConstraints do
#test goes here
end
如何添加lib
文件夹以便 RSpec 运行其中的测试?
提前致谢。