首页 \ 问答 \ 使用Flash事件系统或构建自己的观察者设计模式?(Use Flash Event System or build own Observer Design Pattern?)

使用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
更新时间:2023-05-18 18:05

最满意答案

您的测试中有几个问题

第一个是在每个场景之前运行前块,并且当第二个场景运行时,创建的对象的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'

相关问答

更多
  • 我使用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 ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/capybaratchromeyxgncsseoferrorgb_149" target="_blank">使用Capybara和无头Chrome运行功能测试时的EOFError [关闭](EOFError when running feature tests with Capybara and headless Chrome [closed])</a><i>[2023-09-05] </i></h2> </div> <div class="tw_li_cont"> 更新:这个问题的根源是WEBrick的monkeypatch。 它命名不佳,位于一个不寻常的位置,作者不再在团队中。 一个很好的提醒,应该不惜一切代价避免使用monkeypatches。 原始答案: 我一直在与乔丹(OP)就此问题进行合作。 虽然我们没有找到根本原因,但我们发现没有回溯的EOFError来自哪里。 以下代码可以在Ruby的标准库中找到: Net::BufferedIO#rbuf_fill https://github.com/ruby/ruby/blob/v2_4_3/lib/net/pro ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/huangguashuitungongzuo_180" target="_blank">黄瓜水豚是如何工作的(cucumber capybara how does it work)</a><i>[2022-03-03] </i></h2> </div> <div class="tw_li_cont"> 虽然我真的不知道这是如何工作的最深的细节。 但我足够为您提供一些观点。 Cucumber是一个红宝石验收测试框架,它可以让你用纯英文编写验收。 现在总体上它位于Webrat或Capybara之上,它提供了它的真实能力,即模拟浏览器或自动浏览器测试。 Capybara或Webrat可以轻松运行验收测试.Capybara使用各种驱动程序进行验收测试变得非常简单。 司机,如硒,速度或机架测试。 在香草案例中,机架测试用于模拟浏览器测试。 Rack-Test本身只负责创建用于运行测试的会话,步骤定义等由capyba ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/chaoshishuitunhongbaoshicuowu_198" target="_blank">获得超时::水豚和红宝石的错误(Getting Timeout::Error in capybara and ruby)</a><i>[2023-11-23] </i></h2> </div> <div class="tw_li_cont"> 我认为问题来自这条线 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 ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/capybaraceshizhongshijquery_329" target="_blank">在Capybara测试中使用jQuery(Using jQuery in Capybara tests)</a><i>[2023-05-17] </i></h2> </div> <div class="tw_li_cont"> 使用execute_script / evaluate_script与测试中的页面进行交互并不能模拟真实的用户交互,并且在很多情况下可以使您的测试毫无意义。 这样做的主要原因是它允许您执行用户从未做过的事情(更改隐藏/只读/禁用字段的值等)。 它也不会生成用户与元素交互生成的相同事件,因此页面中的JS可能不会以相同的方式做出反应。 execute_script确实在编写测试中占有一席之地,但它有限,通常是为了获取值(而不是更改内容)或解决浏览器/驱动程序中的问题(一旦你完全理解了你正在尝试解决的问题并确定它 ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/stcsqryplfscw_427" target="_blank">在水豚测试期间以任意频率发生错误(Error occurring in arbitrary frequency during Capybara tests)</a><i>[2022-07-22] </i></h2> </div> <div class="tw_li_cont"> 您的测试中有几个问题 第一个是在每个场景之前运行前块,并且当第二个场景运行时,创建的对象的id可能是2(除非先前的场景创建了更多的位置然后它会更高),等等。为了解决这个问题,你要解决这个问题。应该保存您正在创建的对象,然后使用其id生成要访问的路径 before do @place = create(:place, :reviewed) end 然后当你需要访问它 visit("/places/#{@place.id}/edit") 或使用路线助手 visit(edit_place_path(@p ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/capybaranomethoderror_430" target="_blank">Capybara NoMethodError(Capybara NoMethodError)</a><i>[2021-11-24] </i></h2> </div> <div class="tw_li_cont"> 不确定是什么原因,但在进行了更多研究以解决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 ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/capybaraminitestyufa_525" target="_blank">结合Capybara和Minitest语法(combining Capybara and Minitest syntax)</a><i>[2024-02-08] </i></h2> </div> <div class="tw_li_cont"> 您无法在一次测试中结合使用#get和#page,并期望事情正常工作,因为它们都有自己的请求和页面内容。 水豚(使用支持JS功能的驱动程序时)会尝试通过运行浏览器并控制它向应用程序发出请求来模拟用户。 然后Capybara在浏览器中查询文档。 您不会(大多数水豚司机)可以访问响应代码,模板呈现等内容,因为用户通常不会看到它们,而Capybara(再次)的目的是模拟用户。 #另一方面,通过直接调用应用程序的快捷方式。 您可以使用Capybara.string在使用#get获得的响应内容上使用Capybara提供 ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/capybarainfiniteredirecterror_530" target="_blank">Capybara InfiniteRedirectError(Capybara InfiniteRedirectError)</a><i>[2023-03-31] </i></h2> </div> <div class="tw_li_cont"> 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 ... </div> </div> </li> </ul> </div> <div class="main_right"> <div class="search-out"> <div class="search"> <form action="/wenda" target="_blank" method="get"> <input type="search" autocorrect="off" autocomplete="off" placeholder="请输入关键词" id="q" name="q" value=""> <button class="btn_s" type="submit">搜索</button> </form> </div> </div> <div class="commonh"> <h2>相关文章</h2> <span class="fr"><a href="/jiaocheng" target="_blank">更多</a></span> </div> <div class="right_list"> <li> <a title="初学设计模式【2】观察者模式——Observer" href="/article/cxsjms2gczmsObserver_3" target="_blank">初学设计模式【2】观察者模式——Observer</a> </li> <li> <a title="zoj 2966 Build The Electric System" href="/article/zoj2966BuildTheElectricSystem_3" target="_blank">zoj 2966 Build The Electric System</a> </li> <li> <a title="flash问题" href="/article/flashwenti_5" target="_blank">flash问题</a> </li> <li> <a title="JAVA设计模式学习19——观察者模式" href="/article/JAVAsjmsxx19gczms_0" target="_blank">JAVA设计模式学习19——观察者模式</a> </li> <li> <a title="What Is Software Design? 先放上来有空看看~" href="/article/WhatIsSoftwareDesignxfslykkk_3" target="_blank">What Is Software Design? 先放上来有空看看~</a> </li> <li> <a title="redhat6.4上build storm 0.9.0.1" href="/article/redhat64shangbuildstorm0901_3" target="_blank">redhat6.4上build storm 0.9.0.1</a> </li> <li> <a title="【转载】Netflix: System Architectures for Personalization and Recommendation" href="/article/zzNetflixSystemArchitecturesforP_3" target="_blank">【转载】Netflix: System Architectures for Personalization and Recommendation</a> </li> <li> <a title="storm事件管理器EventManager源码分析-event.clj" href="/article/stormsjglqEventManagerymfxeventclj_3" target="_blank">storm事件管理器EventManager源码分析-event.clj</a> </li> <li> <a title="HDFS Append 设计文档的QA(Questions about the “Append Design”)" href="/article/HDFSAppendsjwddQAQuestionsabouttheAppendDesign_0" target="_blank">HDFS Append 设计文档的QA(Questions about the “Append Design”)</a> </li> <li> <a title="菜鸟求如何修改别人写好的swf flash文件?" href="/article/cnqrhxgbrxhdswfflashwj_4" target="_blank">菜鸟求如何修改别人写好的swf flash文件?</a> </li> </div> <div class="commonh"> <h2>最新问答</h2> <span class="fr"><a href="/wenda" target="_blank">更多</a></span> </div> <div class="right_list"> <li> <a title="sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)" href="/wenda/sp_updatestatsdzsqlserver2005zwf_476" target="_blank">sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)</a> </li> <li> <a title="如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)" href="/wenda/cjcxyxfwjhclilsymysqlshell_445" target="_blank">如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)</a> </li> <li> <a title="AESGCM解密失败的MAC(AESGCM decryption failing with MAC)" href="/wenda/aesgcmjiemishibaimac_544" target="_blank">AESGCM解密失败的MAC(AESGCM decryption failing with MAC)</a> </li> <li> <a title="Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)" href="/wenda/zurbfoundationqiantaowanggeduiqi_221" target="_blank">Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)</a> </li> <li> <a title="湖北京山哪里有修平板计算机的" href="/wenda/hubeijingshanxiupingbanjisuanji_10" target="_blank">湖北京山哪里有修平板计算机的</a> </li> <li> <a title="SimplePie问题(SimplePie Problem)" href="/wenda/simplepie_476" target="_blank">SimplePie问题(SimplePie Problem)</a> </li> <li> <a title="在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)" href="/wenda/zhongshangxiawen_512" target="_blank">在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)</a> </li> <li> <a title="HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)" href="/wenda/htmljavascriptczmlqywjjfw_124" target="_blank">HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)</a> </li> <li> <a title="为什么我会收到链接错误?(Why do I get a linker error?)" href="/wenda/wohuishoudaolianjiecuowu_187" target="_blank">为什么我会收到链接错误?(Why do I get a linker error?)</a> </li> <li> <a title="如何正确定义析构函数(How to properly define destructor)" href="/wenda/zhengquedingyixigouhanshu_360" target="_blank">如何正确定义析构函数(How to properly define destructor)</a> </li> <li> <a title="垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)" href="/wenda/chuizhiqiehuancaidandakaijifuji_367" target="_blank">垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)</a> </li> <li> <a title="类型不匹配 - JavaScript(Type mismatch - JavaScript)" href="/wenda/leixingpipeijavascript_119" target="_blank">类型不匹配 - JavaScript(Type mismatch - JavaScript)</a> </li> <li> <a title="为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)" href="/wenda/dwmxcdjwnetmvckzqczsgxzsyt_456" target="_blank">为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)</a> </li> <li> <a title="在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)" href="/wenda/xmstatsmodelsslqblm_294" target="_blank">在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)</a> </li> <li> <a title="如何开启mysql计划事件" href="/wenda/kaiqimysqljihuashijian_74" target="_blank">如何开启mysql计划事件</a> </li> <li> <a title="检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)" href="/wenda/jcszzhdyzdsyrjavascript_216" target="_blank">检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)</a> </li> <li> <a title="使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)" href="/wenda/opengleshuizhilunkuo_546" target="_blank">使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)</a> </li> <li> <a title="java日历格式(java Calendar format)" href="/wenda/javariligeshi_355" target="_blank">java日历格式(java Calendar format)</a> </li> <li> <a title="Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)" href="/wenda/pythonpandaspandasnumpyzhdasksjk_403" target="_blank">Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)</a> </li> <li> <a title="如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)" href="/wenda/ssfjelasticsearchsyzwdnr_160" target="_blank">如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)</a> </li> <li> <a title="LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)" href="/wenda/linqentitieszuochaxun_396" target="_blank">LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)</a> </li> <li> <a title="从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)" href="/wenda/extjs41sdzscjlshcfsj_326" target="_blank">从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)</a> </li> <li> <a title="运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])" href="/wenda/yxjavascriptjqwyjtgb_456" target="_blank">运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])</a> </li> <li> <a title="如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)" href="/wenda/glassfishdywzdzgz_117" target="_blank">如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)</a> </li> <li> <a title="如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)" href="/wenda/hqexeyycxczhttpqq_387" target="_blank">如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)</a> </li> <li> <a title="嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)" href="/wenda/handroidzdbjpdpzyc_92" target="_blank">嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)</a> </li> <li> <a title="Assimp详细说明typedef(Assimp elaborated type refers to typedef)" href="/wenda/assimpxiangxitypedef_151" target="_blank">Assimp详细说明typedef(Assimp elaborated type refers to typedef)</a> </li> <li> <a title="初始化继承类中不同对象的列表(initialize list of different objects in inherited class)" href="/wenda/cshjclztdlb_222" target="_blank">初始化继承类中不同对象的列表(initialize list of different objects in inherited class)</a> </li> <li> <a title="使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)" href="/wenda/jqueryajaxgridviewxzbxjpf_325" target="_blank">使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)</a> </li> <li> <a title="Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)" href="/wenda/geoxml3groundoverlayzindex_331" target="_blank">Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)</a> </li> </div> </div> </div> </div> <div style="clear:both;"></div> <div class="footer"> <div class="mainbox"> <div class="info"> <p>Copyright ©2023 <a href="https://www.peixunduo.com" target="_blank">peixunduo.com</a> All Rights Reserved.<a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备14003112号</a> </p> <p>本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!</p> </div> </div> </div> <script type="text/javascript" src="/resources/js/common.js?v=324"></script> <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https'){ bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else{ bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?9eebaceb5e4371a0aad59712a1a1ecff"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>