Sha256: 890e2fb587496d49d8e1b98baa3bcedd94c6c815380500581aa795470648fc42

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper'

describe WrapIt::Base, type: :wrapped do
  it 'includes framework-specific methods' do
    methods = successor_class.protected_instance_methods(true)
    expect(methods).to include :concat, :capture, :output_buffer
  end

  it 'renders base as div' do
    render '<%= helper %>'
    expect(rendered).to have_tag 'div', count: 1
  end

  describe 'self.omit_content' do
    it 'captures block content' do
      render '<%= helper do %>Some text<% end %>'
      expect(rendered).to have_tag 'div', count: 1, text: /Some text/
    end

    it 'omits block content with omit_content' do
      successor_class.class_eval { omit_content }
      render '<%= helper do %>Some text<% end %>'
      expect(rendered).to have_tag 'div', count: 1, text: ''
    end
  end

  describe '#render' do
    it 'adds content from arguments' do
      expect(
        successor.render('text', :and, ' from arguments')
      ).to have_tag 'div', text: 'text from arguments'
    end

    it 'adds content from block' do
      expect(successor.render { 'text' }).to have_tag 'div', text: 'text'
    end
  end

  describe '#wrap' do
    it 'wraps with WrapIt::Base by default' do
      render '<%= helper(tag: :p) { |s| s.wrap } %>'
      expect(rendered).to have_tag 'div > p'
    end

    it 'wraps with WrapIt::Base and creating options' do
      render '<%= helper(tag: :p) { |s| s.wrap tag: :nav } %>'
      expect(rendered).to have_tag 'nav > p'
    end

    it 'wraps with class and creating options' do
      render <<-EOL
        <% w = Class.new(WrapIt::Base) { switch :sw, html_class: 'act' } %>
        <%= helper(tag: :p) { |s| s.wrap w, :sw, tag: :nav } %>'
      EOL
      expect(rendered).to have_tag 'nav.act > p'
    end

    it 'wraps with block' do
      render <<-EOL
        <%= helper(tag: :p) { |s| s.wrap do
          |w| w.html_class << 'nav'
        end } %>'
      EOL
      expect(rendered).to have_tag 'div.nav > p'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wrap_it-1.0.2 spec/integration/base_spec.rb
wrap_it-1.0.1 spec/integration/base_spec.rb
wrap_it-1.0.0 spec/integration/base_spec.rb