Ruby 单元测试 Get 方法
我正在绞尽脑汁地尝试扩大现有 Rails 2.3 应用程序的测试覆盖范围。
他们正在使用单元:测试框架。我真的很难理解如何调试经常出现的 get
方法。这是一个例子:
get(:results,
{ # params
:s => "college",
:alt_iframes => iframes_param,
:site_version => ApplicationController::VERSION_GOOGLE.to_i
},
{ # session
:arrival_id => 3,
:arrival_quality => test_quality,
:tid => test_tid,
})
当它起作用时,发生的事情是不言而喻的。然而,当它不起作用时,我在调试问题所在时遇到很多麻烦。
无论如何,有没有办法了解这样的调用相当于什么确切的 URL?或者是否可以调用这种形式的 get("localhost:3000
")。
当我进行谷歌搜索时,我什至找到了文档。
I am pulling my hair out trying to expand the testing coverage for an existing Rails 2.3 app.
They are using a unit:test framework. I am really having trouble wrapping my head around how to debug the get
method that appears a lot. Here is an example:
get(:results,
{ # params
:s => "college",
:alt_iframes => iframes_param,
:site_version => ApplicationController::VERSION_GOOGLE.to_i
},
{ # session
:arrival_id => 3,
:arrival_quality => test_quality,
:tid => test_tid,
})
When it works, it is pretty self-evident what is going on. However, when it doesn't work, I have a lot of trouble debugging what is going wrong.
Is there anyway to understand what exact URL a call like this equates to? Or is it possible to make a call of this form instaed get("localhost:3000
").
I am having even finding documentation when I do a google search.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在谈论控制器测试,则
get
根本不会调用 URL。它只是直接调用您正在测试的控制器中的操作。如果您谈论的是集成测试,那么它的工作方式会有所不同......并且没有人应该在单元测试中调用 get 。If you are talking about a controller test, then
get
doesn't call a URL at all. It just directly calls the action in the controller you are testing. It works differently if you are talking about an integration test... and nobody should be calling get in a unit test.这很大程度上取决于测试所测试的方法以及应用程序是否是 RESTful。
例如,如果您在注释控制器中执行此操作,Rails 将使用设置的路由来确定这是测试 /comments。
如果是看跌期权,它会知道您正在使用 /comments/:id 测试更新。
This largely depends on the method that the test is testing and if the application is RESTful or not.
For instance, if you're doing this in a comments controller, Rails will use the routes that are setup to determine that this is testing /comments.
If it's a put, it'll know you're testing update with /comments/:id.