私は私のレールアプリに関するいくつかのテストをしています。私はいくつかのフォームについて宝石の繭を使用しています。私は "日付選択"をテストするいくつかのトラブルがあります。私が間違っていることを知りたいのですが、あなたの助けが大いに評価されるでしょう!RSpec - 日付コクーンの宝石
ここで私がこれまで行ってきたものを下記見つけてください:求人フォーム
ネストされたフィールドを(私は入力フィールドstarted_atをテストしようとしています)
.nested-fields
= f.input :company_name, label:'Nom de entreprise', input_html: {class: "form-control job-company-name"}
= f.input :title, label: 'Votre fonction', input_html: {class: "form-control job-title "}
= f.input :location, label: 'Lieu de travail', input_html: {class: "form-control job-location"}
= f.input :started_at, discard_day: true, order: [:month, :year], include_blank: true, label:'Date début',input_html: {class: "work-started-at job-started-at"}, start_year: 1970, end_year: 2016, :id => 'task_target_date'
= f.input :finished_at, discard_day: true, order: [:month, :year], label: 'Date fin (mettre le mois en cours si c\'est votre emploi actuel)',input_html: {class: "work-finished-at end_date job-finished-at"},start_year: 1970, end_year: 2016, :default => Time.now
= f.input :description, label: 'Vos responsabilités',:input_html => {:rows => 9, style: 'max-width:100%;', class: ""}
.remove-experience.text-center
= link_to_remove_association "supprimer cette expérience", f, class: 'btn btn-delete form-button'
RSpecのとカピバラ
require 'rails_helper'
RSpec.feature "Edit Profile" do
scenario "Profile updated successfully ", js: true do
Given "user visits profile edit page"
When "user updates profile basic info"
When "user updates work experiences info"
When "user updates education info"
Then "user views profile updated"
end
def user_updates_work_experiences_info
click_link "Parcours professionnel"
click_link "Ajouter une expérience"
find(".job-company-name").set("Natixis")
find(".job-title").set("Contrôleur Financier")
find(".job-location").set("Paris")
select_date("2013,December,7", :from => "Date début")
end
def select_date(date, options = {})
field = options[:from]
base_id = find(:xpath, ".//label[contains(.,'#{field}')]")[:for]
year, month, day = date.split(',')
select year, :from => "#{base_id}_1i"
select month, :from => "#{base_id}_2i"
end
end
テストを実行すると、次のメッセージが表示されます。
Failure/Error: select year, :from => "#{base_id}_1i"
Capybara::ElementNotFound:
Unable to find select box "profile_experiences_attributes_1467917726232_started_at_2i_1i"
君たちをありがとう;)
あなたのERBを見てみると
ラベルに "job-started-at"という文字が含まれていないと推測していますので、実際に生成されたHTMLをerbよりも追加してください。 –