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を渡します。
try have_selector:css、 "#object_field" –
ヘルパーが戻ってきた実際の文字列を確認しましたか? –
ありがとう@FrederickCheung、はい文字列にはすべての要素が含まれており、フォームは期待通りにレンダリングされます。私は、マッチャーに期待どおりに動作させることができません。 –