Class: Boring::Ci::GitlabCi::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
BoringGenerators::GeneratorHelper
Defined in:
lib/generators/boring/ci/gitlab_ci/install/install_generator.rb

Instance Method Summary collapse

Methods included from BoringGenerators::GeneratorHelper

#app_ruby_version, #bundle_install, #check_and_install_gem, #gem_installed?, #inject_into_file_if_new

Instance Method Details

#add_capybara_configurationsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/generators/boring/ci/gitlab_ci/install/install_generator.rb', line 61

def add_capybara_configurations
  if options[:app_test_framework] == "minitest"
    template("capybara_helper.rb", "test/helpers/capybara.rb")

    inject_into_file_if_new "test/application_system_test_case.rb",
                            "require \"helpers/capybara\"\n",
                            before: "class ApplicationSystemTestCase"
    gsub_file "test/application_system_test_case.rb",
              /driven_by :selenium, using: :(?:chrome|headless_chrome).*\n/,
              "driven_by :selenium_chrome_custom"

    capybara_setup = "    \\n\n    def setup\n      Capybara.server_host = \"0.0.0.0\" # bind to all interfaces\n      Capybara.server_port = 3000\n\n      if ENV[\"SELENIUM_REMOTE_URL\"].present?\n        ip = Socket.ip_address_list.detect(&:ipv4_private?).ip_address\n        Capybara.app_host = \"http://\\\#{ip}:\\\#{Capybara.server_port}\"\n      end\n\n      super\n    end\n    RUBY\n\n    inject_into_file_if_new \"test/application_system_test_case.rb\",\n                            optimize_indentation(\n                              capybara_setup,\n                              amount = 2\n                            ),\n                            after: \"driven_by :selenium_chrome_custom\"\n  else\n    template(\"capybara_helper.rb\", \"spec/support/capybara.rb\")\n\n    inject_into_file_if_new \"spec/rails_helper.rb\",\n                            \"require_relative \\\"./support/capybara\\\"\\n\\n\",\n                            before: \"RSpec.configure do |config|\"\n  end\nend\n"

#add_gems_for_system_testObject



56
57
58
59
# File 'lib/generators/boring/ci/gitlab_ci/install/install_generator.rb', line 56

def add_gems_for_system_test
  check_and_install_gem "capybara", group: :test
  check_and_install_gem "selenium-webdriver", group: :test
end

#add_gitlab_ci_configurationsObject



46
47
48
49
50
51
52
53
54
# File 'lib/generators/boring/ci/gitlab_ci/install/install_generator.rb', line 46

def add_gitlab_ci_configurations
  @ruby_version = options[:ruby_version] || app_ruby_version
  @app_test_framework = options[:app_test_framework]
  @environment_variable_manager = options[:environment_variable_manager]
  @database = options[:database]

  template("ci.yml", ".gitlab-ci.yml")
  template("database.yml.ci", "config/database.yml.ci")
end

#add_sample_testsObject



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/generators/boring/ci/gitlab_ci/install/install_generator.rb', line 102

def add_sample_tests
  return if options[:skip_sample_tests]

  if options[:app_test_framework] == "minitest"
    template("unit_sample_test.rb", "test/models/sample_test.rb")
    template("system_sample_test.rb", "test/system/sample_test.rb")
  else
    template("unit_sample_spec.rb", "spec/models/sample_spec.rb")
    template("system_sample_spec.rb", "spec/system/sample_spec.rb")
  end
end

#show_readmeObject



114
115
116
# File 'lib/generators/boring/ci/gitlab_ci/install/install_generator.rb', line 114

def show_readme
  readme "README"
end