草庐IT

ruby-on-rails - 使用 RSpec 测试 Redis 事务

我正在使用WATCH/MULTI/EXEC命令序列来完成Rails应用程序中的事务。我想详细说明应用程序在交易成功和交易失败时的行为(特别是在交易期间在另一个session中修改监视的key时)。具体来说,给出下面的(人为的)示例,我如何编写一个规范,在执行任意计算时始终修改Redis中的testval?deftest_watchREDIS.watch("testval")doval=REDIS.get('testval')val+=1000#arbitrarycomputationREDIS.multido|m|REDIS.set('testval',val)endendend

rspec - 当在一个 RSpec 套件中调用多个 with_api() 测试时,Goliath 会破坏 em-synchrony/em-hiredis

我在使用RSpec测试GoliathAPI时遇到了奇怪的行为。我的一项测试如下所示:require'helper'describeScales::Dispatchdoit"shouldreturna404ifresourcewasnotfound"dowith_api(Scales::Server)doget_request(:path=>'/')do|client|client.response_header.http_status.should==404endendendit"shouldreturnaresource"doScales::Storage::Sync.set"/ex

ruby-on-rails - 使用 Redis 和 Rails 的 Rspec 测试失败

我重构了我的Rails代码,将用户关系存储在Redis而不是Postgres数据库中。之前的代码:#user.rbhas_many:relationships,foreign_key:"follower_id",dependent::destroyhas_many:following,through::relationships,source::followeddeffollow!(other_user)relationships.create!(followed_id:other_user.id)end重构后的代码:#user.rbdeffollow!(other_user)rdb.

RSPEC 2.3 +设计1.0.11

我有一个非常旧的轨道2.3.18,Ruby1.9.3,RSPEC1.x应用程序,我们正在升级,并且其中有静止的认证。因此,我已经用设计1.0.11代替了。我可以登录到应用程序,但是我的测试不会运行;这是所讨论的测试require'spec_helper'describeCategoriesControllerdocontext"Asaloggedinuser"dobeforedologin_usercurrent_firm=mock_model(Firm,:id=>1)controller.stub!(:current_firm).and_return(current_firm)enddesc

ruby-on-rails - 如何处理 Rspec 中的 Mongoid::Errors::DocumentNotFound?

我有一个带有以下代码的ArticleController:defedit@article=current_user.articles.find(params[:id])end以及以下测试:describe"GET'edit'"doit"shouldfailwhensignedinandeditinganotheruserarticle"dosign_in@userget:edit,:id=>@another_user_article.idresponse.should_notbe_successendend但是,当我开始测试时,出现以下错误(这是正常的),但我想知道如何处理才能让我的测

ruby-on-rails - 运行测试时无法清除 Mongo DB

我正在使用rails、mongoid、spork、rspec。通过rspec运行测试时,我发现数据库中的记录数量在增加。purge!和database_cleaner都没有帮助。我的测试是:describeMyConvertordocontext'workingwithmymodel'before(:each)doFactoryGirl.create:my_modelend#examplesgohereendend我的规范助手是:Spork.each_rundoRSpec.configuredo|config|#...config.before(:each)doMongoid.purg

ruby-on-rails - 在 Presenter 规范中使用 ActionView::TestCase::Behavior 和 View 方法

使用Railscast示例,我为演示者编写了规范,其中包括ActionView::TestCase::Behavior并将view方法传递给演示者。spec/spec_helper.rb:...config.includeActionView::TestCase::Behavior,:example_group=>{:file_path=>%r{spec/presenters}}...spec/presenters/order_presenter_spec.rb:require'spec_helper'describeOrderPresenterdodescribe"#subtotal

ruby-on-rails - 使用 Rspec 和 Mongoid 5.0 on Rails 4 清理或重置测试数据库

当我运行我的rspec测试时,由于我的mongodb数据库中的数据过时,很多测试都失败了。据我所知,使用干净的数据库进行测试要好得多。如何在每次测试前清理和/或重新植入数据库? 最佳答案 您可以使用database_cleanergem来完成这个任务。来自他们的文档:RSpec.configuredo|config|config.use_transactional_fixtures=falseconfig.before(:suite)doDatabaseCleaner.clean_with(:truncation)endconfig

ruby-on-rails - 无法激活activemodel-3.2.15,因为activesupport-4.0.1冲突

尝试运行我的rspec测试(任何或所有)时出现此错误:Unabletoactivateactivemodel-3.2.15,becauseactivesupport-4.0.1conflictswithactivesupport(=3.2.15),builder-3.1.4conflictswithbuilder(~>3.0.0)我的Gemfile有:source'https://rubygems.org'rails_version='~>4.0.0.rc2'gem'activerecord',rails_versiongem'actionpack',rails_versiongem'

ruby - `require' : cannot load such file -- mongo (LoadError)

`require':无法加载这样的文件--mongo(LoadError)不确定为什么会收到此错误。我使用的所有其他gem都可以正常工作。我的rspec测试的顶部如下所示:require'rubygems'require'spec_helper.rb'require'base64'require'json'require'bigdecimal'require'mysql2'require'mongo''mongo'然而在irb中工作:irb=>require'mongo'true当我在脚本中使用它时,它也能正常工作。只是不在我的rspec测试中。我的文件结构如下:automation/