草庐IT

mutation-testing

全部标签

ruby - Ruby Koans 的test_changing_hashes 中的bonus 问题的答案是什么?

在RubyKoans,about_hashes.rb部分包含以下代码和注释:deftest_changing_hasheshash={:one=>"uno",:two=>"dos"}hash[:one]="eins"expected={:one=>"eins",:two=>"dos"}assert_equaltrue,expected==hash#BonusQuestion:Whywas"expected"brokenoutintoavariable#ratherthanusedasaliteral?end我无法在评论中找到奖金问题的答案-我尝试实际进行他们建议的替换,结果是一样的。我

ruby Rspec : Testing instance variables without adding an accessor to source

我正在尝试测试以下方法:defunprocess_move(board,move)ifmove[0].instance_of?(Array)multi_move=@multi_move.pop(2).reversemulti_move.eachdo|single_move|unapply_move(board,single_move)endelseboard=unapply_move(board,move)endboardend我想为@multi_move设置状态,但我不想添加仅用于测试的访问器。有没有办法在没有访问器的情况下这样做?谢谢。 最佳答案

ruby-on-rails - rails 4 : How to reset test database?

我在使用Rails4并注意到我的一些RSpec测试失败了,因为我的一些测试重构使用了前置过滤器(大概是因为事务)。这篇文章描述了一个类似的问题:railstestdatabasenotclearingaftersomeruns代替使用DatabaseCleanergem,是否有清除测试数据库的rake命令?我相信rakedb:test:prepare在Rails4中被弃用了。此外,如果在交易之前,如`post:create,user:Fabricate.attributes_for(:user)`是持久性的,是否有另一种重构方式来避免手动清除测试数据库的需要?

ruby-on-rails - 如何在测试环境运行Rails控制台并加载test_helper.rb?

背景:我在使用Thoughtbot的“工厂女孩”gem时遇到了一些问题,该gem用于创建要在单元测试和其他测试中使用的对象。我想转到控制台并运行不同的FactoryGirl调用以检查发生了什么。例如,我想去那里做...>>Factory(:user).inspect我知道您可以在不同的环境中运行控制台...$脚本/控制台RAILS_ENV=test但是当我这样做时,工厂类不可用。看起来好像test_helper.rb没有加载。我尝试了各种require调用,包括一个带有到test_helper.rb的绝对路径的调用,但它们的失败与此类似:$script/consoleRAILS_ENV

ruby-on-rails - 什么是 rake db :test:prepare actually do?

我正在观看Rails教程视频,但我无法弄清楚db:test:prepare命令的实际作用。有人可以提供解释吗? 最佳答案 Therakedb:migrateaboverunsanypendingmigrationsonthedevelopmentenvironmentandupdatesdb/schema.rb.Therakedb:test:loadrecreatesthetestdatabasefromthecurrentdb/schema.rb.Onsubsequentattempts,itisagoodideatofirstr

javascript - 在 indexedDB 中检索数据时出现错误 "A mutation operation was attempted on a database that did not allow mutations."

我有这个简单的示例代码:varrequest=mozIndexedDB.open('MyTestDatabase');request.onsuccess=function(event){vardb=event.target.result;varrequest=db.setVersion('1.0');request.onsuccess=function(event){console.log("Successversion.");if(!db.objectStoreNames.contains('customers')){console.log("CreatingobjectStore"

javascript - 类型错误 : parsed is undefined on angularjs service unit test

我正在尝试对使用$http的服务进行单元测试。我正在使用Jasmine,但我一直收到此错误:TypeError:parsedisundefinedinangular.js(line13737)这是我的服务的样子:angular.module('myapp.services',[]).factory('inviteService',['$rootScope','$http',function($rootScope,$http){varinviteService={token:'',getInvite:function(callback,errorCallback){$http.get('

javascript - Node : Testing with sinon and async/await

使用sinon和async/await运行此测试时遇到问题。这是我正在做的一个例子://infilefuncsasyncfunctionfuncA(id){leturl=getRoute53()+idreturnawaitfuncB(url);}asyncfunctionfuncB(url){//emptyfunction}和测试:letfuncs=require('./funcs');...//describeletstubRoute53=null;letstubFuncB=null;letroute53='https://sample-route53.com/'letid='123

javascript - React-testing-library:因输入而改变

我正在尝试测试组件是否会因输入元素的更改而更新。我使用fireEvent.change()函数,如果我随后检查我使用getByPlaceholderText找到的节点的值,它已按预期更新。但是我看不到react组件本身的变化。这可能是因为更改直到重新渲染才会发生;我将如何测试这个?react-testing-library的rerender似乎“从头开始”启动组件(即没有新的输入值),并且waitForElement永远找不到它在等待什么。这是组件TestForm.js:importReactfrom'react';import{withState}from'recompose';co

javascript - 简单的 Angular Testing 失败($injector :unpr Unknown Provider) when I have no dependencies

我得到thiserror。这与我的注入(inject)器无法解决所需的依赖关系有关,但即使我对Angular了解有限,我也很确定这段代码不应该依赖于任何模块。此代码在浏览器中运行良好,但它似乎不想在我的测试中运行。我一直在关注文档中的examples我的Angular版本是1.2.13(编辑:现在使用1.12.15)。这是我的代码:varapp=angular.module('app',[]).controller('GreetingCtrl',function($scope){$scope.title="HelloWorld!";$scope.message="Test,test.O