【问题标题】:Testing Liquid templates in rails using Rspec使用 Rspec 在 Rails 中测试 Liquid 模板
【发布时间】:2009-09-04 16:08:05
【问题描述】:

希望使用 rspec 来测试液体模板。有人试过这个吗?有没有可能。

具体来说,我们的应用允许用户提交一组模板,我希望能够编写集成测试来验证这些模板。

欢迎使用替代解决方案/方法..

【问题讨论】:

    标签: ruby-on-rails rspec liquid


    【解决方案1】:
    it "should render liquid" do
      liquid = <<-LIQUID
      {% for category in bulletin.categories %}
      {{ category.title }}
      {% for event in category.events %}
      {{ event.name }}
      {% endfor %}
      {% endfor %}
      LIQUID
    
      rendered = Liquid::Template.parse(liquid).render 'bulletin' => @bulletin
    
      rendered.should include @category.title
      rendered.should include @event.name
    end
    

    【讨论】:

      【解决方案2】:

      为了测试用户交互,我推荐使用 Cucumber。这允许您指定用户步骤并检查您的应用程序如何响应 - 通过浏览器。这是非常强大的东西!

      RSpec 应该用于测试模型和控制器中的特定方法。使用 RSpec 进行视图测试没有任何意义。使用 Cucumber,您可以使用整个应用程序堆栈。

      【讨论】:

        【解决方案3】:

        如果您的意思是要在保存时验证模板,那么模型应该负责模板的验证,并且规范应该测试验证,而不是模板。我将使用 rspec 来测试模型上的特定验证,并使用 cucumber 来测试有效和无效的情况。

        【讨论】:

          猜你喜欢
          • 2017-05-28
          • 1970-01-01
          • 1970-01-01
          • 2012-09-26
          • 1970-01-01
          • 1970-01-01
          • 2012-07-06
          • 2010-10-07
          • 2017-01-06
          相关资源
          最近更新 更多