File: component_generator_test.rb

package info (click to toggle)
ruby-view-component 4.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,832 kB
  • sloc: ruby: 8,385; sh: 166; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 974 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
# frozen_string_literal: true

require_relative "../../test_helper"
require "generators/view_component/component/component_generator"

class ComponentGeneratorTest < Rails::Generators::TestCase
  tests ViewComponent::Generators::ComponentGenerator
  destination Dir.mktmpdir
  setup :prepare_destination

  def test_component
    run_generator %w[example]

    assert_file "app/components/test_engine/example_component.rb" do |component|
      assert_match(/module TestEngine/, component)
      assert_match(/class ExampleComponent < ViewComponent::Base/, component)
      assert_no_match(/def initialize/, component)
    end
  end

  def test_component_without_suffix
    run_generator %w[example --skip-suffix]

    assert_file "app/components/test_engine/example.rb" do |component|
      assert_match(/module TestEngine/, component)
      assert_match(/class Example < ViewComponent::Base/, component)
      assert_no_match(/def initialize/, component)
    end
  end
end