Sha256: f970c1182f578165316116f3b007b4ca868eada7de1daf2c47c5539b903093bc

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

RSpec.describe 'bem_attrs_for helper' do
  delegate :bem_attrs_for, to: :view

  context 'when a block and element have no name' do
    it { expect(bem_attrs_for).to be_empty }
  end

  context 'when only a block name is specified' do
    it { expect(bem_attrs_for(:block)).to include(class: 'block i-bem', 'data-bem': '{"block":{}}') }
    it { expect(bem_attrs_for(:block, mods: :enabled)).to include(class: 'block block_enabled i-bem', 'data-bem': '{"block":{}}') }
    it { expect(bem_attrs_for(:block, mix: { block1: :elem })).to include(class: 'block block1__elem i-bem', 'data-bem': '{"block":{}}') }
    it { expect(bem_attrs_for(:block, js: { key: :val })).to include(class: 'block i-bem', 'data-bem': '{"block":{"key":"val"}}') }
    it { expect(bem_attrs_for(:block, js: false)).to include(class: 'block') }

    ['', false].each do |elem|
      it { expect(bem_attrs_for(:block, elem)).to be_empty }
    end
  end

  context 'when only an element name is specified' do
    ['', nil, false].each do |block|
      it { expect(bem_attrs_for(block, :elem)).to be_empty }
    end
  end

  context 'when a name is specified for a block and element' do
    it { expect(bem_attrs_for(:block, :elem)).to include(class: 'block__elem i-bem', 'data-bem': '{"block__elem":{}}') }
    it { expect(bem_attrs_for(:block, :elem, mods: :enabled)).to include(class: 'block__elem block__elem_enabled i-bem', 'data-bem': '{"block__elem":{}}') }
    it { expect(bem_attrs_for(:block, :elem, mix: :block_2)).to include(class: 'block__elem block-2 i-bem', 'data-bem': '{"block__elem":{}}') }
    it { expect(bem_attrs_for(:block, :elem, js: { key: :val })).to include(class: 'block__elem i-bem', 'data-bem': '{"block__elem":{"key":"val"}}') }
    it { expect(bem_attrs_for(:block, :elem, js: false)).to include(class: 'block__elem') }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bemer-0.6.0 spec/action_view/helpers/bem_attrs_for_spec.rb
bemer-0.5.0 spec/action_view/helpers/bem_attrs_for_spec.rb
bemer-0.4.0 spec/action_view/helpers/bem_attrs_for_spec.rb