我正在尝试使用Rspec进行测试。当我运行时$rspecmytest_spec.rb由于我得到以下错误/home/bastien/.merbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in`require':cannotloadsuchfile--rails_helper(LoadError)我已经尝试了很多东西,如果我跑了,不知何故rspecspec或bundleexecrspec从我的.rspec文件所在的文件夹中,我没有收到任何错误。我创建了一个应用程序只是为了测试这个问题(我创
我正在学习教程http://apionrails.icalialabs.com/book/chapter_three但是当我运行Controller测试时bundleexecrspecspec/controllers我得到了未定义的方法错误:Failures:Api::V1::UsersControllerGET#showFailure/Error:it{shouldrespond_with200}NoMethodError:undefinedmethod`respond_with'for##./spec/controllers/api/v1/users_controller_spec
运行时:rakespec:models一切正常,但当我这样做的时候rspecspec/models/spot_spec.rb有Spot.stub!:test1,我得到:undefinedmethod`stub!'forSpot:Class错误仅在我包含该stub时发生!行。有什么办法可以避免吗?我只想运行特定型号的规范。更新:使用Ruby1.9.2和RSpec2.4.0,这里是spot_spec.rb代码:requireFile.expand_path(File.dirname(__FILE__)+'/../spec_helper')describeSpotdobefore(:all)
我听说最好避免在RSpec中使用its,let,let!,specify,before,和subject。关于let,let!和before,如果不使用它们,我该如何执行设置任务? 最佳答案 编写这些最佳实践的人实际上只想说“不要使用RSpec”。避免使用核心功能并仍然认为你可以把事情做好是很疯狂的。你能链接到这些最佳实践吗?我很想阅读它们,看看它们是否合理,或者只是一些j-random-guy的意见。避免before和let?什么?真的吗?避免specify,我想,这只是it的旧语法。避免特定的subject电话?我想,如果您的代
我无法理解为什么在运行我的测试时,以下代码在rspec中不起作用。Lead.update_status(2,2,true)expect(Lead).toreceive(:update_status).with(2,2,true)我也试过Lead.update_status(2,2,true)expect_any_instance_of(Lead).toreceive(:update_status).with(2,2,true)我得到的错误是().update_status(2,2,true)expected:1timewitharguments:(2,2,true)received:0
我正在使用Rspec和Capybara编写集成测试。我注意到,在测试activerecord选项的创建时,我经常必须执行相同的代码。例如:it"shouldcreateanewinstance"do#Icreateaninstancehereendit"shoulddosomethingbasedonanewinstance"do#Icreateaninstancehere#Iclickintotherecordandaddasubrecord,orsomethingelseend问题似乎是ActiveRecord对象不会在测试中保持不变,但默认情况下,Capybara在规范中维护相同
我的代码只需要在特定版本的ActiveRecord上运行(解决旧AR库上的错误的方法)。此代码测试ActiveRecord::VERSION常量的值以查看它是否需要运行。有没有办法在rspec中模拟这些常量,这样我就可以测试该代码路径,而无需在测试机器上安装正确的ActiveRecordgem? 最佳答案 我最终编写了一个辅助方法来让我在执行代码块时覆盖常量:defwith_constants(constants,&block)constants.eachdo|constant,val|Object.const_set(consta
我使用rspec-guard连续运行我的测试,但有时测试失败是因为:Running:spec/requests/signup_spec.rbFFFailures:1)SignupdoesnotemailconfirmationmailaftersignupFailure/Error:visitnew_user_pathNameError:undefinedlocalvariableormethod`new_user_path'for##./spec/requests/signup_spec.rb:4:in`block(2levels)in'2)Signupshouldemailconf
我遇到了一个奇怪的问题。我以前从未使用过Devisegem。所以,我尝试编写简单的RSpec测试:require'spec_helper'describe"Admins"dobefore(:each)do@email="test@test.ru"user=FactoryGirl.create(:user,:email=>@email)enddescribe"signin/out"dodescribe"success"doit"shouldsignauserinandout"dovisitnew_user_session_pathendendendend我收到这样的错误:1)Admins
我从Webrat迁移到Capybara,现在我遇到了很多错误。例如在webrat中我可以在集成测试中使用它:response.shouldbe_success但是Capybara表明:Failure/Error:response.shouldbe_successNoMethodError:undefinedmethod`success?'fornil:NilClass有没有提供这种功能的方法?UPD:我的规范:require'spec_helper'describe"Admins"dobefore(:each)do@admin=FactoryGirl.create(:admin)vis