jjzjj

unit-conversion

全部标签

ruby-on-rails - 如何扩展 Ruby Test::Unit 断言以包含 assert_false?

显然在Test::Unit中没有assert_false。您将如何通过扩展断言并添加文件config/initializers/assertions_helper.rb来添加它?这是最好的方法吗?我不想修改test/unit/assertions.rb。顺便说一句,我不认为这是多余的。我使用的是assert_equalfalse,something_to_evaluate。这种方法的问题是很容易意外使用assertfalse,something_to_evaluate。这将始终失败,不会引发错误或警告,并且会在测试中引入错误。 最佳答案

ruby-on-rails - 脚本/服务器 custom_require.rb :36:in `require' : cannot load such file -- test/unit/error (LoadError)

我有一个基于1.8.7构建的应用程序,我正尝试在1.9.3的系统上启动它当我运行脚本/服务器时,我得到:/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require':cannotloadsuchfile--test/unit/error(LoadError)from/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require'我的服务器脚本如下所示:#!/usr/bin/envrubyrequireFile.expand_path('../.

ruby - 杰基尔服务错误 : no implicit conversion of nil into String

我用这个错误搜索了jekyll。jekyll处理页面时似乎出现了ruby​​错误,但我根本不了解ruby​​。杰基尔版本1.3.1我什至重新安装了ruby​​和jekyll,但结果没有改变。更新:在我将jekyll从1.31降级到1.20后,这个错误消失了注意:我的网站是用jekyll1.20创建的,所以它不能用1.3.1构建?这是核心问题吗?E:\GitHub\sample>jekyll服务--trace:Configurationfile:E:/GitHub/sample/_config.ymlSource:E:/GitHub/sampleDestination:E:/GitHub

ruby - gem 更新——系统返回 "no implicit conversion of nil into String"

运行gemupdate--system不断返回错误#gemupdate--systemUpdatingrubygems-updateERROR:Whileexecutinggem...(TypeError)noimplicitconversionofnilintoString如何解决?详细:http://pastebin.com/2uBYEMTi 最佳答案 这可能是由于不兼容的gem版本(也许是一个正在做Monkey补丁的gem?)。您可以尝试更新单个gem吗? 关于ruby-gem更新

ruby-on-rails - ruby rails : Unit Testing non activerecord models and still load fixtures

我可能遗漏了一些东西,但我陷入了这种情况:我有一个非activerecord模型,我想对其进行测试。我从Test::Unit::TestCase派生了它的测试用例类。但是,模型的测试用例类在其自身内部使用了其他activerecord模型类,我想为它们加载固定装置。我的问题是fixtures类方法仅在我从ActiveSupport::TestCase继承测试用例类时才可用(它在ActiveRecord::TestFixtures包含在ActiveSupport::TestCase中)。任何帮助,因为运行测试都会给我错误:未定义的方法“fixtures”(这是可以理解的),如果我从Act

ruby - 我如何获得 RSpec 的共享示例,例如 Ruby Test::Unit 中的行为?

在RSpecforTest::Unittests中是否有类似于shared_examples的插件/扩展? 最佳答案 如果您正在使用rails(或只是active_support),请使用Concern.require'active_support/concern'moduleSharedTestsextendActiveSupport::Concernincludeddo#Thisway,testnamecanbeastring:)test'bananabananabanana'doasserttrueendendend如果您不使

ruby-on-rails - "No explicit conversion of Symbol into String"用于 rails 4.0.1 中的新记录(仅限)

在我的Rails4升级之后,尝试为我的任何ActiveRecord类创建一个新记录NoexplicitconversionofSymbolintoString例如,这里是我的链接的links_params方法deflink_paramsparams.require(:link).permit(:url_address,:group_id,:alt_text,:version_number,:position,:content_date,:verified_date)#Thisisline157end#line118is:@link=Link.new(link_params)但是我明白了

ruby - 在 Ruby 中,如何控制 Test::Unit 测试的运行顺序?

例如,当运行这些测试时,我想确保test_fizz总是先运行。require'test/unit'classFooTest更新:我为什么要这样做?我的想法是,某些测试(那些测试更简单、更基本的方法)的早期失败将使跟踪系统中的问题变得更容易。例如,bar的成功取决于fizz是否正常工作。如果fizz坏了,我想马上知道,因为没有必要担心bar,它也会失败,但输出要复杂得多测试结果。 最佳答案 您可以使用Test::Unit::TestCase#test_order=:defined定义测试顺序例子:gem'test-unit'#Iuse

ruby - 为什么 'undefined method ` assert_equal' ' is thrown even after requiring ' test/unit'

我打开irb并输入:require'test/unit'但是当我使用assert_equal方法时,出现以下错误:NoMethodError:undefinedmethod'assert_equal'formain:Object。为什么即使在需要“测试/单元”之后也会发生这种情况? 最佳答案 assert_equal是在Test::Unit::TestCase的子类上定义的,因此仅在该类中可用。您可能会成功地使用includeTest::Unit::TestCase将这些方法加载到当前范围。更有可能的是,您最好将测试写在一个短文件中

ruby - 类型错误 : no implicit conversion of Hash into String

尝试解析一些JSON,为什么text是空的?期望的输出:text应该返回Helloworld\n\nApple,Harbor\n\nBanana,Kitchen\n\nMango,Bedroomtext="Helloworld"json='{"fruits":[{"name":"Apple","location":"Harbor"},{"name":"Banana","location":"Kitchen"},{"name":"Mango","location":"Bedroom"}]}'fruits=JSON.parse(json)defformat_fruits(fruits)fr