【问题标题】:Testing render_template with Rails 4使用 Rails 4 测试 render_template
【发布时间】:2014-06-10 05:05:05
【问题描述】:

我在 Rails 3.2 上有这个工作测试

it('render messages') { expect(helper.error_message('test')).to render_template('message') }

但是这在 Rails 4 上不起作用,这是消息:

  2) ApplicationHelper#error_message render messages
     Failure/Error: it('render messages') { expect(helper.error_message('test')).to render_template('message') }
       expecting <"message"> but rendering with <["_message"]>
     # ./spec/helpers/application_helper_spec.rb:9:in `block (3 levels) in <top (required)>'

我已经在 ActionView 上搜索了可能会影响这一点的更改,但没有找到任何东西。我想知道解决方案是否只是添加_

expect(helper.error_message('test')).to render_template('_message')

或者这样做有什么缺点吗?

【问题讨论】:

    标签: testing ruby-on-rails-4 rspec ruby-on-rails-3.2 actionview


    【解决方案1】:

    这是部分内容,对吗?将部分名称传递给render_template

    render_template(:partial => "_message")
    

    更多信息在Guide to Testing Rails Applications

    【讨论】:

      猜你喜欢
      • 2014-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-21
      相关资源
      最近更新 更多