【问题标题】:Extend view with RSpec.configure使用 RSpec.configure 扩展视图
【发布时间】:2013-10-17 14:29:54
【问题描述】:

我禁用了 ActionController 的 include_all_helpers,所以我必须在我的视图规范中处理这个问题。这工作正常:

require 'spec_helper'

describe "admin/test.html.haml" do
  before(:each) { view.extend Admin::BaseHelper }
  it { render }
end

我想将前一行提取到 spec_helper.rb:

RSpec.configure do |config|
  config.before(:each, type: :view) do
    if example.metadata[:full_description].start_with?('admin/')
      view.extend Admin::BaseHelper
    end
  end
end

没有我的规范失败:

undefined method `view_context' for nil:NilClass

所以我的扩展调用导致视图为零?我错过了什么吗?还是我误会了什么?

【问题讨论】:

标签: ruby-on-rails ruby ruby-on-rails-3 rspec


【解决方案1】:

我的代码似乎没问题,它似乎是bug in rspec-rails 或相关项目。感谢 phoet 的提示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2018-09-15
    • 2011-11-01
    相关资源
    最近更新 更多