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") {
    "      # frozen_string_literal: true\n\n      class \#{ file_name.camelize }TestHelper < \#{ base_helper? ? 'Capybara::TestHelper' : 'BaseTestHelper' }\n      # Aliases: Semantic aliases for locators, can be used in most DSL methods.\n        aliases(\n          \#{ base_helper? ? '# Avoid defining :el here since it will be inherited by all helpers.' : \"# el: '.\#{ file_name.tr('_', '-') }',\" }\n        )\n\n      # Finders: A convenient way to get related data or nested elements.\n\n      # Actions: Encapsulate complex actions to provide a cleaner interface.\n\n      # Assertions: Check on element properties, used with `should` and `should_not`.\n\n      # Background: Helpers to add/modify/delete data in the database or session.\n      end\n    CAPYBARA_TEST_HELPER\n  }\nend\n"