我有一个像这样的简单规范:
scenario "Fill the payments information for a painting", js: true do
period = create(:period)
painting = create(:painting, period: period, published: false)
admin = AdminUser.create!(email: 'admin@example.com', password: 'test1234')
painting_price = create(:painting_price)
sign_in
visit new_painting_order_path(painting_id: painting.id, painting_price_id: painting_price.id)
click_on "MasterCard/Visa"
puts Painting.unscoped
click_on "Compléter la commande"
expect(admin.email).to have_received_an_email
end
这样的控制器:
def create
puts Painting.unscoped
# ...
end
在第一个puts
,我有一幅画,但在第二个,没有画。我激活了SQL跟踪,我有这个:
Painting Load (0.5ms) SELECT "paintings".* FROM "paintings" | ETA: ??:??:??
[#<Painting id: 1, artist_id: 1, title: "A title for the painting", year: "1997", technic: "A technic", dimensions: "20\" X 10\"", created_at: "2014-08-10 11:08:01", updated_at: "2014-08-10 11:08:01", owner_id: 1, painting_technic_id: 1, painting_type_id: 1, measure_unit_
id: 1, painting_category_id: 2, height: 100, width: 100, depth: 10, height_with_frame: nil, width_with_frame: nil, depth_with_frame: nil, ref_catalog: nil, authenticity_certificate: nil, signature: nil, comment: nil, period_id: 1, published: false, address: "43 rue de la
boustifaille", postal_code: "G0G 2B0", city: "Sept-Iles", phone: "0123456789", country_id: 3, region_id: nil, end_publishing_date: nil, on_demand: true, numbered: nil, framed: nil, painting_price_id: nil, source: nil, number: nil>]
(0.9ms) ALTER TABLE "active_admin_comments" DISABLE TRIGGER ALL;ALTER TABLE "provider_services" DISABLE TRIGGER ALL;ALTER TABLE "painting_category_translations" DISABLE TRIGGER ALL;ALTER TABLE "page_translations" DISABLE TRIGGER ALL;ALTER TABLE "painting_provenances"
DISABLE TRIGGER ALL;ALTER TABLE "painting_technics" DISABLE TRIGGER ALL;ALTER TABLE "painting_type_translations" DISABLE TRIGGER ALL;ALTER TABLE "region_translations" DISABLE TRIGGER ALL;ALTER TABLE "orders" DISABLE TRIGGER ALL;ALTER TABLE "pages" DISABLE TRIGGER ALL;ALTER TABLE "painting_technic_translations" DISABLE TRIGGER ALL;ALTER TABLE "painting_prices" DISABLE TRIGGER ALL;ALTER TABLE "provider_divisions" DISABLE TRIGGER ALL;ALTER TABLE "provider_profile_translations" DISABLE TRIGGER ALL;ALTER TABLE "additional_information_option_t$anslations" DISABLE TRIGGER ALL;ALTER TABLE "additional_information_type_services" DISABLE TRIGGER ALL;ALTER TABLE "additional_information_type_translations" DISABLE TRIGGER ALL;ALTER TABLE "painting_types" DISABLE TRIGGER ALL;ALTER TABLE "period_translations" DISABLE TR$GGER ALL;ALTER TABLE "simple_captcha_data" DISABLE TRIGGER ALL;ALTER TABLE "temp_provider_profiles" DISABLE TRIGGER ALL;ALTER TABLE "paintings" DISABLE TRIGGER ALL;ALTER TABLE "schema_migrations" DISABLE TRIGGER ALL;ALTER TABLE "provider_service_intervention_level_provid$
ds" DISABLE TRIGGER ALL;ALTER TABLE "painting_categories" DISABLE TRIGGER ALL;ALTER TABLE "images" DISABLE TRIGGER ALL;ALTER TABLE "page_part_translations" DISABLE TRIGGER ALL;ALTER TABLE "intervention_levels_provided" DISABLE TRIGGER ALL;ALTER TABLE "regions" DISABLE TR$
GGER ALL;ALTER TABLE "services_provided" DISABLE TRIGGER ALL;ALTER TABLE "service_translations" DISABLE TRIGGER ALL;ALTER TABLE "services" DISABLE TRIGGER ALL;ALTER TABLE "service_formulas" DISABLE TRIGGER ALL;ALTER TABLE "messages" DISABLE TRIGGER ALL;ALTER TABLE "provi$
er_service_additional_information_options" DISABLE TRIGGER ALL;ALTER TABLE "provider_service_medium_provideds" DISABLE TRIGGER ALL;ALTER TABLE "provider_service_service_provideds" DISABLE TRIGGER ALL;ALTER TABLE "provider_service_territory_provideds" DISABLE TRIGGER ALL;$
LTER TABLE "provider_profiles" DISABLE TRIGGER ALL;ALTER TABLE "additional_information_options" DISABLE TRIGGER ALL;ALTER TABLE "admin_users" DISABLE TRIGGER ALL;ALTER TABLE "city_translations" DISABLE TRIGGER ALL;ALTER TABLE "periods" DISABLE TRIGGER ALL;ALTER TABLE "te$
ritories_provided" DISABLE TRIGGER ALL;ALTER TABLE "temp_provider_services" DISABLE TRIGGER ALL;ALTER TABLE "collector_profiles" DISABLE TRIGGER ALL;ALTER TABLE "notifications" DISABLE TRIGGER ALL;ALTER TABLE "page_parts" DISABLE TRIGGER ALL;ALTER TABLE "page_services" D$SABLE TRIGGER ALL;ALTER TABLE "measure_unit_translations" DISABLE TRIGGER ALL;ALTER TABLE "formulas" DISABLE TRIGGER ALL;ALTER TABLE "measure_units" DISABLE TRIGGER ALL;ALTER TABLE "media_provided" DISABLE TRIGGER ALL;ALTER TABLE "coupon_periods" DISABLE TRIGGER ALL;ALTE$ TABLE "coupons" DISABLE TRIGGER ALL;ALTER TABLE "currencies" DISABLE TRIGGER ALL;ALTER TABLE "artists" DISABLE TRIGGER ALL;ALTER TABLE "cities" DISABLE TRIGGER ALL;ALTER TABLE "countries" DISABLE TRIGGER ALL;ALTER TABLE "country_translations" DISABLE TRIGGER ALL;ALTER T$BLE "users" DISABLE TRIGGER ALL;ALTER TABLE "additional_information_types" DISABLE TRIGGER ALL
User Load (1234.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
Painting Load (0.7ms) SELECT "paintings".* FROM "paintings"
[]
Painting Load (0.4ms) SELECT "paintings".* FROM "paintings" WHERE "paintings"."id" = $1 LIMIT 1 [["id", "1"]]
(1293.0ms) TRUNCATE TABLE "active_admin_comments", "provider_services", "painting_provenances", "painting_technics", "painting_type_translations", "painting_category_translations", "page_translations", "orders", "pages", "painting_technic_translations", "region_trans$ations", "provider_profile_translations", "additional_information_option_translations", "painting_prices", "provider_divisions", "additional_information_type_services", "additional_information_type_translations", "painting_types", "period_translations", "paintings", "sim$le_captcha_data", "temp_provider_profiles", "provider_service_intervention_level_provideds", "painting_categories", "images", "page_part_translations", "intervention_levels_provided", "regions", "services_provided", "services", "service_formulas", "service_translations", "messages", "provider_service_additional_information_options", "provider_service_medium_provideds", "provider_service_service_provideds", "provider_service_territory_provideds", "provider_profiles", "city_translations", "periods", "additional_information_options", "admin$users", "territories_provided", "temp_provider_services", "collector_profiles", "notifications", "page_parts", "page_services", "measure_unit_translations", "formulas", "measure_units", "media_provided", "coupon_periods", "coupons", "currencies", "cities", "countries", "$ountry_translations", "users", "additional_information_types", "artists" RESTART IDENTITY CASCADE;
(1.6ms) ALTER TABLE "active_admin_comments" ENABLE TRIGGER ALL;ALTER TABLE "provider_services" ENABLE TRIGGER ALL;ALTER TABLE "painting_category_translations" ENABLE TRIGGER ALL;ALTER TABLE "page_translations" ENABLE TRIGGER ALL;ALTER TABLE "painting_provenances" ENA$LE TRIGGER ALL;ALTER TABLE "painting_technics" ENABLE TRIGGER ALL;ALTER TABLE "painting_type_translations" ENABLE TRIGGER ALL;ALTER TABLE "region_translations" ENABLE TRIGGER ALL;ALTER TABLE "orders" ENABLE TRIGGER ALL;ALTER TABLE "pages" ENABLE TRIGGER ALL;ALTER TABLE "$ainting_technic_translations" ENABLE TRIGGER ALL;ALTER TABLE "painting_prices" ENABLE TRIGGER ALL;ALTER TABLE "provider_divisions" ENABLE TRIGGER ALL;ALTER TABLE "provider_profile_translations" ENABLE TRIGGER ALL;ALTER TABLE "additional_information_option_translations" E$ABLE TRIGGER ALL;ALTER TABLE "additional_information_type_services" ENABLE TRIGGER ALL;ALTER TABLE "additional_information_type_translations" ENABLE TRIGGER ALL;ALTER TABLE "painting_types" ENABLE TRIGGER ALL;ALTER TABLE "period_translations" ENABLE TRIGGER ALL;ALTER TAB$E "simple_captcha_data" ENABLE TRIGGER ALL;ALTER TABLE "temp_provider_profiles" ENABLE TRIGGER ALL;ALTER TABLE "paintings" ENABLE TRIGGER ALL;ALTER TABLE "schema_migrations" ENABLE TRIGGER ALL;ALTER TABLE "provider_service_intervention_level_provideds" ENABLE TRIGGER ALL$
ALTER TABLE "painting_categories" ENABLE TRIGGER ALL;ALTER TABLE "images" ENABLE TRIGGER ALL;ALTER TABLE "page_part_translations" ENABLE TRIGGER ALL;ALTER TABLE "intervention_levels_provided" ENABLE TRIGGER ALL;ALTER TABLE "regions" ENABLE TRIGGER ALL;ALTER TABLE "servic$
s_provided" ENABLE TRIGGER ALL;ALTER TABLE "service_translations" ENABLE TRIGGER ALL;ALTER TABLE "services" ENABLE TRIGGER ALL;ALTER TABLE "service_formulas" ENABLE TRIGGER ALL;ALTER TABLE "messages" ENABLE TRIGGER ALL;ALTER TABLE "provider_service_additional_information$
options" ENABLE TRIGGER ALL;ALTER TABLE "provider_service_medium_provideds" ENABLE TRIGGER ALL;ALTER TABLE "provider_service_service_provideds" ENABLE TRIGGER ALL;ALTER TABLE "provider_service_territory_provideds" ENABLE TRIGGER ALL;ALTER TABLE "provider_profiles" ENABLE
TRIGGER ALL;ALTER TABLE "additional_information_options" ENABLE TRIGGER ALL;ALTER TABLE "admin_users" ENABLE TRIGGER ALL;ALTER TABLE "city_translations" ENABLE TRIGGER ALL;ALTER TABLE "periods" ENABLE TRIGGER ALL;ALTER TABLE "territories_provided" ENABLE TRIGGER ALL;ALTE$
TABLE "temp_provider_services" ENABLE TRIGGER ALL;ALTER TABLE "collector_profiles" ENABLE TRIGGER ALL;ALTER TABLE "notifications" ENABLE TRIGGER ALL;ALTER TABLE "page_parts" ENABLE TRIGGER ALL;ALTER TABLE "page_services" ENABLE TRIGGER ALL;ALTER TABLE "measure_unit_tran$
lations" ENABLE TRIGGER ALL;ALTER TABLE "formulas" ENABLE TRIGGER ALL;ALTER TABLE "measure_units" ENABLE TRIGGER ALL;ALTER TABLE "media_provided" ENABLE TRIGGER ALL;ALTER TABLE "coupon_periods" ENABLE TRIGGER ALL;ALTER TABLE "coupons" ENABLE TRIGGER ALL;ALTER TABLE "curr$
ncies" ENABLE TRIGGER ALL;ALTER TABLE "artists" ENABLE TRIGGER ALL;ALTER TABLE "cities" ENABLE TRIGGER ALL;ALTER TABLE "countries" ENABLE TRIGGER ALL;ALTER TABLE "country_translations" ENABLE TRIGGER ALL;ALTER TABLE "users" ENABLE TRIGGER ALL;ALTER TABLE "additional_info$
mation_types" ENABLE TRIGGER ALL
您可以看到,在两个puts
之间,它会DISABLE TRIGGER ALL
。显然,我的代码中没有任何内容可以做到这一点。
当我在expect(page).to have_content("Votre commande a bien été éffectuée")
之后添加Compléter la commande
时。它有效。
我认为capybara-webkit存在问题。它似乎在时间之前清理数据库。
你有想法解决它吗?
答案 0 :(得分:0)
除非你使用机架测试驱动程序,否则capybara调用通常是异步的 - 它不知道点击产生的处理何时完成。只要在spec块中执行代码完成,它就会使用数据库清理程序来清理表。
通常你没有注意到这一点,因为水豚探测器方法(由have_css
,have_content
,click_link
等使用的方法)将在一段有限的时间内重试时间。您对电子邮件递送的检查并不知道如何执行此操作。
这个最简单的修复是你已经找到的:使用其中一个知道如何等待引入同步点的capybara方法。