草庐IT

dyld_stub_binder

全部标签

Ruby 与法拉第 stub ,无法让它工作

对不起标题,我太沮丧了,现在想不出更好的东西。我有一个类,Judge,它有一个方法#stats。此stats方法应该向api发送GET请求并获取一些数据作为响应。我正在尝试对此进行测试并stub统计方法,以便我不执行实际请求。这是我的测试的样子:describeJudgedodescribe'.stats'docontext'whensuccess'dosubject{Judge.stats}it'returnsstats'doallow(Faraday).toreceive(:get).and_return('somedata')expect(subject.status).toeq

ruby-on-rails - 使用摩卡,有没有办法用很多参数 stub ?

假设我有这门课classFoodefbar(param1=nil,param2=nil,param3=nil):bar1ifparam1:bar2ifparam2:bar3ifparam3endend我可以使用stubwholebar方法:Foo.any_instance.expects(:bar).at_least_once.returns(false)但是,如果我只想在bar方法的param1为真时stub,我找不到办法:我也看了with,和has_entry,好像只适用于单个参数。我期待这样的功能。Foo.any_instance.expects(:bar).with('true

ruby - 在 RSpec 中 stub RestClient 响应

我有以下规范...describe"successfulPOSTon/user/create"doit"shouldredirecttodashboard"dopost'/user/create',{:name=>"dave",:email=>"dave@dave.com",:password=>"another_pass"}last_response.shouldbe_redirectfollow_redirect!last_request.url.should=='http://example.org/dave/dashboard'endendSinatra应用程序的post方法使

ruby-on-rails - Rspec 模拟, 'expect' 也可以 stub 方法作为副作用吗?

我正在尝试理解继承应用程序中的测试,我需要一些帮助。有很多像这样的规范组(查看规范):let(:job_post){FactoryGirl.create(:job_post)}#...beforedoexpect(view).toreceive(:job_post).at_least(:once).and_return(job_post)endit"shouldrenderwithouterror"dorenderend...job_post是在Controller上定义的辅助方法。(是的,他们可以使用@instance变量,而我正在重构它)。现在,在我看来,在beforeblock中

ruby-on-rails - 使用 Rspec stub 链式方法

我想调用一个只会返回一条记录的named_scope,但named_scope会返回一个数组,这没什么大不了的,因为我可以将它与.first链接起来:Model.named_scope(param).first这行得通,我正在努力解决的问题是如何对链接的调用进行stub。有没有人对我如何使用Rspec模拟实现这一点有引用或答案? 最佳答案 我想通了。Client.stub!(:named_scope).and_return(@clients=mock([Client]))@clients.stub!(:first).and_retu

ruby - 使用 Mocha 将对象作为参数传递给 stub 方法

Foo.expects(:bar)Foo.bar(:abc=>123,:xyz=>987)#assertFoo.barwascalledwithahashthathasakeyof:abc==123基本上,我想检查作为参数传递给stub方法的对象,以便检查该对象的值。在我的情况下,我不能使用Foo.expects(:bar).with({:abc=>123})因为我知道对象不会彼此相等。我只想比较参数的子值。当然这是可能的,我只是找不到这里的语法或策略。 最佳答案 我想通了!原来with可以占用一个block。Foo.expects

ruby - Rspec——需要 stub File.open 在另一个文件中被调用

在我的测试中,我使用一些参数初始化了一个名为Package的新类。在这个类的初始化中,我打开了一个文件,该文件在我的远程机器上可用,但在本地通常不存在。我想知道如何在我的测试中stub该方法。我正在使用rspec和mocha。我试过类似的东西:File.stubs(:open).with(:file).returns(File.open("#{package_root}/test_files/test.yml"))在我的测试中初始化Package之前,我有这一行。我遇到了这个错误:unexpectedinvocation:File.open('package/test_files/te

ruby - 大多数方法中的 "This is a stub, used for indexing"?

我正在研究cursesgem的curses.rb,我发现它无处不在:defattrset(attrs)#Thisisastub,usedforindexingend#bkgdset(ch)##Manipulatethebackgroundofthecurrentwindow#withcharacterInteger+ch+##seealsoCurses.bkgdsetdefbkgdset(ch)#Thisisastub,usedforindexingend#bkgd(ch)##Setthebackgroundofthecurrentwindow#andapplycharacterInt

ruby-on-rails - 如何在 Rails 中使用 Rspec stub 错误引发?

我是Rails和Rspec的新手,我正在使用Rspec来测试这个包含异常处理的Controller方法:defsearch_movies_director@current_movie=Movie.find(params[:id])begin@movies=Movie.find_movies_director(params[:id])rescueMovie::NoDirectorErrorflash[:warning]="#{@current_movie}hasnodirectorinfo"redirect_tomovies_pathendend我不知道如何正确测试上述路径:在无效搜索后

ruby - 仅在第一次调用 Rspec 时 stub 方法

我如何才能只在第一次调用时对方法进行stub,而在第二次调用中它应该按预期运行?我有以下方法:defmethoddo_stuffrescue=>MyExceptionsleeprandretryend我想在第一次调用do_stuff时引发MyException,但在第二次调用中,行为正常。我需要实现此目的以测试我的rescueblock,而不会出现无限循环。有什么办法可以实现吗? 最佳答案 您可以将block传递给将在调用stub时调用的stub。然后你可以在那里执行unstub,除了做任何你需要做的。classFoodefinit