Вот моя спецификация для страницы, которая использует кнопку для запуска Javascript, чтобы развернуть усеченный текст description
.
it 'gets the description and inventory', js: true do
product = Product.create!(name: "Test Product", inventory: 0, description: "This is a test description with more text than should be there.")
customer = Customer.create(:name => Faker::Name.name)
invoice = Invoice.create
order = Order.create(customer: customer, invoice: invoice)
order.products << product
visit products_path
expect(page).to have_content(product.name, count: 1)
expect(page).not_to have_content product.description
click_button "More Info"
expect(page).to have_content product.description
expect(page).to have_content "Sold Out"
product.inventory = 1
product.save
visit products_path
click_button "More Info"
expect(page).to have_content "Available"
end
Когда я запускаю сервер rails и захожу на страницу в браузере,Кнопка «Подробнее» определенно работает правильно.Однако, когда я запускаю спецификацию, кнопка не работает:
1) Products products index gets the description and inventory
Failure/Error: expect(page).to have_content product.description
expected to find text "This is a test description with more text than should be there." in "Flatiron Widgets Store Products Test Product This is a test description ... More Info"
# ./spec/features/product_feature_spec.rb:47:in `block (3 levels) in <top (required)>'
Теперь я знаю, что вполне возможно, что есть какая-то проблема, из-за которой кнопка фактически не работает, но я 'Мне интересно, если проблема в том, что мы на самом деле проверяем page
, который не был очищен с тех пор, как была нажата кнопка.
Кто-нибудь знает, действительно ли это проблема, и если да, тоесть ли способ "перепроверять" страницу?Я не собираюсь перезагружать или обновлять страницу, потому что это переведет JS в исходное состояние предварительной кнопки.