require 'spec_helper' module Deface describe HamlConverter do include_context "mock Rails.application" def haml_to_erb(src) haml_engine = Deface::HamlConverter.new(src) haml_engine.render.gsub("\n", "") end describe "convert haml to erb" do it "should hanlde simple tags" do haml_to_erb("%%strong.code#message Hello, World!").should == "Hello, World!" end it "should handle complex tags" do haml_to_erb(%q{#content .left.column %h2 Welcome to our site! %p= print_information .right.column = render :partial => "sidebar"}).should == "

Welcome to our site!

<%= print_information %>

<%= render :partial => \"sidebar\" %>
" end it "should handle erb loud" do haml_to_erb("%h3.title= entry.title").should == "

<%= entry.title %>

" end it "should handle single erb silent" do haml_to_erb("- some_method").should == "<% some_method %>" end it "should handle implicitly closed erb loud" do haml_to_erb("= if @this == 'this' %p hello ").should == "<%= if @this == 'this' %>

hello

<% end %>" end it "should handle implicitly closed erb silent" do haml_to_erb("- if foo? %p hello ").should == "<% if foo? %>

hello

<% end %>" end it "should handle blocks passed to erb loud" do haml_to_erb("= form_for Post.new do |f| %p = f.text_field :name").should == "<%= form_for Post.new do |f| %>

<%= f.text_field :name %>

<% end %>" end it "should handle blocks passed to erb silent" do haml_to_erb("- @posts.each do |post| %p = post.name").should == "<% @posts.each do |post| %>

<%= post.name %>

<% end %>" end end end end