使用Flash事件系统或构建自己的观察者设计模式?(Use Flash Event System or build own Observer Design Pattern?)
在这本食谱中,有人提倡建立自己的观察者设计模式: http : //cookbooks.adobe.com/post_Using_Observer_Pattern_instead_of_Events-18232.html
性能真的更快吗?
In this cookbook someone advocates to build own Observer Design Pattern: http://cookbooks.adobe.com/post_Using_Observer_Pattern_instead_of_Events-18232.html
Is it really faster as for performance ?
原文:https://stackoverflow.com/questions/4490893
最满意答案
您的测试中有几个问题
第一个是在每个场景之前运行前块,并且当第二个场景运行时,创建的对象的id可能是2(除非先前的场景创建了更多的位置然后它会更高),等等。为了解决这个问题,你要解决这个问题。应该保存您正在创建的对象,然后使用其id生成要访问的路径
before do @place = create(:place, :reviewed) end
然后当你需要访问它
visit("/places/#{@place.id}/edit")
或使用路线助手
visit(edit_place_path(@place)) # preferred unless you're actually testing the text used for the url
第二个问题是,在访问新位置之前,您不是在等click_on完成它正在做的任何事情。 使用支持JS的驱动程序时,无法保证当这些操作返回时,浏览器点击/交互触发的操作已完成。 您需要在访问新位置之前检查指示操作已完成的可见更改,否则新访问可以在完成之前取消触发或处理的操作。
click_on('Update Place') page.must_have_content('Place Updated') #whatever message is displayed visit '/places'
You have a couple of issues in your tests
The first is that the before block is run before each scenario, and when the second scenario is run the id of the object created is probably 2 (unless the previous scenario created more places then it would be higher), etc. To solve this you should be saving the object you're creating and then using its id to generate the path to visit
before do @place = create(:place, :reviewed) end
then when you need to visit it
visit("/places/#{@place.id}/edit")
or using the route helpers
visit(edit_place_path(@place)) # preferred unless you're actually testing the text used for the url
The second issue is that you're not waiting for click_on to complete whatever it's doing before visiting a new location. When using JS capable drivers there is no guarantee that actions triggered by browser clicks/interactions have completed when those actions return. You need to check for visible changes that indicate the actions are complete before visiting a new location or the new visit can cancel the action triggered or get processed before it completes.
click_on('Update Place') page.must_have_content('Place Updated') #whatever message is displayed visit '/places'
相关问答
更多-
Capybara的HTTP基本认证(HTTP basic auth for Capybara)[2023-08-20]
我使用page.driver.basic_authorize(name, password)来代替它 更新 : 目前,在水豚升级之后,我正在使用这一堆解决方法: if page.driver.respond_to?(:basic_auth) page.driver.basic_auth(name, password) elsif page.driver.respond_to?(:basic_authorize) page.driver.basic_authorize(name, password) ... -
我不是100%清楚你正在尝试做什么,或者为什么,但从错误信息中听起来你正试图测试页面的
元素? have_content需要在当前作用域中查找可见文本字符串,它不需要哈希。 如果您正在尝试测试页面标题,则应使用have_title expect(page).to have_title("mugenseikatsu") I'm not 100% clear on exactly what you're trying to do, or why, but from the error messag ... -
更新:这个问题的根源是WEBrick的monkeypatch。 它命名不佳,位于一个不寻常的位置,作者不再在团队中。 一个很好的提醒,应该不惜一切代价避免使用monkeypatches。 原始答案: 我一直在与乔丹(OP)就此问题进行合作。 虽然我们没有找到根本原因,但我们发现没有回溯的EOFError来自哪里。 以下代码可以在Ruby的标准库中找到: Net::BufferedIO#rbuf_fill https://github.com/ruby/ruby/blob/v2_4_3/lib/net/pro ...
-
黄瓜水豚是如何工作的(cucumber capybara how does it work)[2022-03-03]
虽然我真的不知道这是如何工作的最深的细节。 但我足够为您提供一些观点。 Cucumber是一个红宝石验收测试框架,它可以让你用纯英文编写验收。 现在总体上它位于Webrat或Capybara之上,它提供了它的真实能力,即模拟浏览器或自动浏览器测试。 Capybara或Webrat可以轻松运行验收测试.Capybara使用各种驱动程序进行验收测试变得非常简单。 司机,如硒,速度或机架测试。 在香草案例中,机架测试用于模拟浏览器测试。 Rack-Test本身只负责创建用于运行测试的会话,步骤定义等由capyba ... -
我认为问题来自这条线 Capybara.run_server = false 如果您正在运行基于机架的测试,则需要此功能。 删除它并重新运行测试。 如果您正在运行基于Web的测试,您可能希望将其保留在那里 - 并且仅仅因为您使用Selenium并不意味着您正在运行Web基础测试。 您仍然在浏览器中运行基于机架的测试。 I think the problems comes from this line Capybara.run_server = false You will need this if yo ...
-
使用execute_script / evaluate_script与测试中的页面进行交互并不能模拟真实的用户交互,并且在很多情况下可以使您的测试毫无意义。 这样做的主要原因是它允许您执行用户从未做过的事情(更改隐藏/只读/禁用字段的值等)。 它也不会生成用户与元素交互生成的相同事件,因此页面中的JS可能不会以相同的方式做出反应。 execute_script确实在编写测试中占有一席之地,但它有限,通常是为了获取值(而不是更改内容)或解决浏览器/驱动程序中的问题(一旦你完全理解了你正在尝试解决的问题并确定它 ...
-
您的测试中有几个问题 第一个是在每个场景之前运行前块,并且当第二个场景运行时,创建的对象的id可能是2(除非先前的场景创建了更多的位置然后它会更高),等等。为了解决这个问题,你要解决这个问题。应该保存您正在创建的对象,然后使用其id生成要访问的路径 before do @place = create(:place, :reviewed) end 然后当你需要访问它 visit("/places/#{@place.id}/edit") 或使用路线助手 visit(edit_place_path(@p ...
-
Capybara NoMethodError(Capybara NoMethodError)[2021-11-24]
不确定是什么原因,但在进行了更多研究以解决spec / features / require 'spec_helper'这个问题之后,我需要将require 'spec_helper'更改为require 'rails_helper' 。 Not sure what the reasoning is, but after doing more research to fix this issue in spec/features/static_pages_spec.rb I needed to change ... -
您无法在一次测试中结合使用#get和#page,并期望事情正常工作,因为它们都有自己的请求和页面内容。 水豚(使用支持JS功能的驱动程序时)会尝试通过运行浏览器并控制它向应用程序发出请求来模拟用户。 然后Capybara在浏览器中查询文档。 您不会(大多数水豚司机)可以访问响应代码,模板呈现等内容,因为用户通常不会看到它们,而Capybara(再次)的目的是模拟用户。 #另一方面,通过直接调用应用程序的快捷方式。 您可以使用Capybara.string在使用#get获得的响应内容上使用Capybara提供 ...
-
Capybara rack_test驱动程序忽略主机名,因此您无法使用它来测试子域行为,您需要使用其中一个利用/模仿完整浏览器的驱动程序运行这些测试(selenium,poltergeist,capybara-webkit )。 另外,你想使用have_current_path matcher而不是eq与`current_url'来编写和url / path检查 expect(page).not_to have_current_path(/random-subdomain/, url: true) The ...