2016-08-10 9 views
1

私はapp/config/libにあるテストを実行しようとしていますが、RSpecのテストを見つけることができません。RSpecを設定してlibフォルダの仕様を見つけるには?私はこのチュートリアル<a href="http://apionrails.icalialabs.com/book/frontmatter" rel="nofollow">http://apionrails.icalialabs.com/book/frontmatter</a></p> <p>次のRails 5.0と少しAPIを作成してい

私はconfig.autoload_paths << Rails.root.join('lib')または 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 

RSpecのは、それに位置テストを実行しますので、どのように私はlibフォルダを追加することができますか?

ありがとうございます。

答えて

1

RSpecはautoload_pathsでテストを検索しません。引数なしでrspecまたはrake specを実行すると、RSpecはデフォルトでspecディレクトリを探します。 applib

rspec app/config/lib/spec 

しかし、それはだあなたのコードは別のspecのディレクトリにあなたのスペックを維持するための普遍的な規則を、:あなたは別のディレクトリにスペックを実行したい場合は、引数としてrspecにそのディレクトリを与えます、私はあなたの仕様をspec/libに移しました。 RSpecは特別な努力なしにそれらを見つけるでしょう。

関連する問題

 関連する問題