草庐IT

Test_stub

全部标签

ruby - 你如何在 Rspec 中模拟/ stub 反引号系统调用?

我有一个使用反引号的方法,但stub不适用于它。它正在拉取ls的结果:classTestHelperdefself.test_method`ls`endendrspec测试:describeTestHelperdodescribe'.test_method'dosubject{described_class.test_method}before{Kernel.stub(:`).and_return("test_dir")}it{expect(subject).toeql("test_dir")}endend 最佳答案 TestHel

ruby-on-rails - rails : How to insert a text_field without a form just to test the layout?

我现在正在为我的应用程序做布局,我想插入一个不执行任何操作的text.field,只是为了看看它的外观。我该怎么做? 最佳答案 有几种方法可以满足您的需求。1)只写静态HTML2)使用text_field_tag3)使用form_for为虚拟对象构建虚拟表单 关于ruby-on-rails-rails:Howtoinsertatext_fieldwithoutaformjusttotestthelayout?,我们在StackOverflow上找到一个类似的问题:

ruby - Rspec any_instance.stub 为 nil :NilClass exception 引发未定义的方法 `any_instance_recorder_for'

这是我正在测试的包含在Foo.rb中的类:classFoodefbarreturn2endend这是Foo_spec.rb中包含的我的测试:require"./Foo.rb"describe"Foo"dobefore(:all)doputs"#{Foo==nil}"Foo.any_instance.stub(:bar).and_return(1)endit"shouldpassthis"dof=Foo.newf.bar.shouldeq1endend我得到以下输出:falseFFailures:1)FooShouldpassthisFailure/Error:Foo.any_insta

ruby-on-rails - 请求规范中的 stub 身份验证

我正在寻找做this的方法但在要求规范。我需要登录和注销double或instance_double来设计而不是实际的ActiveModel/ActiveRecord。通过使用wiki页面中的代码:moduleRequestSpecHelpersdefsign_in(user=double('user'))ifuser.nil?allow(request.env['warden']).toreceive(:authenticate!).and_throw(:warden,{:scope=>:user})allow(controller).toreceive(:current_user)

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 - 我可以覆盖任务 :environment in test_helper. rb 来测试 rake 任务吗?

我在Rakefile中有一系列rake任务,我想将其作为我的规范等的一部分进行测试。每个任务都以以下形式定义:task:do_somthing=>:environmentdo#Dosomethingwiththedatabasehereend:environment任务设置ActiveRecord/DataMapper数据库连接和类。我没有将其用作Rails的一部分,但我有一系列测试,我喜欢将其作为BDD的一部分运行。此片段说明了我如何尝试测试rake任务。defsetup@rake=Rake::Application.newRake.application=@rakeloadFile

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 - capybara -webkit : automatically save a screenshot on an RSpec test failure

当使用带有Rspec的capybara-webkit测试失败时,如何自动保存html和屏幕截图?如何在RSpec测试失败时执行回调。奖励积分:如何避免出现以下错误:Capybara::Driver::Webkit::WebkitInvalidResponseError执行这段代码时:require'capybara/util/save_and_open_page'path="/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"png=Capybara.save_and_open_page_path+"#{path}.png"page.driver.re

Ruby Koans #75 test_constants_become_symbols,正确答案?

我的问题基于这个问题:RubyKoan:Constantsbecomesymbols.我有以下代码:in_ruby_version("mri")doRubyConstant="Whatisthesoundofonehandclapping?"deftest_constants_become_symbolsall_symbols=Symbol.all_symbolsassert_equal__,all_symbols.include?(__)endend正确答案应该是下面的吗?assert_equaltrue,all_symbols.include?("RubyConstant".to_

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方法使