具体的には、テスト目的ActionController::Routing::Routes.recognize_path
で、にないルートを認識しようとしています。routes.rb
何らかの方法でルートをモックまたは動的に追加することは可能ですか? モカでRspecを使用しています。
具体的には、テスト目的ActionController::Routing::Routes.recognize_path
で、にないルートを認識しようとしています。routes.rb
何らかの方法でルートをモックまたは動的に追加することは可能ですか? モカでRspecを使用しています。
うまくいくかどうかはまったくわかりませんが、次のようなことを試すことができます。
class ApplicationController < ActionController::Base
rescue_from ActionView::MissingTemplate do |exception|
# use exception.path to extract the path information
ActionController::Routing::Routes.draw do |map|
# Add your dynamic route using path here and then do a redirect to it
end
end
end
http://github.com/chrisk/fakewebのfakeweb
gemはあなたのニーズに合うかもしれません。
基本的な文字列応答を登録する方法(READMEから):
FakeWeb.register_uri(:get, "http://example.com/test1", :body => "Hello World!")
テストする:
Net::HTTP.get(URI.parse("http://example.com/test1"))
戻り値"Hello World!"
Net::HTTP.get(URI.parse("http://example.com/test2"))
この場合、FakeWebはバイパスされ、実際のリクエストからの応答が返されます