القضبان تزوير طريق
-
27-09-2019 - |
سؤال
لكي أكون محددًا ، أحاول الحصول على ActionController::Routing::Routes.recognize_path
للتعرف على طريق غير موجود routes.rb
, ، لأغراض تجريبية.
هل من الممكن أن يسخر بطريقة أو بأخرى أو إضافة مسار؟ أنا أستخدم RSPEC مع Mocha.
المحلول
ليس لدي أي فكرة على الإطلاق ما إذا كنت ستعمل ولكن يمكنك تجربة شيء مثل هذا:
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
نصائح أخرى
ال fakeweb
جوهرة في http://github.com/chrisk/fakeweb قد تناسب احتياجاتك.
كيفية تسجيل استجابة السلسلة الأساسية (من 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"))
في هذه الحالة ، يتم تجاوز FAPEWEB وإعادة الاستجابة من طلب حقيقي
لا تنتمي إلى StackOverflow