1

具体的には、テスト目的ActionController::Routing::Routes.recognize_pathで、にないルートを認識しようとしています。routes.rb

何らかの方法でルートをモックまたは動的に追加することは可能ですか? モカでRspecを使用しています。

4

2 に答える 2

3

うまくいくかどうかはまったくわかりませんが、次のようなことを試すことができます。

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
于 2010-08-10T00:03:49.567 に答える
0

http://github.com/chrisk/fakewebfakewebgemはあなたのニーズに合うかもしれません。

基本的な文字列応答を登録する方法(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はバイパスされ、実際のリクエストからの応答が返されます

于 2010-08-10T02:31:35.003 に答える