草庐IT

constant_time_test

全部标签

ruby-on-rails - 之前(:each) for all tests except one

这是我的spec_helper.rb的一部分:RSpec.configuredo|config|config.before(:each)dologin(email,password)visitroot_urlendend我在所有(20多个)测试中都需要,除了一个。有没有办法避免单一测试执行beforehook? 最佳答案 您可以将元数据添加到不需要登录的测试中,然后在您的beforeHook中评估该元数据。例如,同一个文件中的两个测试。一个需要登录,一个不需要。#foo_spec.rbdescribeFoododescribe"#b

ruby-on-rails - 为什么要测试:units and test:functionals insist on running in development environment?

我正在尝试测试一些特定于环境的设置(特定于中间件,但这似乎无关紧要),但我无法让测试在正确的环境中运行。症状:如果我运行rubytest/unit/my_test.rb,一切都很好,因为它做的第一件事是需要test/test_helper.rb,这会设置环境"test"然后加载Rails环境。如果我运行raketest,第一批(功能)运行良好,但第二批(单元)失败。失败是ENV['RAILS_ENV]以某种方式在批处理之间未设置,然后config/environment.rb看到没有设置并使用默认值"development“。环境在config/environment.rb的开头和该文

ruby 公案 : Constants become symbols

在about_symbols.rbRubyKoan(https://github.com/edgecase/ruby_koans)中,我有以下代码:RubyConstant="Whatisthesoundofonehandclapping?"deftest_constants_become_symbolsall_symbols=Symbol.all_symbolsassert_equaltrue,all_symbols.include?(:"nonexistent")assert_equaltrue,all_symbols.include?(:"Whatisthesoundofoneh

ruby - gemspec 文件中的 `files` 、 `executables` 、 `test_files` 和 `require_paths` 是什么?

我不清楚.gemspec文件中的某些规范在做什么。具体来说,spec.files=`gitls-files-z`.split("\x0")spec.executables=spec.files.grep(%r{^bin/}){|f|File.basename(f)}spec.test_files=spec.files.grep(%r{^(test|spec|features)/})spec.require_paths=["lib"]谁能解释一下这些与RubyGem的功能有何关系以及为什么需要它们? 最佳答案 executables:

从 float 转换的 Ruby Time 对象不等于原始 Time 对象

time=Time.nowfvalue=time.to_freturntime==Time.at(fvalue)这里有人可以解释为什么上面的表达式返回false吗?如何从与原始时间变量匹配的float创建新的时间对象?谢谢 最佳答案 IEEE754double(由to_f返回)不够准确,无法表示确切时间。t1=Time.nowf1=t1.to_ft2=Time.at(f1)#theylookthesamet1.inspect#=>'2013-09-0923:46:08+0200't2.inspect#=>'2013-09-0923:

ruby-on-rails - rails 2 : test 'link_to' and other view helpers from the rails console?

在Rails2中,我经常使用控制台,并且想知道使用它测试View助手(例如“link_to”或“url_for”)的最佳方法是什么。执行此操作的最佳方法是什么? 最佳答案 您可以将您的includeActionView::Helpers::UrlHelper添加到~/.irbrc以在您启动控制台时自动加载它。 关于ruby-on-rails-rails2:test'link_to'andotherviewhelpersfromtherailsconsole?,我们在StackOverfl

ruby-on-rails - 与 Ruby 中的 Time.now.advance() 相反

http://api.rubyonrails.org/classes/Time.html#method-i-advance记录一个方法advance()添加到当前时间。是否有相反的'go_back()方法? 最佳答案 我认为没有,但没有什么可以阻止您在advance中使用负值。Time.now.advance(:days=>-1,:hours=>-1) 关于ruby-on-rails-与Ruby中的Time.now.advance()相反,我们在StackOverflow上找到一个类似的

ruby-on-rails - rails : How to test if an attribute of a class object is required in the model policy?

简单地说,我有一个模型用户,其中包含名称、电子邮件和评论作为属性。validates_presence_of:namevalidates_presence_of:email所以“姓名”和“电子邮件”是必需的,但不是“评论”。my_user=User.new我想找到一种方法来测试像my_user.name.required?或User.name.required?类似的东西。我的目标是创建一个表单,并根据该项目是否设置为“validates_presence_of”,将特定类动态添加到表单项目span或td我试图搜索它,但没有找到任何相关信息。有没有简单的方法可以做到这一点?谢谢

ruby - 有没有办法表达 'infinite time' ?

我正在使用Range表示时间范围的类。现在我想要一个表示给定时间后任意点的范围。我试过(DateTime.now..nil),但是Range类不允许不同类的对象是同一范围的端点。(尝试使用此属性创建Range会导致ArgumentError:badvalueforrange。)是否有时间的无穷大等价物,即Time.now+(1.0/0.0)?或者,是否有办法绕过Range类要求其min和max值属于同一类的要求? 最佳答案 可以使用DateTime::Infinity类:future=DateTime.now..DateTime::

ruby-on-rails - Ruby/Rails 神秘的 "undefined constant"问题

我有一个Rails项目,其中一个常量在处理请求时在某个时刻被破坏。我正在使用mime/types和restclientgem。restclient模块定义了MIME的扩展,其中包含type_for_extension方法。moduleRestClient...defstringify_headersheadersresult[key]=target_values.map{|ext|MIME::Types.type_for_extension(ext.to_s.strip)}.join(',')...endendendmoduleMIMEclassTypesdeftype_for_ext