简体   繁体   English

在RSpec Controller规范中测试RJS的最佳方法是什么?

[英]Best way to test RJS in RSpec Controller specs?

What is the best way to ensure that the proper RJS is being generated in a Controller action? 确保在Controller操作中生成正确的RJS的最佳方法是什么?

For example, I want to ensure that a div is highlighted as such: 例如,我想确保div被突出显示为:

def new
  render :update do |page|
    page.visual_effect :highlight, :some_div
  end
end

Rant: This is quickly becoming one of the reasons I grow tired of RSpec after using it for a year. Rant:这很快成为我使用RSpec一年后厌倦RSpec的原因之一。 This should be an easy question, but it's one that no one seems to have an answer for. 这应该是一个简单的问题,但是没有人似乎有答案。

I've been told repeatedly that RSpec specifies behavior and what I'm trying to do here is just "test code". 我一再被告知RSpec指定行为,我在这里尝试做的只是“测试代码”。 Highlighting of the :some_div is behavior as far as I can tell. 突出显示:some_div就是我所知道的行为。

Is it not possible to setup a controller test for the output of the response and look for some javascript formatting? 是否无法为响应的输出设置控制器测试并寻找一些javascript格式?

  xhr :get, :new
  response.should be_success
  response.should have_text("... test for JS response ...")

I would also probably use Selenium to more fully test this on the client, and the Controller test is more of a "sanity" check. 我也可能会使用Selenium在客户端上更全面地测试它,而Controller测试更像是一种“理智”检查。

rspec gives you the have_rjs helper which wraps assert_select_rjs. rspec为您提供了包含assert_select_rjs的have_rjs帮助器。 Here are some specifics: 以下是一些细节:

http://jonathan.tron.name/2007/11/24/rspec-and-inline-rjs http://jonathan.tron.name/2007/11/24/rspec-and-inline-rjs

Unfortunately assert_select_rjs only covers: 不幸的是,assert_select_rjs仅涵盖:

:replace, :replace_html, :show, :hide, :toggle, :remove and :insert_html 

So this won't handle the visual_effect from your question. 所以这不会处理你问题的visual_effect。 However the ARTS plugin does support the visual effects. 然而,ARTS插件确实支持视觉效果。

http://github.com/timocratic/arts/tree/master http://github.com/timocratic/arts/tree/master

You should be able to combine that with rspecs new 'spec/interop/test'. 你应该能够将它与rspecs新的'spec / interop / test'结合起来。

http://blog.davidchelimsky.net/2009/2/2/rspec-works-with-test-unit http://blog.davidchelimsky.net/2009/2/2/rspec-works-with-test-unit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM