views:

215

answers:

3

looking to use rspec to test liquid templates. Anyone tried this? Is it possible.

Specifically our app allows users to submit a set of templates and I'd like to be able to write integration tests to validate these templates.

Alternative solutions/approaches welcome..

A: 

For testing user interaction I recommend using Cucumber. This allows you to specify the user steps and check how your app responds - through a browser. This is very powerful stuff!

RSpec should be used for testing specific methods in your models and controllers. View testing with RSpec doesn't make any sense. With Cucumber, you're exercising your entire application stack.

Ariejan
+1  A: 
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
Macario
A: 

If you mean that you want to validate the template on save, then the model should be responsible for the validation of the template and the spec should test the validations, not the template. I would use rspec to test the specific validations as on the model, and cucumber to test the valid and invalid cases.

Jed Schneider