После создания нового объекта необходимо перенаправить на показ действий. Как я проверяю текущий путь?Capybara: Проверить текущий путь к создаваемому странице объекту
feature 'add lost pet' do
given(:data) {attributes_for(:lost_pet)}
background do
visit root_path
click_on 'Register new lost pet'
end
scenario 'add new lost pet with valid data' do
within '#new_lost_pet' do
fill_in 'Name', with: data[:name]
fill_in 'Type', with: data[:type]
fill_in 'Breed', with: data[:breed]
fill_in 'Gender', with: data[:gender]
fill_in 'Size', with: data[:size]
fill_in 'Colour', with: data[:colour]
fill_in 'Age', with: data[:age]
fill_in 'Age unit', with: data[:age_unit]
fill_in 'Description', with: data[:description]
fill_in 'Collar description', with: data[:collar_description]
check 'Desexed', :checked
check 'Microchipped', :checked
fill_in 'Microchip number', with: data[:microchipped_number]
select '2015', from: "lost_pet[date_missing(1i)]"
select 'October', from: 'lost_pet[date_missing(2i)]'
select '10', from: 'lost_pet[date_missing(3i)]'
fill_in 'Rewald', with: data[:rewald]
fill_in 'Image', with: data[:image]
fill_in 'Adress lost', with: data[:adress_lost]
click_on 'Create'
end
expect(current_path).to eq lost_pet_path(????)
end
Для lost_pet_path мне нужен идентификатор, но как я создаю идентификатор? Или как лучше проверить путь в Капибаре?
я добавил lost_pet = LostPet.last и получить ошибки: ** Сбой/Ошибка: ожидать (current_path) .то экв lost_pet_path (lost_pet) ctionController :: UrlGenerationError: Нет совпадений маршрутов {: action => "show",: controller => "lost_pets",: id => nil} отсутствуют необходимые ключи: [: id] ** –
асинхронный характер click_on означает Похоже, что LostPet не будет создан на данный момент (если используется любой драйвер, отличный от проверки в стойке) - так что LostPet.last будет равен нулю - см. Мой ответ –
Хорошая точка Tom. –