草庐IT

live-unit-tests

全部标签

ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test

我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

ruby 单元测试 : run some code after each failed test

在Test::Unit中的ruby​​单元测试断言失败后,在执行teardown之前,是否有一些简洁优雅的方法来立即执行我的代码?我正在做一些自动化的GUI测试,并希望在出现问题后立即截图。 最佳答案 如果您使用的是1.9,请不要使用Test::Unit::TestCase作为您的基类。对其进行子类化并覆盖#run_test以进行救援,截取屏幕截图并重新提出:classMyAbstractTestCase或者,我认为这实际上是最简洁的方法,您可以使用before_teardownHook:classMyTestCase这不适用于1.

ruby-on-rails - 如何扩展 Ruby Test::Unit 断言以包含 assert_false?

显然在Test::Unit中没有assert_false。您将如何通过扩展断言并添加文件config/initializers/assertions_helper.rb来添加它?这是最好的方法吗?我不想修改test/unit/assertions.rb。顺便说一句,我不认为这是多余的。我使用的是assert_equalfalse,something_to_evaluate。这种方法的问题是很容易意外使用assertfalse,something_to_evaluate。这将始终失败,不会引发错误或警告,并且会在测试中引入错误。 最佳答案

ruby-on-rails - 脚本/服务器 custom_require.rb :36:in `require' : cannot load such file -- test/unit/error (LoadError)

我有一个基于1.8.7构建的应用程序,我正尝试在1.9.3的系统上启动它当我运行脚本/服务器时,我得到:/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require':cannotloadsuchfile--test/unit/error(LoadError)from/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require'我的服务器脚本如下所示:#!/usr/bin/envrubyrequireFile.expand_path('../.

ruby - 在 Rails 4 中写入流时如何使用 Rspec 和 ActionController::Live 进行测试?

我目前正在试验ActionController::Live,但我不知道如何正确地测试它。在我的Controller中,我写了这个response.stream.write("event:#{event}\n")response.stream.write("data:#{post.to_json}\n\n")但是当我在rspec测试中检查对象时,我看到了这个(rdb:1)response.stream.instance_variable_get(:@buf)["event:event\n"]当我将“数据”写入流时,我不明白为什么它没有出现在数组中。当我删除第一个response.stre

ruby-on-rails - 如何让 ActionController::Live streaming 与 Thin 一起工作?

问题你能用thin吗?与ActionController::Live实现服务器端事件(SSE)和长轮询?如果是,怎么办?上下文虽然标题是HowtogetRails4ActionController::LivestreamingworkingwithThinandRuby2?AndhowdoThinandPumascalewithlivestreaming?的重复,OP通过问两个问题混淆了水域,这个问题从未得到回答。许多其他帖子建议您可以使用thin对于服务器端事件(sse),如果您通过execthinstart--threaded启动它:DoesHerokusupportActionC

ruby-on-rails - rspec rails 测试 : how can I force ActiveJob job's to run inline for certain tests?

我希望我的后台作业能够内联运行某些标记测试。我可以通过用perform_enqueueddo包装测试来做到这一点,但我希望能够用元数据标记它们,如果可能的话,它会自动发生。我试过以下方法:it"doeseverythinginthejobtoo",perform_enqueued:truedoendconfig.around(:each)do|example|ifexample.metadata[:perform_enqueued]perform_enqueued_jobsdoexample.runendendend但它会导致错误:undefinedmethod`perform_enq

ruby-on-rails - Rails 5 升级 :/actionpack-5. 0.0/lib/action_controller/test_case.rb:49:in `initialize':参数数量错误(0 代表 2)(ArgumentError)

我最近正在进行Rails5升级,当我尝试启动Rails控制台时遇到了这个错误:/actionpack-5.0.0/lib/action_controller/test_case.rb:49:ininitialize':wrongnumberofarguments(0for2)(ArgumentError)当前bundleupdaterails已经完成了gem依赖项的解决,足以更新到5.0.0,rspec正在运行(尽管我正在修复很多中断)。我也可以运行railss没有错误。这里是代码中断行:https://github.com/rails/rails/blob/master/action

ruby-on-rails - ruby rails : Best way to test a failed call to a third party API

我现在调用第三方网络服务作为我的应用程序的一部分。我正在使用RestClientgem来执行此操作。有大量工具可以用来做同样的事情,所以这应该无关紧要。我很好奇的是有足够好的测试,没有什么太花哨的,我可以在其中模拟当第三方Web服务出于任何原因不可用时我的应用程序如何响应。无论是我超出了速率限制还是由于网络延迟/并发症而超时,我只想能够获取HTTP状态代码之类的东西并测试我的应用程序在该事件中执行的操作。使用Test::Unit执行此操作的最佳方法是什么?现在,对第三方服务的调用封装在我的一个Controller中。我有一个简单的模块,其中包含一些用于远程服务不同端点的包装器方法。我只

ruby - 我如何在不使用 ruby​​ 中的 sleep() 的情况下 rspec/test 一个 updated_at 字段?

如何在不使用sleep(1.second)方法的情况下编写规范?当我取消sleep时,我的测试会因为返回相同的时间戳而中断吗?我有以下类方法:defskipqs=find_or_create_by(user_id:user_id)qs.set_updated_atqs.n_skip+=1qs.save!end和以下规范:qs=skip(user.id)sleep(1.second)qs2=skip(user.id)qs.should_notbe_nilqs2.should_notbe_nil(qs.updated_at 最佳答案 我