我正在尝试构建一个通过POST发送JSON(或XML)的rspec测试。但是,我似乎无法真正让它工作:json={....data....}.to_jsonpost'/model1.json',json,{'CONTENT_TYPE'=>'application/json'}还有这个json={....data....}.to_jsonpost'/model1.json',json,{'Content-Type'=>'application/json'}有什么想法吗?谢谢! 最佳答案 在Rails3中,您可以跳过header和@re
我想测试我的User模型关联has_many:projects,dependent::destroy现在已经走了这么远:it"destroysdependentprojects"douser=FactoryGirl.build(:user)project=FactoryGirl.build(:project)user.projects但这给出了一个错误:Failure/Error:expect(Project.count).tochange(-1)ArgumentError:`change`requireseitheranobjectandmessage(`change(obj,:ms
我不知道我做错了什么,但每次我尝试测试重定向时,我都会收到此错误:“@requestmustbeanActionDispatch::Request”context"asnon-signedinuser"doit"shouldredirecttotheloginpage"doexpect{visitadmin_account_url(account,host:get_host(account))}.toredirect_to(signin_path)endend1)AdminAccountPagesAdmin::Accounts#showasnon-signedinusershouldr
因此,我尝试在Rails项目的上下文中学习rspecBDD测试框架。我遇到的问题是,在我的一生中,我无法在rspec描述中正确加载我的固定装置。免责声明:是的,有比固定装置更好的东西可以使用。在我开始使用相关工具(如factory-girl、mocha、auto-test等)之前,我试图一次学习一件事,在这里(特别是rspec)。因此,我试图让死的简单,如果笨重,固定装置工作。无论如何,这是代码:/test/fixtures/users.yml-#password:"secret"foo:username:fooemail:foo@example.compassword_hash:34
我有一堆RSpecRake任务定义了我希望在运行整套测试时按特定顺序运行。我试过这样的:task:run_in_order=>[:one,:two,:three]doputs"Runsuiteoftests"end它运行第一个测试然后停止并且不运行其余任务。因此,如果使用Rake语法,它就不起作用。有没有办法记录RSpecRake任务的任务依赖性? 最佳答案 检查这个http://blog.davidchelimsky.net/2012/01/04/rspec-28-is-released/–orderrandWeaddedan--
我正在将rubyonrails项目的一部分移植到gem中。我已经使用bundlegem创建了新的gem目录。对于lib和spec目录,gem的项目布局如下所示:|-lib||-mylib|||-MYCLASS.rb|||-version.rb||||-mylib.rb||-spec|-spec_helper.rb|-mylib|-test_MYCLASS.rbspec/spec_helper.rb的内容:require"mylib"RSpec.configuredo|config|endmylib.gemspec的相关部分,由bundlegem命令生成:spec.files=`gi
这是我一段时间以来第一次开始一个新的Rails项目。在构建模型时,Rspec创建以“RSpec”为谓词的描述blockRSpec.describeMyModeldo...end与旧风格对比:describeMyModeldo...end我已经仔细阅读了变更日志,但一定是遗漏了变更的理由? 最佳答案 从RSpec3开始,您可以通过限制domainspecificlanguage(dsl)来禁用describe的全局可用性。.以RSpec.describe为前缀确保测试在实现限制后仍将运行。注意:您仍然不需要前缀,除非您使用config
我是测试和Rails的新手,但我正努力让我的TDD流程正常运行。我想知道您是否使用任何类型的范例来测试has_many:through关系?(或者我想一般来说只是has_many)。例如,我发现在我的模型规范中,我肯定会编写简单的测试来检查关系两端的相关方法。即:require'spec_helper'describePostdobefore(:each)do@attr={:subject=>"f00PostSubject",:content=>"8arPostBodyContent"}enddescribe"validations"do...enddescribe"categoriz
在Rails3.2.9中,我有如下定义的自定义错误页面:#application.rbconfig.exceptions_app=self.routes#routes.rbmatch'/404'=>'errors#not_found'效果如预期。当我在development.rb中设置config.consider_all_requests_local=false时,我在访问/foo时得到了not_foundView/p>但是我该如何使用Rspec+Capybara来测试呢?我已经试过了:#/spec/features/not_found_spec.rbrequire'spec_hel
假设我有一个带有redirect_to_baz方法的FoosController。classFoosController我正在使用spec/controllers/foos_controller_spec.rb对此进行测试:require'spec_helper'describeFoosController,:type=>:controllerdodescribe"GETredirect_to_baz"doit"redirectstoexample.comwithparams"doget:redirect_to_bazexpect(response).toredirect_to"htt