在minitest中使用助手 [英] Using helpers in minitest
本文介绍了在minitest中使用助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用minitest测试我的应用程序类,但出现错误,提示undefined method image_path
.我该如何解决?
I'm trying to test my app class in using minitest but I am getting a error stating undefined method image_path
. How can I get around this?
require 'test_helper'
class AppTest < ActiveSupport::TestCase
setup do
@app = apps(:app_one)
end
test 'should have icon_url' do
assert(@app.icon_url == image_path('icn-medium-norm.png'))
end
end
app/models/app.rb
class App < ActiveRecord::Base
has_many :versions, dependent: :destroy
has_many :user_subscriptions, dependent: :destroy
has_many :users, through: :user_subscriptions
validates :name, uniqueness: { case_sensitive: false, scope: :app_type }
scope :since, ->(time) { where('created_at > ?', time) }
scope :ios, -> { where("app_type = 'ios' ") }
scope :android, -> { where("app_type = 'android' ") }
def icon_url
versions.last[:icon_url] || image_path('icn-medium-norm.png')
end
...
end
即使我做类似的事情
test 'should have icon_url' do
assert(@app.icon_url =~ %r{.png})
end
由于应用程序模型,我得到了相同的错误
I get the same error because of the app model
推荐答案
尝试:
assert_equal @app.icon_url, ApplicationController.helpers.image_path('icn-medium-norm.png')
参考: https://stackoverflow.com/a/7465398/429758
这篇关于在minitest中使用助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文