草庐IT

hdr-Build_and_test_caching

全部标签

ruby-on-rails - rails : Testing named scopes with RSpec

我是测试Rails网络应用程序和RSpec的新手。我使用遗留代码并需要添加测试。那么使用RSpec测试查找器和命名范围的最佳方法是什么?我在Google中找到了一些方法,但它们并不理想。例如:http://paulsturgess.co.uk/articles/show/93-using-rspec-to-test-a-named_scope-in-ruby-on-railsit"excludesusersthatarenotactive"do@user=Factory(:user,:active=>false)User.active.should_notinclude(@user)e

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 - RSpec allow/expect 与 just expect/and_return

在RSpec中,特别是版本>=3,有什么区别:使用allow设置带有返回测试替身的参数的消息期望,然后使用expect对返回的测试替身进行断言只需使用expect设置带有参数的期望并返回测试替身还是只是语义?我知道用expect提供/指定返回值是thesyntaxinRSpecmocks2.13,但据我所知,thesyntaxchangedinRSpecmocks3使用允许。但是,在下面的(传递的)示例代码中,使用allow/expect或仅使用expect/and_return似乎产生相同的结果。如果一种语法比另一种语法更受欢迎,也许我会期望有某种弃用通知,但由于没有,这两种语法似乎

ruby - Rails 在最后一个之前加入逗号和 "and"的字符串列表

是否有一个标准的Rails助手可以将字符串数组(如["apple","banana","pear"])转换为"apple,banana,andpear"用于插入句子? 最佳答案 Yeahto_sentence应该工作得很好。http://apidock.com/rails/Array/to_sentence 关于ruby-Rails在最后一个之前加入逗号和"and"的字符串列表,我们在StackOverflow上找到一个类似的问题: https://stack

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 - 使用 'gem pq' 安装 PostgreSQL gem 失败并出现错误 : Failed to build gem native extension

我正在学习RubyonRails并尝试开发应用程序。在我的应用程序中,我试图在开发模式下使用默认的SQLite数据库,在生产模式下使用PostgreSQL。但是我在尝试使用安装pggem时遇到以下错误:geminstallpgBuilding native extensions.  This could take a while...ERROR:  Error installing pg:        ERROR: Failed to build gem native extension.     /home/tusharkhatiwada/.rvm/rubies/ruby-2.0.

ruby-on-rails - 如何解决弃用警告 "Method to_hash is deprecated and will be removed in Rails 5.1"

我正在尝试更新到Rails5,我收到以下弃用警告:DEPRECATIONWARNING:Methodto_hashisdeprecatedandwillberemovedinRails5.1,asActionController::Parametersnolongerinheritsfromhash.Usingthisdeprecatedbehaviorexposespotentialsecurityproblems.Ifyoucontinuetousethismethodyoumaybecreatingasecurityvulnerabilityinyourappthatcanbee

ruby - 什么是 :+ and &:+ in Ruby?

我已经看过好几次了,但我不知道如何使用它们。镐说这些是特殊的快捷方式,但我找不到语法描述。我在这种情况下见过他们:[1,2,3].inject(:+)例如计算总和。 最佳答案 让我们从一个更简单的例子开始。假设我们有一个我们想要大写的字符串数组:['foo','bar','blah'].map{|e|e.upcase}#=>['FOO','BAR','BLAH']此外,您还可以创建所谓的Proc对象(闭包):block=proc{|e|e.upcase}block.call("foo")#=>"FOO"您可以使用&语法将这样的过程传

ruby-on-rails - rails 验证 : :allow_nil and :inclusion both needed at the same time

通常“种类”字段应允许留空。但如果不为空,则该值应包含在['a','b']validates_inclusion_of:kind,:in=>['a','b'],:allow_nil=>true代码不起作用? 最佳答案 在Rails5中,您可以在包含block的外部或内部使用allow_blank:true:validates:kind,inclusion:{in:['a','b'],allow_blank:true}或validates:kind,inclusion:{in:['a','b']},allow_blank:true提示

ruby-on-rails - Rails 3.1 中的 Rails.cache 错误 - TypeError : can't dump hash with default proc

我在3.1.0.rc4(ruby1.9.2p180(2011-02-18修订版30909)[x86_64-darwin10])上遇到Rails.cache方法问题。该代码在2.3.12(ruby1.8.7(2011-02-18补丁级别334)[i686-linux],MBARI0x8770,RubyEnterpriseEdition2011.03)上的同一应用程序中运行良好,但在升级后开始返回错误。我还没弄明白为什么。当尝试缓存具有多个作用域的对象时似乎会发生错误。此外,无论有多少范围,使用lambda的任何范围都会失败。我曾因这些模式而失败:Rails.cache.fetch("ke