4

キャッシュが無効な場合とキャッシュが有効な場合のアクション キャッシュをテストする仕様があります。テストの実行順序が合格するかどうかに影響するようです。

it "should not cache the index page when we're not caching" do
    ActionController::Base.perform_caching = false
    HomeController.caches_action :index
    Rails.cache.clear
    ActionController::Base.cache_store.exist?(:index_cache_path).should be_false
    get :index
    ActionController::Base.cache_store.exist?(:index_cache_path).should be_false
end

it "should cache the index page when we're caching" do
    ActionController::Base.perform_caching = true
    HomeController.caches_action :index
    Rails.cache.clear
    ActionController::Base.cache_store.exist?(:index_cache_path).should be_false
    get :index
    ActionController::Base.cache_store.exist?(:index_cache_path).should be_true
end

上記の順序でテストを実行すると、最後の期待値に cache_store が存在しないため、最後のテストが失敗します。キャッシングなしのテストがキャッシングのテストに影響を与えている理由に困惑しています。誰が何が悪いのか知っていますか?

4

2 に答える 2

1

「ActionController::Base.perform_caching = false」の設定を元に戻していないため、spec_helper.rb のランダム テスト順序を true にすると意味があります。

キャッシング テストを記述する推奨される方法は、キャッシング設定のオンとオフを設定する before(:each) と after(:each) を実行することです。

これらの設定をテストしているので、オンにする場合は、テストが終了する前にオフにすることを忘れないでください。逆の場合も同様です。テストはよりアトミックになります。

于 2013-04-02T02:27:24.153 に答える