2016-07-31 5 views
0

私は、フォームmatch/id = "MyId "/passesのときにhave_selector "#MyId"が失敗するのはなぜですか?

#helpers/my_helper.rb 
def build_form 
    form_for object, url: object_path, method: :post do |f| 
    html = f.text_input :field 
    html += f.submit 
    html.html_safe 
    end 
end 

そして、このヘルパーのテスト

#spec/helpers/my_helper_spec.rb 
describe MyHelper do 
    it { expect(helper.my_helper).to have_selector "form[action='#{objects_path}'][method='post']" } # PASSES 
    it { expect(helper.my_helper).to have_selector "#object_field" } #FAILS - but this should pass 
    it { expect(helper.my_helper).to match /id=\"object_field\"/ } # PASSES 
end 

を生成し、レールのヘルパーを持っている私はまだRSpecの勉強なので、これは明白な疑問かもしれません。

have_selectorを入力に使用すると、これらのテストが失敗するのはなぜですか?そして、have_selectorは正しくformタグを渡し、matchは入力IDを渡します。

+0

try have_selector:css、 "#object_field" –

+0

ヘルパーが戻ってきた実際の文字列を確認しましたか? –

+0

ありがとう@FrederickCheung、はい文字列にはすべての要素が含まれており、フォームは期待通りにレンダリングされます。私は、マッチャーに期待どおりに動作させることができません。 –

答えて

0

私は理解していますが、object_fieldは要素のidを含む変数です。 trueの場合は、次に試してください:

関連する問題