File: component_spec.rb

package info (click to toggle)
ruby-arbre 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 532 kB
  • sloc: ruby: 1,912; makefile: 7; sh: 4
file content (41 lines) | stat: -rw-r--r-- 917 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true
require 'spec_helper'

# A mock subclass to play with
class MockComponent < Arbre::Component
  builder_method :mock_component

  def build
    h2 "Hello World"
  end
end

describe Arbre::Component do
  let(:assigns) { {} }
  let(:helpers) { nil }
  let(:component_class) { MockComponent }
  let(:component) { component_class.new }

  it "is a subclass of an html div" do
    expect(described_class.ancestors).to include(Arbre::HTML::Div)
  end

  it "renders to a div, even as a subclass" do
    expect(component.tag_name).to eq('div')
  end

  it "does not have a class list" do
    expect(component.class_list.to_s).to eq("")
    expect(component.class_list.empty?).to be(true)
  end

  it "renders the object using the builder method name" do
    expect(arbre {
      mock_component
    }.to_s).to eq <<~HTML
      <div>
        <h2>Hello World</h2>
      </div>
      HTML
  end
end