在 selenium 模式下,assert_response 不适用于 webrat
有人知道如何使用 selenium 让assert_response 与 webrat 一起工作吗?我不断收到
NoMethodError: undefined method `response_code' for nil:NilClass
这是我的测试:
def test_basic_page_load
visit root_path
click_link "register"
assert_response 200
end
这是错误:
==> Waiting for Selenium RC server on port 4444... Ready!
==> Waiting for rails application server on port 3001... Ready!
E
1) Error:
test_basic_page_load(UserCrudTest):
NoMethodError: undefined method `response_code' for nil:NilClass
/test/integration/user_crud_test.rb:11:in `test_basic_page_load'
Finished in 12.269964 seconds.
我确信我错过了一些愚蠢的东西,但我只是没有看到它......有什么想法吗?
Anyone know how to get assert_response to work with webrat using selenium? I keep getting
NoMethodError: undefined method `response_code' for nil:NilClass
Here's my test:
def test_basic_page_load
visit root_path
click_link "register"
assert_response 200
end
Here's the error:
==> Waiting for Selenium RC server on port 4444... Ready!
==> Waiting for rails application server on port 3001... Ready!
E
1) Error:
test_basic_page_load(UserCrudTest):
NoMethodError: undefined method `response_code' for nil:NilClass
/test/integration/user_crud_test.rb:11:in `test_basic_page_load'
Finished in 12.269964 seconds.
I'm sure it's something silly that I'm missing, but I just don't see it.... Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯嗯,目前看来是不可能的。
测试过程从命令行(在
Webrat::Selenium::ApplicationServers::Rails
中)启动一个新的 mongrel 实例,因此无权访问@controller
由ActionController::Integration::Session.get
设置的变量。这个@controller变量由assert_response使用。我想知道使用
fork
而不是system
启动一个混合服务器需要做多少工作(在Webrat::Selenium::ApplicationServers::Rails.start 中) )。它可以与 selenium.wait_for_page_to_load 结合使用,以确保测试等待服务器进程完成响应。只是一个想法,我可能不会再研究它了。
对于任何使用 webrat 和 Shoulda 的人来说,这样的东西仍然有效:
干杯,
布莱恩
Hmmm, it looks like it's not possible at the moment.
The testing process starts a new mongrel instance from the command line (in
Webrat::Selenium::ApplicationServers::Rails
) and therefore doesn't have access to the@controller
variable that would be set byActionController::Integration::Session.get
. This@controller
variable is used by assert_response.I wonder how much work it would be to start up a mongrel server using
fork
instead ofsystem
(inWebrat::Selenium::ApplicationServers::Rails.start
). It could maybe be combined withselenium.wait_for_page_to_load
to ensure the test waits for the server process to finish the response. Just an idea, I probably won't look into it any more.For anyone using webrat with shoulda, something like this will still work:
Cheers,
Brian