Class: TestHelperGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/test_helper/test_helper_generator.rb

Overview

Internal: Generates a new test helper file in the appropriate directory.

Instance Method Summary collapse

Instance Method Details

#base_helper?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/generators/test_helper/test_helper_generator.rb', line 8

def base_helper?
  file_name.to_s == 'base'
end

#create_helper_fileObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/test_helper/test_helper_generator.rb', line 12

def create_helper_file
  create_file("#{ CapybaraTestHelpers.config.helpers_paths.first }/#{ file_name }_test_helper.rb") {
    <<~CAPYBARA_TEST_HELPER
      # frozen_string_literal: true

      class #{ file_name.camelize }TestHelper < #{ base_helper? ? 'Capybara::TestHelper' : 'BaseTestHelper' }
      # Aliases: Semantic aliases for locators, can be used in most DSL methods.
        aliases(
          #{ base_helper? ? '# Avoid defining :el here since it will be inherited by all helpers.' : "# el: '.#{ file_name.tr('_', '-') }'," }
        )

      # Finders: A convenient way to get related data or nested elements.

      # Actions: Encapsulate complex actions to provide a cleaner interface.

      # Assertions: Check on element properties, used with `should` and `should_not`.

      # Background: Helpers to add/modify/delete data in the database or session.
      end
    CAPYBARA_TEST_HELPER
  }
end