草庐IT

the_mock

全部标签

ruby-on-rails - RSpec::Mocks::ExampleMethods 的未定义方法 instance_double

我有一个这样的测试用例:describeWorkCardsControllerdoit"something"dowork_card=instance_double(WorkCard,{:started?=>true})#somemorecodeendend当我运行RSpec时,出现错误:undefinedmethod'instance_double'for#根据http://rubydoc.info/github/rspec/rspec-mocks/RSpec/Mocks/ExampleMethods这种方法存在。所以我尝试通过以下方式直接访问它:describeWorkCardsCo

ruby-on-rails - 使用 minitest 在 mock 上多次调用相同的方法

我使用的是带有Ruby1.9.3的minitest版本如何使用它测试模拟的多次调用?我需要类似的东西mockObject.expect.times(2):method,[return_1firsttime,return_2secondtime]mockObject.verify有什么办法可以实现吗? 最佳答案 您需要调用expect每次调用该方法。mockObject.expect:method,return_1,[first,time,args]mockObject.expect:method,return_2,[second,t

Ruby Guard 问题 - 'Please install the sqlite3 adapter' - railstutorial.org

我正在关注RubyonRailsTutorial并且在测试部分变得有些困惑,特别是-3.6.2-AutomatedtestswithGuard按照部署到Heroku的教程说明,我已切换到Postgresql并从我的gemfile中删除了sqlite3,并进行了捆绑安装以进行更新。但是,一旦我运行bundleexecguard我收到消息:/Users/username/.rvm/gems/ruby-1.9.3-p125@global/gems/bundler-1.1.3/lib/bundler/rubygems_integration.rb:147:inblockinreplace_ge

Ruby:Titleize:如何忽略较小的词,如 'and' 、 'the' 、 'or 等

deftitleize(string)string.split("").map{|word|word.capitalize}.join("")end这会标题化每个单词,但我如何捕捉某些我不想大写的单词?即)jack和吉尔请不要使用正则表达式。更新:我在使这段代码工作时遇到了问题:我让它打印了一个全部大写的单词数组,但并非没有下面的列表。words_no_cap=["and","or","the","over","to","the","a","but"]deftitleize(string)cap_word=string.split("").map{|word|word.capitali

ruby-on-rails - 为什么我得到 "including Capybara::DSL in the global scope is not recommended!"

每次我运行规范,即使规范通过,例如$rspecspec/integration/view_homepage_spec.rbincludingCapybara::DSLintheglobalscopeisnotrecommended!.Finishedin0.6174seconds1example,0failuresRandomizedwithseed14130$我的Gemfile有:group:test,:developmentdogem'rspec-rails'gem'capybara'end我的spec_helper有:ENV["RAILS_ENV"]||='test'requir

ruby - 什么在 Ruby : defining the alias method or using alias_method? 中运行得更快

什么在以后调用时更快:deffirst_method?()second_method?()end或alias_method:firstmethod,:second_method如果可能的话,为什么?(注意:我不问什么更好/更好等等->这里只有原始速度以及为什么它更快很有趣) 最佳答案 至少在Ruby1.8.6中,别名似乎更快:#!/usr/local/bin/rubyrequire'benchmark'$global_bool=trueclassObjectdeffirst_method?$global_boolenddefseco

ruby-on-rails - rails : modify form parameters before modifying the database

我正在开发一个通过表单发送数据的Rails应用程序。我想在表单发送之后,但在它被处理之前修改表单的一些“参数”。我现在拥有的{"commit"=>"Create","authenticity_token"=>"0000000000000000000000000""page"=>{"body"=>"TEST","link_attributes"=>[{"action"=>"Foo"},{"action"=>"Bar"},{"action"=>"Test"},{"action"=>"Blah"}]}}我想要什么{"commit"=>"Create","authenticity_token"

ruby-on-rails - 为什么我会收到此 Passenger 错误 Could not find rake-0.9.2.2 in any of the sources?

我刚刚创建了一个新的空Rails应用程序,它几乎是空的。我创建它只是为了找出问题所在,但我收到了以下错误。我正在使用Rails3.1.0和Ruby1.9.2Errormessage:Couldnotfindrake-0.9.2.2inanyofthesources(Bundler::GemNotFound)Exceptionclass:PhusionPassenger::UnknownError所以我将rake-0.9.2.2添加到Gemfile并运行bundle,但我仍然收到相同的错误消息。我不知道问题出在哪里,我什至尝试打开Rails日志文件,但里面什么也没有。我尝试了很多次以不同

ruby - 为什么 `"在 Ruby 中不重复"* 3` the same as ` 3 * "repeat"`?

当我输入这个时:puts'repeat'*3我得到:>>repeatrepeatrepeat但是如果我这样做是行不通的:puts3*'repeat'为什么? 最佳答案 在Ruby中,当你调用a*b时,您实际上是在调用一个名为*的方法在a.试试这个,例如:a=5=>5b=6=>6a.*(b)=>30c="hello"=>"hello"c.*(a)=>"hellohellohellohellohello"因此*工作正常,因为*String上的方法了解如何处理整数。它通过将自身的多个副本连接在一起来做出响应。但是当你做3*"repeat"

ruby-on-rails - Ruby on Rails : allow the user to enter a new information, 或单击下拉菜单选择现有信息

这里是新的ROR程序员。我正在尝试构建一个Web应用程序,该应用程序允许用户填写表单,他们在其中输入公司信息,然后通过单击提交,将输入添加到数据库中。目前,如果用户要创建一个新条目,他们会看到几个字段,例如“公司名称”。有一个空白框供他们输入新公司,旁边有一个下拉菜单,用户可以使用该菜单查看数据库中的现有公司。"SelectaCompany")%>我正在寻找一种允许用户输入新公司的方法,或者单击下拉菜单并选择现有公司。目前:如果未在文本框中输入任何内容且未从下拉列表中选择任何选项,则将其保存为空白。如果输入了一些内容,但没有选择任何选项,它将被保存为空白。但是,如果输入内容并从下拉列表