【问题标题】:RSpec doesn't automatically determine view spec typeRSpec 不会自动确定视图规范类型
【发布时间】:2014-12-28 23:05:41
【问题描述】:

我有一个位于app/views/shared/_card_instance.html.haml 的视图。以下规范通过:

spec/views/_card_instance.html.haml_spec.rb

require 'spec_helper'

describe 'card_instance partial', type: :view do
  it 'should just display the missing slot if present' do
    card = double(:card, missing_slot: 'Rare')
    render 'shared/card_instance', card: card

    expect(rendered).to have_css('.card', text: 'Rare')
  end
end

但是,如果我删除 type: :view,它会失败:

Failures:

  1) card_instance partial should just display the missing slot if present
     Failure/Error: render 'shared/card_instance', card: card
     NoMethodError:
       undefined method `render' for #<RSpec::ExampleGroups::CardInstancePartial:0x5d02b50>
     # ./spec/views/_card_instance.html.haml_spec.rb:6:in `block (2 levels) in <top (required)>'

为什么? RSpec 不应该根据路径将规范标识为视图规范吗?

(RSpec 3.1;Rails 3.2;Windows)

【问题讨论】:

    标签: ruby-on-rails rspec rspec3


    【解决方案1】:

    【讨论】:

    • 啊哈!这也解释了我在使用辅助规范时遇到的问题。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多