gpt4 book ai didi

iphone - 测试 View 助手

转载 作者:行者123 更新时间:2023-12-03 18:26:11 28 4
gpt4 key购买 nike

我目前正在开发一个 Rails 插件,用于生成 iPhone 特定的 HTML 元标记。我尝试使用 ActionView::TestCase 进行单元测试,但不断收到相同的错误。请参阅下面的文件内容和错误。任何想法或帮助将不胜感激。

test_helper.rb

require 'rubygems'
require 'test/unit'
require 'active_support'
require 'action_view'
require File.join(File.dirname(__FILE__), '..', 'lib', 'iphone_helper')

iphone_test_helper.rb

require 'test_helper'

class IphoneHelperTest < ActionView::TestCase
test 'br' do
tag = tag('br')
assert_tag_in tag, '<br />'
end
end

错误

RuntimeError: In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers

最佳答案

对我有用的糟糕而hacky的解决方法(因为我正在处理gem而不是在完整的rails环境中):

require 'ostruct'

module ActionController::UrlFor
def _routes
helpers = OpenStruct.new
helpers.url_helpers = Module.new
helpers
end
end

关于iphone - 测试 View 助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3546107/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com