1

次のビューがありますが、ビューの仕様では適切に特定できません。

ファイル: "products / index.html.haml"

#products
  = render @products

そして、これは私のビューの仕様です:

require 'spec_helper'

describe "products/index.html.haml" do
  let(:products) {[mock_model(Product)]}

  before do
    stub_template "products/product.html.haml" => "" 
    render
  end

  it "should render the products" do
    rendered.should have_selector(#products) do
    rendered.should render_template products
  end
end

ここでの問題は、have_selectorがブロックを受け入れないため、パーシャルが#productsdiv内にレンダリングされていることを表明する方法がないことです。CapybaraマッチャーはView仕様内では機能しないため、どちらでも使用できません。

この問題も参照してください:https ://github.com/rspec/rspec-rails/issues/387

4

2 に答える 2

4

正解は、webratはブロックを取りますが、capybaraはブロックを取りません。

これは、カピバラの作成者であるJonas Nicklasが、なぜそれが行われないのか、そして彼がそれを追加する予定がないことを説明する問題です。

https://github.com/jnicklas/capybara/issues/384

Object#tapを使用してブロックをcapybaraの#findに渡す例がいくつかありましたが、これはおそらく一度は機能しましたが、もう機能していないようです。

更新:現在rspec / capybaraでこれを行う方法がないというDavidからの確認:

https://groups.google.com/forum/?fromgroups=#!topic/rspec/HBfznq4Yd0k

于 2012-12-14T04:02:36.383 に答える
0

私がしているのは、パーシャルがレンダリングするクラスまたはIDをテストすることです。そして、have_selectorはブロックを受け入れます。

 it "should render the products" do
   rendered.should have_selector('#products') do |products|
     products.should have_select('.product')
   end
   rendered.should render_template 'products'
 end
于 2011-06-08T06:16:35.750 に答える