草庐IT

used_elements

全部标签

ruby-on-rails - RSpec 故事和规范 : When to use what?

所以我想开始使用RSpec故事,但我不确定编写Controller、模型和View规范的位置。例如,您有“登录”故事和“用户提供错误的密码”场景,难道您最终测试的不是与Controller/模型规范相同的东西(response.shouldrender...,user.shouldbe_nil等)所以我的问题是:对于那些习惯于使用RoR进行bdd(或故事dd)的人,您是否仍然编写模型/Controller规范?如果是这样,您遵循的工作流程如何(“第一个故事,然后缩小到特定规范”)? 最佳答案 如果您现在开始使用故事(而不是拥有大量遗

ruby-on-rails - Vagrant/VirtualBox VM 配置 : rbenv installs successfully but subsequent uses in script fail

我正在使用Vagrant+VirtualBox为我的Rails应用设置虚拟机。我正在清理Vagrantfile中引用的.sh配置脚本,如下所示:config.vm.provision"shell",path:"script/provision-script.sh"配置脚本做了很多事情,但最后它应该安装rbenvRuby版本控制,然后使用rbenv安装Ruby2.2.1。供应脚本的那部分看起来像这样:echo"settinguprbenv"#executetheremainingcommandsasvagrantuser,insteadofrootsudo-H-uvagrantbash-

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 - slim 的模板 : Is it possible to put two elements on the same line?

我经常想嵌套元素,比如下面的导航:ullia(href="#")linkNamelia(href="#")linkNamelia(href="#")linkName是否可以将li和a放在同一行?像li>a这样的语法会很好。 最佳答案 我相信你可以做这样的事情ulli:ahref="#"Link1li:ahref="#"Link2参见内嵌标签:http://rdoc.info/gems/slim/file/README.md#Inline_tags 关于ruby-on-rails-slim

ruby - 如何避免 RSpec 中的 "Useless use of == in void context"?

在RSpec中,如果我有警告并且有x.should==42another_line_of_code然后我得到一个关于的警告warning:uselessuseof==invoidcontext还有什么我可以做的吗关闭警告将其更改为bitbucket=(x.should==42) 最佳答案 使用:x.shouldeq(42)或者:x.shouldbe==42或者移动x.should==42使其成为itblock中的最后一行。对于那些思考但是为什么?的人我完全是Ruby的菜鸟,但这是我的理解:警告来自Ruby,因为像x.should==

ruby-on-rails - "use"Ruby/Rails/Rack 代码中的关键字/词

最近我在查看与goliath相关的一些代码时,偶然在Ruby代码中看到了这个词use。,中间件等。看起来它不同于include/extend,andrequire.有人可以解释为什么存在这个use关键字,以及它与include/require有何不同?它是如何工作的,何时使用它? 最佳答案 文档正如人们指出的那样,use不是Ruby关键字,它实际上是Rack::Builderclass的一个方法。:use(middleware,*args,&block)Specifiesmiddlewaretouseinastack.Thisdoc

ruby-on-rails - rails : Copying attributes from an object to another using the "attributes" method

让模型Quote具有属性[price,description]让模型Invoice有属性[price,description,priority]让invoice模型Invoice中的对象具有属性{price:10,description:'lamp',priority:10}invoice={price:10,description:'lamp',priority:10}假设我想将invoice属性复制到新的quote。quote=Quote.new(invoice.attributes)这会引发一个错误,即priority在模型Quote中不存在。如何将invoice属性复制到新的q

ruby-on-rails - "use this if it isn' t 空白的 Ruby 速记,否则使用那个“

我有以下代码:url=file.s3_url.blank??file.url:file.s3_url有没有更短的写法?谢谢! 最佳答案 在ActiveSupport中有一个抽象,Object#presence:url=file.s3_url.presence||file.url 关于ruby-on-rails-"usethisifitisn't空白的Ruby速记,否则使用那个“,我们在StackOverflow上找到一个类似的问题: https://stack

ruby-on-rails - Spring 警告 : You're using Rubygems 2. 0.3。至少升级到 Rubygems 2.1.0

我收到错误:警告:您正在将Rubygems2.0.3与Spring一起使用。尝试运行Rails控制台时至少升级到Rubygems2.1.0。我该如何更新它? 最佳答案 尝试运行gemupdate--system来更新Rubygems本身。 关于ruby-on-rails-Spring警告:You'reusingRubygems2.0.3。至少升级到Rubygems2.1.0,我们在StackOverflow上找到一个类似的问题: https://stackov

ruby-on-rails - Time.use_zone 未按预期工作

现在是旧金山太平洋标准时间下午2:54。出于某种原因,此代码块未返回夏威夷HST中午12:54。我在这里错过了什么吗?我希望此代码返回我在夏威夷的当前时间Time.use_zone('Hawaii')doTime.nowend#=>2012-01-0314:54:54-0800 最佳答案 这应该没问题:Time.use_zone('Hawaii')dopTime.zone.nowend 关于ruby-on-rails-Time.use_zone未按预期工作,我们在StackOverflo