草庐IT

python测试

全部标签

javascript - 在 Ruby 和 JavaScript 中测试 undefined variable ?

在JavaScript中,有一种有用的方法可以测试从未在任何给定点定义的变量。例如,如果尚undefinedvariablebob,则以下代码片段将返回true:typeof(bob)=='undefined'如何在Ruby中完成相同的测试?编辑:我正在寻找一个本质上同样紧凑的测试。我使用异常等提出了一些笨拙的近似值,但它们不是很漂亮! 最佳答案 defined?(variable_name)irb(main):004:0>defined?(foo)=>nilirb(main):005:0>foo=1=>1irb(main):006

ruby-on-rails - 如何测试依赖: :destroy with RSpec?

我想测试我的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

ruby-on-rails - 如何使用 Rspec 和 Capybara 测试重定向

我不知道我做错了什么,但每次我尝试测试重定向时,我都会收到此错误:“@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

使用Python Win32COM如何获取对图表数据表的引用?

使用PythonWin32COM如何获取对图表数据表的引用?我可以使用数据表创建图表(PowerPoint将其弹出在单独的窗口中),例如:importwin32comfromMSOimportconstantsasmsoconstApplication=win32com.client.Dispatch("PowerPoint.Application")Application.Visible=TruePresentation=Application.Presentations.Add()FirstSlide=Presentation.Slides.Add(1,12)...noproblemadd

python范围误差段循环

我正在尝试编写一个Python程序,该程序将采用任何小写字母并返回其中最长的字母顺序。以下是代码的一部分。s="abc"#samplestringanslist=[]#storesanswersshift=0#shiftssubstringexpan=0#expandssubstringwhilelen(s)>=1+shift+expan:#withinboundsofsifs[0+shift+expan]>s[1+shift+expan]:#ifnotalphabeticalshift+=1#movessubstringoverelse:#ifalphabeticalwhiles[0+shi

ruby-on-rails - 在 Ruby 单元测试中,如何断言一个字符串包含某个子字符串?

在Ruby单元测试中,如何断言字符串包含子字符串?像这样的东西:assert_containsstring_to_test,substring_to_verify 最佳答案 您可以使用assert_matchpattern,string,[message]如果string=~pattern为真:assert_matchsubstring_to_verify,string_to_test例如assert_match/foo/,"foobar"如果你经常使用它,为什么不写你自己的断言呢?require'test/unit'moduleT

ruby-on-rails - 测试时我应该在 Factory girl 中 stub 模型还是在规范文件中 stub ?

几乎我遇到的每一个规范文件我最终都会写这样的东西:before:eachdo@cimg=Factory.build:cimg_valid@cimg.stub(:validate_img).and_returntrue@cimg.stub(:validate_img_url).and_returntrue@cimg.stub(:save_images).and_returntrue@cimg.stub(:process_image).and_returntrue@cimg.stub(:img).and_returntrueend我的意思是,我从Factory.build获得的模型是完全有

ruby-on-rails - 一个 has_many :through Relationship 的 Rails RSpec 测试

我是测试和Rails的新手,但我正努力让我的TDD流程正常运行。我想知道您是否使用任何类型的范例来测试has_many:through关系?(或者我想一般来说只是has_many)。例如,我发现在我的模型规范中,我肯定会编写简单的测试来检查关系两端的相关方法。即:require'spec_helper'describePostdobefore(:each)do@attr={:subject=>"f00PostSubject",:content=>"8arPostBodyContent"}enddescribe"validations"do...enddescribe"categoriz

ruby-on-rails - 尝试在测试中运行 rails c 时获取 config.eager_load 设置为 nil

我正在尝试运行Rails(4.1.2)控制台railscRAILS_ENV=test我得到这个:>config.eager_loadissettonil.Pleaseupdateyour>config/environments/*.rbfilesaccordingly:>>*development-setittofalse*test-setittofalse(unless>youuseatoolthatpreloadsyourtestenvironment)*production->setittotrue>>/Users/xxxxxx/.rvm/gems/ruby-2.2.2/gems

ruby-on-rails - 使用 Rspec + Capybara 在 Rails 中测试错误页面

在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