草庐IT

build-all

全部标签

ruby-on-rails - 如果我调用 Factory.build 以使我的 Controller 测试快速,我怎样才能让 Factory Girl 永远不会访问数据库?

我正在寻求使我的Rails测试更快。我只有520个测试,但它们在bash中运行需要62秒,在Rubymine中运行需要82秒。作为典型Controller测试的示例,我使用此代码以@user身份登录并在CommentsController中为我的RSpecController测试创建基本的@comment:before(:each)do@user=Factory.create(:user)sign_in@user@comment=Factory.create(:comment)end您可能会意识到...这很慢。它构建了一个@user,但也为该用户构建了关联。@comment也是如此。所

ruby-on-rails - 哪里用 `FactoryGirl.build_stubbed` 哪里用RSpec的 `mock`/`double`

我很好奇人们在编写RSpec规范时倾向于在哪里使用FactoryGirl.build_stubbed以及他们在哪里使用double。也就是说,是否有最佳实践,例如“仅在相应的模型规范中使用FactoryGirl方法?”当您发现自己在spec/models/bar_spec.rb中使用FactoryGirl.create(:foo)时,是否有代码味道?如果您在spec/models/bar_spec.rb中使用FactoryGirl.build_stubbed(:foo),代码味道会不会变小?如果您在foos_controller_spec.rb中使用FactoryGirl.create

ruby - 为什么.all?在空数组上返回 true?

我想使用Ruby评估数组中的所有项,如果它们都通过条件测试则返回true。我可以使用例如array.all?{|值|值==2}所以:>array=[2,2]>array.all?{|value|value==2}=>true>array=[2,3]>array.all?{|value|value==2}=>false太棒了!但是,为什么一个空数组可以通过这个测试呢?>array=[]>array.all?{|value|value==2}=>true这不应该返回false吗?如果我需要它返回false,我应该如何修改方法? 最佳答案

ruby-on-rails - 在 RSpec 中,在 :all block 之前使用 let 变量

我的大部分测试中都有以下代码:describe'index'let(:company){FactoryGirl.create(:company)}let(:user){FactoryGirl.create(:user,company:company)}beforedosign_inuservisitproducts_pathend...end但我收到以下警告:WARNING:letdeclaration'user'accessedina'before(:all)'我的问题是,这样做的正确方法是什么?我找不到关于警告本身的太多信息。谢谢!编辑:我的目标是使用user变量,这样我就可以将它

ruby-on-rails - Rails 上的 build 和 new 有什么区别?

谁能告诉我Rails上的build和new命令有什么区别? 最佳答案 new用于特定模型的新实例:foo=Foo.newbuild用于在AR关联中创建一个新实例:bar=foo.build_bar#(has_oneorbelongs_to)或bar=foo.bars.build#(has\_many,habtmorhas_many:through)http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html更新根据@toklands的建议

ruby-on-rails - 安装调试器时出错 : Failed to build gem native extension with ruby-1. 9.3-p362

尝试为新项目运行bundle时,遇到以下错误:Installingdebugger(1.2.2)withnativeextensionsGem::Installer::ExtensionBuildError:ERROR:Failedtobuildgemnativeextension.C:/Ruby193/bin/ruby.exeextconf.rbcheckingforrb_method_entry_t.called_idinmethod.h...nocheckingforrb_control_frame_t.method_idinmethod.h...nocheckingforrb_

ruby - "find_all"和 "select"是一回事吗?

这两个语句给我相同的结果:[1,2,3,4].find_all{|x|x.even?}[1,2,3,4].select{|x|x.even?}find_all只是一个别名吗?有理由使用一个而不是另一个吗? 最佳答案 #find_all和#select非常相似;差异非常微妙。在大多数情况下,它们是等价的。这取决于实现它的类。Enumerable#find_all和Enumerable#select在同一代码上运行。Array和Range也是如此,因为它们使用Enumerable实现。在Hash的情况下,#select被重新定义为返回一

ruby-on-rails - 错误 : failed to build gem native extension when installing rails on mac mountian lion os

我最近更新到MountainLion并重新安装了Ruby,但是当我尝试运行测试Rails应用程序时,我收到一条错误消息,指出“我的系统当前未安装Rails”。我按照它说的做,输入sudogeminstallrails并得到:clearedfaster_requirecachesduetonewgeminstall...Successfullyinstalledrails-3.2.71geminstalledInstallingridocumentationforrails-3.2.7...InstallingRDocdocumentationforrails-3.2.7...但是当我检

ruby-on-rails - macOS, rails : "Failed to build gem native extension"

我无法尝试在我的Mac上安装Rails。我有OSX10.6.8,我已经确认我有Ruby,版本1.8.7我运行了sudogemupdate和sudogemupdate--system来获取最新版本的软件。但是,当我运行sudogeminstallrails时,出现了这个错误:ERROR:Errorinstallingrails:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/rubyextconf.rbmkmf.rbcan'tfindh

ruby-on-rails - rails : Postgres permission denied to create database on rake db:create:all

我正在尝试创建用于开发和测试的postgres数据库。我正在使用:OSX优胜美地Rails版本:4.2.0git版本:2.2.2psql版本:9.4.0ruby版本:2.1.0p0自制软件版本:0.9.5gem文件:gem'pg'数据库.yml:default:&defaultadapter:postgresqlencoding:unicodepool:5development:rakedb:create:all返回PG::InsufficientPrivilege:ERROR:permissiondeniedtocreatedatabase:CREATEDATABASE"myapp_