草庐IT

test_method

全部标签

ruby - 如何从 Test::Unit::TestCase 获取堆栈跟踪

我正在测试一些Ruby代码并且有一个失败的Test::Unit::TestCase。不幸的是,失败报告只给我最上面的错误,而不是完整的堆栈跟踪。具体来说,它说:1)Failure:test_tp_make(TestScripts::TestTpMake)[test/test_scripts.rb:73]:Exceptionraised:>.引用的行号(73)是我的测试用例中assert_nothing_raised代码块的开始,它又开始了另一个代码块,该代码块又调用了一个大型库。我已经尝试使用--verbose标志运行测试,不幸的是这不会改变异常输出。我尝试查阅Test::Unit文档

ruby-on-rails - Rails - 测试 fixture 错误 NoMethodError : undefined method `type' for nil:NilClass

我在运行使用具有模型之间关联的固定装置的测试时遇到问题。这是我一运行raketest就得到的错误:ERROR["test_truth",SevenPortfolioTest,0.005154775]test_truth#SevenPortfolioTest(0.01s)NoMethodError:NoMethodError:undefinedmethod`type'fornil:NilClassERROR["test_should_destroy_item_video",SevenPortfolio::ItemVideosControllerTest,0.008887804]test_

ruby - alias_method 和 class_methods 不混合?

我一直在尝试修补全局缓存模块,但我不明白为什么它不起作用。有人有什么建议吗?这是错误:NameError:undefinedmethod`get'formodule`Cache'from(irb):21:in`alias_method'...由此代码生成:moduleCachedefself.getputs"original"endendmoduleCachedefself.get_modifiedputs"Newget"endenddefpeek_a_booCache.module_evaldo#make:get_not_modifiedalias_method:get_not_mo

ruby - 在 Rack::Test 中使用 Cookie

我正在尝试使用Rack::Test为我的Sinatra应用程序编写RSpec测试。我不明白如何使用cookie。例如,如果我的应用程序设置了cookie(不是通过:session),我如何检查该cookie是否设置正确?另外,我如何使用该cookie发送请求? 最佳答案 Rack::Test保留一个cookiejar,该cookiejar在请求期间持续存在。您可以使用rack_mock_session.cookies访问它。假设您有这样的处理程序:get'/cookie/set'doresponse.set_cookie"foo",

ruby 公案 : test_nil_is_an_object

我最近尝试使用这个工具来提高我的Rails技能:http://github.com/edgecase/ruby_koans但我无法通过一些测试。此外,我不确定我是否正确地做了一些事情,因为目标只是通过测试,有很多方法可以通过它,我可能正在做一些不符合标准的事情。有没有办法确认我做的事情是否正确?具体例子:在about_nil中,deftest_nil_is_an_objectassert_equal__,nil.is_a?(Object),"UnlikeNULLinotherlanguages"end它是告诉我检查第二个子句是否等于一个对象(所以我可以说nil是一个对象)或者只是把as

ruby-on-rails - Rails 茧 gem : Undefined Method 'new_record?' on link_to_remove_association with Wicked

我一直在努力弄清楚一些代码。我有一个表格,我正在尝试使用Wicked和茧gem。一切正常,包括link_to_add_association功能。正如Cocoon所建议的那样,我正在为关联的表单字段呈现部分内容,并且除了link_to_remove_association函数之外,一切似乎都正常工作。它返回以下错误:nil:NilClass的未定义方法new_record?这是我抛出错误的部分:这是调用部分的View:location%>这是调用View的Controller操作:classUserStepsController如果有帮助,这里是cocoon中抛出错误的函数:defli

ruby-on-rails - Rails 的 ActiveRecord 序列化 :attr method gives "Missing Class or module error"

我试图在ActiveRecord模型中序列化一个简单的属性,而Rails2.3.4不喜欢它。classShopperserialize:tagsend>>a=Shopper.new=>>>a.tags=['aoeu','stnh']=>['aoeu','snth']>>a.save=>TypeError:classormodulerequired有人知道我错过了什么吗? 最佳答案 Arf...我以为我可以一次序列化两个属性,但事实并非如此:serialize:tags,:garments#thisiswrong第二个参数应该是序列化

ruby-on-rails - self.send(method, =, value) 不起作用

我正在尝试创建一个Ruby类,其中initialize方法接受选项的散列。然后,我将这些选项作为类的attr_accessor。现在,我可以做类似的事情classUserattr_accessor:name,:email,:phonedefinitialize(options)self.name=options[:name]self.email=options[:email]self.phone=options[:phone]endendUser.new(:name=>'SomeName',:email=>'some-name@some-company.com',:phone=>435

ruby-on-rails - class_methods 在关注中做了什么?

我正在阅读一些使用Rails4中关注点的代码。我看了一些文章说,如果我们想包含类方法使用模块ClassMethods,但我阅读的代码使用类似:class_methodsdodef****endend 最佳答案 ActiveSupport::Concern为模块混合的常见Ruby模式提供语法糖。当您使用modulesasmixins时你不能像在类中那样只使用self来声明类方法:moduleFoodefself.bar"HelloWorld"enddefinstance_method"HelloWorld"endendclassBaz

ruby - 试图理解 self.method_name 与 Classname.method_name 在 Ruby 中的使用

我试图了解何时使用self.method_name与何时使用Classname.method_name。在下面的示例中,为什么“before_create”需要引用“User.hash_password”而不是“self.hash_password”或只是“hash_password”?由于我们已经在User类中,我认为before_create方法会“知道”“hash_password”是它自己的类的成员,不需要任何特殊语法来引用它。require'digest/sha1'classUser["name=?andhashed_password=?",name,hashed_passw