Sha256: aaacab3e0583162e62dab88c682b66f9ef291e156c8c13cba6c265774b4267ef

Contents?: true

Size: 1.21 KB

Versions: 9

Compression:

Stored size: 1.21 KB

Contents

# frozen-string-literal: true
require 'spec_helper'

RSpec.describe 'Script rendering', type: :render do
  it 'parses script' do
    expect(render_string('%span= 1 + 2')).to eq("<span>3</span>\n")
  end

  it 'parses multi-line script' do
    expect(render_string(<<HAML)).to eq("<span>\n3\n</span>\n")
%span
  = 1 + 2
HAML
  end

  it 'parses script and text' do
    expect(render_string(<<HAML)).to eq("<span>\n3\n3\n9\n</span>\n")
%span
  = 1 + 2
  3
  = 4 + 5
HAML
  end

  it 'can contain Ruby comment' do
    expect(render_string('%span= 1 + 2 # comments')).to eq("<span>3</span>\n")
  end

  it 'can contain Ruby comment in multi-line' do
    expect(render_string(<<HAML)).to eq("<span>\n3\n3\n9\n</span>\n")
%span
  = 1 + 2 # comment
  3
  = 4 + 5 # comment
HAML
  end

  it 'can be comment-only' do
    expect(render_string(<<HAML)).to eq("\nstring\n")
= # comment
= 'string'
HAML
  end

  it 'can have children' do
    expect(render_string(<<HAML)).to eq("<span>0</span>\n1<span>end</span>\n")
= 1.times do |i|
  %span= i
%span end
HAML
  end

  it 'escapes unsafe string' do
    expect(render_string(<<HAML)).to eq("<p>&lt;script&gt;alert(1)&lt;/script&gt;</p>\n")
- title = '<script>alert(1)</script>'
%p= title
HAML
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
faml-0.7.3 spec/render/script_spec.rb
faml-0.7.2 spec/render/script_spec.rb
faml-0.7.1 spec/render/script_spec.rb
faml-0.7.0 spec/render/script_spec.rb
faml-0.6.5 spec/render/script_spec.rb
faml-0.6.4 spec/render/script_spec.rb
faml-0.6.3 spec/render/script_spec.rb
faml-0.6.2 spec/render/script_spec.rb
faml-0.6.1 spec/render/script_spec.rb