如何从控制台访问 Rails 测试帮助程序代码?
使用普通的 ActiveSupport::TestCase,我添加了几个在 test/test_helper.rb 中生成测试模型对象的帮助器方法。此文件中重新打开了包含帮助器方法的 ActiveSupport::TestCase。
现在假设我在 Ruby 控制台(或 pry,加载了 Rails 环境),并且我想摆弄这些测试方法。我可以加载文件:加载“test/test_helper.rb”,但我无法创建一个 TestCase 实例来让我访问这些测试方法来使用它们:
[4] pry(main)> tc = ActiveSupport::TestCase.new
ArgumentError: wrong number of arguments (0 for 1)
[5] pry(main)> tc = ActiveSupport::TestCase.new(1)
TypeError: 1 is not a symbol
[6] pry(main)> tc = ActiveSupport::TestCase.new(:unit)
ArgumentError: uncaught throw :invalid_test
我徒劳地尝试跟踪源代码中的面包屑痕迹文件来查找 TestCase 初始化方法,这样我就可以弄清楚它在这里坚持的内容。
有人可以帮助我如何思考这样的问题并找出解决方法吗?
Using vanilla ActiveSupport::TestCase, I've added several helper methods that generate test model objects in test/test_helper.rb. In this file is a reopening of ActiveSupport::TestCase that contains the helper methods.
Now suppose I'm in the Ruby Console (or pry, with the Rails environment loaded), and I want to fiddle with these test methods. I can load the file: load "test/test_helper.rb" but I can't create a TestCase instance that will let me access those test methods to play with them:
[4] pry(main)> tc = ActiveSupport::TestCase.new
ArgumentError: wrong number of arguments (0 for 1)
[5] pry(main)> tc = ActiveSupport::TestCase.new(1)
TypeError: 1 is not a symbol
[6] pry(main)> tc = ActiveSupport::TestCase.new(:unit)
ArgumentError: uncaught throw :invalid_test
I've tried in vain to follow the trail of breadcrumbs in source files to find the TestCase initialize method so I could figure out what it's insisting on here.
Can someone help me with how to think about problems like this and figure out a workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从此链接复制: https://gist.github.com/1297510
在您的终端上键入:
Copied from this link: https://gist.github.com/1297510
On your terminal type:
对于您的具体情况,在我的 ActiveSupport (3.22.2.8) 版本中,我能够执行以下操作:
不过,一般来说,有几个选项:
pry
这样的调试器可能会有所帮助,以单步执行通过这个问题。gem open activesupport
查找源代码,或者通过gem 环境
查找您的 gem 的安装位置。For your specific case, in my version of ActiveSupport (3.22.2.8), I was able to do the following:
In general though, there's several options:
pry
can be helpful, to step through the issue.gem open activesupport
or find where your gems are installed withgem environment