boring_generators 0.13.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +83 -49
- data/Gemfile.lock +2 -2
- data/README.md +14 -0
- data/lib/boring_generators/generator_helper.rb +46 -0
- data/lib/boring_generators/version.rb +1 -1
- data/lib/generators/boring/active_storage/azure/install/install_generator.rb +1 -1
- data/lib/generators/boring/annotate/install/install_generator.rb +52 -0
- data/lib/generators/boring/audit/install/install_generator.rb +1 -1
- data/lib/generators/boring/avo/install/install_generator.rb +25 -0
- data/lib/generators/boring/cancancan/install/install_generator.rb +34 -0
- data/lib/generators/boring/ci/gitlab_ci/install/install_generator.rb +120 -0
- data/lib/generators/boring/ci/gitlab_ci/install/templates/README +10 -0
- data/lib/generators/boring/ci/gitlab_ci/install/templates/capybara_helper.rb.tt +42 -0
- data/lib/generators/boring/ci/gitlab_ci/install/templates/ci.yml.tt +94 -0
- data/lib/generators/boring/ci/gitlab_ci/install/templates/database.yml.ci.tt +20 -0
- data/lib/generators/boring/ci/gitlab_ci/install/templates/system_sample_spec.rb.tt +14 -0
- data/lib/generators/boring/ci/gitlab_ci/install/templates/system_sample_test.rb.tt +13 -0
- data/lib/generators/boring/ci/gitlab_ci/install/templates/unit_sample_spec.rb.tt +7 -0
- data/lib/generators/boring/ci/gitlab_ci/install/templates/unit_sample_test.rb.tt +7 -0
- data/lib/generators/boring/devise/doorkeeper/install/install_generator.rb +190 -0
- data/lib/generators/boring/devise/install/install_generator.rb +42 -9
- data/lib/generators/boring/dotenv/install/install_generator.rb +51 -0
- data/lib/generators/boring/dotenv/install/templates/.env +3 -0
- data/lib/generators/boring/factory_bot/install/install_generator.rb +1 -1
- data/lib/generators/boring/faker/install/install_generator.rb +1 -1
- data/lib/generators/boring/favicon/build/build_generator.rb +1 -1
- data/lib/generators/boring/figjam/install/install_generator.rb +33 -0
- data/lib/generators/boring/honeybadger/install/install_generator.rb +47 -0
- data/lib/generators/boring/honeybadger/install/templates/README +6 -0
- data/lib/generators/boring/honeybadger/install/templates/honeybadger.yml.tt +26 -0
- data/lib/generators/boring/letter_opener/install/install_generator.rb +8 -9
- data/lib/generators/boring/oauth/google/install/install_generator.rb +2 -2
- data/lib/generators/boring/pronto/base_generator.rb +78 -0
- data/lib/generators/boring/pronto/github_action/install/install_generator.rb +27 -0
- data/lib/generators/boring/pronto/github_action/install/templates/pronto.yml.tt +53 -0
- data/lib/generators/boring/pronto/gitlab_ci/install/install_generator.rb +112 -0
- data/lib/generators/boring/pronto/gitlab_ci/install/templates/.gitlab-ci.yml.tt +22 -0
- data/lib/generators/boring/pronto/gitlab_ci/install/templates/README +7 -0
- data/lib/generators/boring/rack_mini_profiler/install/install_generator.rb +38 -0
- data/lib/generators/boring/rails_erd/install/install_generator.rb +35 -0
- data/lib/generators/boring/rspec/install/install_generator.rb +1 -1
- data/lib/generators/boring/sentry/install/install_generator.rb +48 -0
- data/lib/generators/boring/sentry/install/templates/sentry.rb +7 -0
- data/lib/generators/boring/vcr/install/install_generator.rb +126 -0
- data/lib/generators/boring/vcr/install/templates/rspec/vcr.rb.tt +9 -0
- data/lib/generators/boring/webmock/install/install_generator.rb +7 -6
- metadata +34 -2
@@ -8,9 +8,9 @@ module Boring
|
|
8
8
|
def add_letter_opener_gem
|
9
9
|
say "Adding letter_opener gem", :green
|
10
10
|
|
11
|
-
gem_content = <<~RUBY
|
12
|
-
\
|
13
|
-
|
11
|
+
gem_content = <<~RUBY.indent(2)
|
12
|
+
\n# Preview email in the default browser instead of sending it to real mailbox
|
13
|
+
gem "letter_opener"
|
14
14
|
RUBY
|
15
15
|
|
16
16
|
insert_into_file "Gemfile", gem_content, after: /group :development do/
|
@@ -23,16 +23,15 @@ module Boring
|
|
23
23
|
def configure_letter_opener
|
24
24
|
say "Configuring letter_opener", :green
|
25
25
|
|
26
|
-
configuration_content = <<~RUBY.chomp
|
27
|
-
\n
|
28
|
-
|
29
|
-
|
30
|
-
end
|
26
|
+
configuration_content = <<~RUBY.chomp.indent(2)
|
27
|
+
\n# Preview email in the browser instead of sending it
|
28
|
+
config.action_mailer.delivery_method = :letter_opener
|
29
|
+
config.action_mailer.perform_deliveries = true
|
31
30
|
RUBY
|
32
31
|
|
33
32
|
gsub_file "config/environments/development.rb",
|
34
33
|
/end\Z/,
|
35
|
-
configuration_content
|
34
|
+
"#{configuration_content}\nend"
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -14,8 +14,8 @@ module Boring
|
|
14
14
|
desc "Adds Google OmniAuth to the application"
|
15
15
|
source_root File.expand_path("templates", __dir__)
|
16
16
|
|
17
|
-
def
|
18
|
-
say "Adding
|
17
|
+
def add_google_omniauth_gem
|
18
|
+
say "Adding Google OmniAuth gem", :green
|
19
19
|
Bundler.with_unbundled_env do
|
20
20
|
run "bundle add omniauth-google-oauth2"
|
21
21
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "boring_generators/generator_helper"
|
4
|
+
|
5
|
+
module Boring
|
6
|
+
module Pronto
|
7
|
+
class BaseGenerator < Rails::Generators::Base
|
8
|
+
desc "Adds Pronto gem with various extensions"
|
9
|
+
|
10
|
+
class_option :skip_extensions,
|
11
|
+
type: :array,
|
12
|
+
aliases: "-se",
|
13
|
+
desc:
|
14
|
+
"List of extensions to skip. Available options: brakeman, flay, reek, rubocop",
|
15
|
+
enum: %w[brakeman flay reek rubocop],
|
16
|
+
default: []
|
17
|
+
|
18
|
+
include BoringGenerators::GeneratorHelper
|
19
|
+
|
20
|
+
def add_pronto_gems
|
21
|
+
say "Adding pronto gems", :green
|
22
|
+
|
23
|
+
gem_content = <<~RUBY.strip
|
24
|
+
#{pronto_gem_content}
|
25
|
+
#{pronto_brakemen_gem_content}
|
26
|
+
#{pronto_flay_gem_content}
|
27
|
+
#{pronto_reek_gem_content}
|
28
|
+
#{pronto_rubocop_gem_content}
|
29
|
+
RUBY
|
30
|
+
|
31
|
+
return if gem_content.blank?
|
32
|
+
|
33
|
+
insert_into_file "Gemfile", "\n#{gem_content}\n"
|
34
|
+
|
35
|
+
Bundler.with_unbundled_env { run "bundle install" }
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def pronto_gem_content
|
41
|
+
return if gem_installed?("pronto")
|
42
|
+
|
43
|
+
<<~RUBY.strip
|
44
|
+
# Pronto is a code linter runner that can be used with git and GitHub pull requests
|
45
|
+
gem "pronto"
|
46
|
+
RUBY
|
47
|
+
end
|
48
|
+
|
49
|
+
def pronto_brakemen_gem_content
|
50
|
+
return if options[:skip_extensions].include?("brakeman")
|
51
|
+
return if gem_installed?("pronto-brakeman")
|
52
|
+
|
53
|
+
"gem \"pronto-brakeman\", require: false"
|
54
|
+
end
|
55
|
+
|
56
|
+
def pronto_flay_gem_content
|
57
|
+
return if options[:skip_extensions].include?("flay")
|
58
|
+
return if gem_installed?("pronto-flay")
|
59
|
+
|
60
|
+
"gem \"pronto-flay\", require: false"
|
61
|
+
end
|
62
|
+
|
63
|
+
def pronto_reek_gem_content
|
64
|
+
return if options[:skip_extensions].include?("reek")
|
65
|
+
return if gem_installed?("pronto-reek")
|
66
|
+
|
67
|
+
"gem \"pronto-reek\", require: false"
|
68
|
+
end
|
69
|
+
|
70
|
+
def pronto_rubocop_gem_content
|
71
|
+
return if options[:skip_extensions].include?("rubocop")
|
72
|
+
return if gem_installed?("pronto-rubocop")
|
73
|
+
|
74
|
+
"gem \"pronto-rubocop\", require: false"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/boring/pronto/base_generator"
|
4
|
+
require "boring_generators/generator_helper"
|
5
|
+
|
6
|
+
module Boring
|
7
|
+
module Pronto
|
8
|
+
module GithubAction
|
9
|
+
class InstallGenerator < Boring::Pronto::BaseGenerator
|
10
|
+
desc "Adds Pronto configurations to Github Action"
|
11
|
+
source_root File.expand_path("templates", __dir__)
|
12
|
+
|
13
|
+
class_option :ruby_version, type: :string, aliases: "-rv"
|
14
|
+
|
15
|
+
include BoringGenerators::GeneratorHelper
|
16
|
+
|
17
|
+
def add_pronto_configuration_for_github_action
|
18
|
+
say "Adding Pronto configurations to .github/workflows/pronto.yml", :green
|
19
|
+
|
20
|
+
@ruby_version = options.ruby_version || app_ruby_version
|
21
|
+
|
22
|
+
template("pronto.yml", ".github/workflows/pronto.yml")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
on: [pull_request]
|
2
|
+
|
3
|
+
name: Pronto
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
pronto:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
permissions:
|
9
|
+
contents: read
|
10
|
+
pull-requests: write
|
11
|
+
statuses: write
|
12
|
+
steps:
|
13
|
+
- name: Checkout code
|
14
|
+
uses: actions/checkout@v2
|
15
|
+
with:
|
16
|
+
fetch-depth: 0
|
17
|
+
|
18
|
+
- name: Setup Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: <%= @ruby_version %>
|
22
|
+
- name: Ruby gem cache
|
23
|
+
uses: actions/cache@v1
|
24
|
+
with:
|
25
|
+
path: vendor/bundle
|
26
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
27
|
+
restore-keys: |
|
28
|
+
${{ runner.os }}-gems-
|
29
|
+
- name: Install gems
|
30
|
+
run: |
|
31
|
+
bundle config path vendor/bundle
|
32
|
+
bundle install --jobs 4 --retry 3
|
33
|
+
|
34
|
+
- name: Setup Node
|
35
|
+
uses: actions/setup-node@v1
|
36
|
+
with:
|
37
|
+
node-version: 10.13.0
|
38
|
+
- name: Find yarn cache location
|
39
|
+
id: yarn-cache
|
40
|
+
run: echo "::set-output name=dir::$(yarn cache dir)"
|
41
|
+
- name: JS package cache
|
42
|
+
uses: actions/cache@v1
|
43
|
+
with:
|
44
|
+
path: ${{ steps.yarn-cache.outputs.dir }}
|
45
|
+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
46
|
+
restore-keys: |
|
47
|
+
${{ runner.os }}-yarn-
|
48
|
+
- name: Install packages
|
49
|
+
run: |
|
50
|
+
yarn install --pure-lockfile
|
51
|
+
- name: Run Pronto
|
52
|
+
run: |
|
53
|
+
PRONTO_PULL_REQUEST_ID="${{ github.event.pull_request.number }}" PRONTO_GITHUB_ACCESS_TOKEN="${{ github.token }}" bundle exec pronto run -f github_status github_pr -c origin/${{ github.base_ref }}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/boring/pronto/base_generator"
|
4
|
+
require "boring_generators/generator_helper"
|
5
|
+
|
6
|
+
module Boring
|
7
|
+
module Pronto
|
8
|
+
module GitlabCi
|
9
|
+
class InstallGenerator < Boring::Pronto::BaseGenerator
|
10
|
+
desc "Adds Pronto gem with various extensions and configures it for Gitlab CI"
|
11
|
+
source_root File.expand_path("templates", __dir__)
|
12
|
+
|
13
|
+
class_option :ruby_version, type: :string, aliases: "-rv"
|
14
|
+
|
15
|
+
include BoringGenerators::GeneratorHelper
|
16
|
+
|
17
|
+
def add_configuration
|
18
|
+
@ruby_version = options.ruby_version || app_ruby_version
|
19
|
+
|
20
|
+
if File.exist?(".gitlab-ci.yml")
|
21
|
+
add_pronto_configuration
|
22
|
+
add_lint_stage
|
23
|
+
show_readme
|
24
|
+
else
|
25
|
+
create_gitlab_ci_with_pronto
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def create_gitlab_ci_with_pronto
|
32
|
+
say "Creating .gitlab-ci.yml with Pronto configurations", :yellow
|
33
|
+
template ".gitlab-ci.yml", ".gitlab-ci.yml"
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_pronto_configuration
|
37
|
+
return if pronto_configuration_exists?
|
38
|
+
|
39
|
+
say "Adding Pronto configurations to .gitlab-ci.yml", :green
|
40
|
+
inject_into_file ".gitlab-ci.yml", pronto_ci_content, before: /\Z/
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_lint_stage
|
44
|
+
return if lint_stage_exists?
|
45
|
+
|
46
|
+
if stages_exists?
|
47
|
+
inject_into_file ".gitlab-ci.yml",
|
48
|
+
optimize_indentation("\n- lint", 2).chomp,
|
49
|
+
after: /stages:/
|
50
|
+
else
|
51
|
+
inject_into_file ".gitlab-ci.yml",
|
52
|
+
stages_configuration,
|
53
|
+
before: /pronto:/
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def show_readme
|
58
|
+
readme "README"
|
59
|
+
end
|
60
|
+
|
61
|
+
def pronto_configuration_exists?
|
62
|
+
gitlab_ci_file_content["pronto"]
|
63
|
+
end
|
64
|
+
|
65
|
+
def lint_stage_exists?
|
66
|
+
gitlab_ci_file_content["stages"] &&
|
67
|
+
gitlab_ci_file_content["stages"].include?("lint")
|
68
|
+
end
|
69
|
+
|
70
|
+
def stages_exists?
|
71
|
+
gitlab_ci_file_content["stages"]
|
72
|
+
end
|
73
|
+
|
74
|
+
def gitlab_ci_file_content
|
75
|
+
@gitlab_ci_file_content ||=
|
76
|
+
YAML.safe_load(File.open(".gitlab-ci.yml"), aliases: true) || {}
|
77
|
+
end
|
78
|
+
|
79
|
+
def pronto_ci_content
|
80
|
+
<<~RUBY
|
81
|
+
pronto:
|
82
|
+
image: ruby:#{@ruby_version}
|
83
|
+
stage: lint
|
84
|
+
only:
|
85
|
+
# run pronto on merge requests and when new changes are pushed to it
|
86
|
+
- merge_requests
|
87
|
+
variables:
|
88
|
+
PRONTO_GITLAB_API_PRIVATE_TOKEN: $PRONTO_ACCESS_TOKEN
|
89
|
+
before_script:
|
90
|
+
# Install cmake required for rugged gem (Pronto depends on it)
|
91
|
+
- apt-get update && apt-get install -y cmake
|
92
|
+
# use bundler version same as the one that bundled the Gemfile
|
93
|
+
- gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)" --no-document
|
94
|
+
- bundle install --jobs $(nproc)
|
95
|
+
script:
|
96
|
+
# Pronto fails with the error "revspec 'origin/{target_branch}' because Gitlab fetches changes with git depth set to 20 by default. You can remove this line if you update Gitlab CI setting to clone the full project.
|
97
|
+
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
|
98
|
+
# Run pronto on branch of current merge request
|
99
|
+
- bundle exec pronto run -f gitlab_mr -c origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
|
100
|
+
RUBY
|
101
|
+
end
|
102
|
+
|
103
|
+
def stages_configuration
|
104
|
+
<<~RUBY
|
105
|
+
stages:
|
106
|
+
- lint
|
107
|
+
RUBY
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
stages:
|
2
|
+
- lint
|
3
|
+
|
4
|
+
pronto:
|
5
|
+
image: ruby:<%= @ruby_version %>
|
6
|
+
stage: lint
|
7
|
+
only:
|
8
|
+
# run pronto on merge requests and when new changes are pushed to it
|
9
|
+
- merge_requests
|
10
|
+
variables:
|
11
|
+
PRONTO_GITLAB_API_PRIVATE_TOKEN: $PRONTO_ACCESS_TOKEN
|
12
|
+
before_script:
|
13
|
+
# Install cmake required for rugged gem (Pronto depends on it)
|
14
|
+
- apt-get update && apt-get install -y cmake
|
15
|
+
# use bundler version same as the one that bundled the Gemfile
|
16
|
+
- gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)" --no-document
|
17
|
+
- bundle install --jobs $(nproc)
|
18
|
+
script:
|
19
|
+
# Pronto fails with the error "revspec 'origin/{target_branch}' because Gitlab fetches changes with git depth set to 20 by default. You can remove this line if you update Gitlab CI setting to clone the full project.
|
20
|
+
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
|
21
|
+
# Run pronto on branch of current merge request
|
22
|
+
- bundle exec pronto run -f gitlab_mr -c origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
|
@@ -0,0 +1,7 @@
|
|
1
|
+
|
2
|
+
===============================================================================
|
3
|
+
|
4
|
+
❗️❗️
|
5
|
+
Pronto needs your Private Gitlab API token for posting comments in the merge request. It is configured as "PRONTO_ACCESS_TOKEN" inside .gitlab-ci.yml, don't forget to configure this variable in your Gitlab Project settings before pushing your new changes to git.
|
6
|
+
|
7
|
+
===============================================================================
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'boring_generators/generator_helper'
|
4
|
+
|
5
|
+
module Boring
|
6
|
+
module RackMiniProfiler
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
include BoringGenerators::GeneratorHelper
|
9
|
+
|
10
|
+
desc "Adds rack-mini-profiler to the application"
|
11
|
+
|
12
|
+
def add_rack_mini_profiler_gem
|
13
|
+
say "Adding rack-mini-profiler gem", :green
|
14
|
+
|
15
|
+
return if gem_installed?("rack-mini-profiler")
|
16
|
+
|
17
|
+
rack_mini_profiler_gems_content = <<~RUBY
|
18
|
+
\t# Profiler for your Rails application
|
19
|
+
\tgem 'rack-mini-profiler', require: false\n
|
20
|
+
RUBY
|
21
|
+
|
22
|
+
insert_into_file "Gemfile",
|
23
|
+
rack_mini_profiler_gems_content,
|
24
|
+
after: /group :development do\n/
|
25
|
+
|
26
|
+
Bundler.with_unbundled_env { run "bundle install" }
|
27
|
+
end
|
28
|
+
|
29
|
+
def configure_rack_mini_profiler
|
30
|
+
say "Configuring rack mini profiler", :green
|
31
|
+
|
32
|
+
Bundler.with_unbundled_env do
|
33
|
+
run "bundle exec rails g rack_mini_profiler:install"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'boring_generators/generator_helper'
|
4
|
+
|
5
|
+
module Boring
|
6
|
+
module RailsErd
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
include BoringGenerators::GeneratorHelper
|
9
|
+
|
10
|
+
desc 'Adds rails-erd gem to the app for generating ERD diagrams'
|
11
|
+
|
12
|
+
def add_rails_erd_gem
|
13
|
+
if gem_installed?("rails-erd")
|
14
|
+
say "rails-erd is already in the Gemfile, skipping it ...", :yellow
|
15
|
+
else
|
16
|
+
say "Adding rails-erd gem", :green
|
17
|
+
gem_content = <<~RUBY
|
18
|
+
\n
|
19
|
+
\tgem "rails-erd"
|
20
|
+
RUBY
|
21
|
+
insert_into_file "Gemfile", gem_content, after: /group :development do/
|
22
|
+
bundle_install
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def configure_rails_erd_gem
|
27
|
+
say 'Configuring rails-erd gem', :green
|
28
|
+
|
29
|
+
Bundler.with_unbundled_env do
|
30
|
+
run 'bundle exec rails g erd:install'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module Sentry
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
desc 'Adds Sentry to the app'
|
8
|
+
|
9
|
+
class_option :use_env_variable, type: :boolean, aliases: '-ev',
|
10
|
+
desc: 'Use ENV variable for Sentry. By default Rails credentials will be used.'
|
11
|
+
class_option :breadcrumbs_logger, type: :array, aliases: '-bl', default: [:active_support_logger, :http_logger],
|
12
|
+
desc: 'Set the breadcrumbs logger. By default [:active_support_logger, :http_logger] will be used.'
|
13
|
+
|
14
|
+
def add_sentry_gems
|
15
|
+
say 'Adding Sentry gem', :green
|
16
|
+
|
17
|
+
Bundler.with_unbundled_env do
|
18
|
+
run 'bundle add sentry-ruby sentry-rails'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def configure_sentry_gem
|
23
|
+
say 'Configuring Sentry gem', :green
|
24
|
+
|
25
|
+
@sentry_dsn_key = sentry_dsn_key
|
26
|
+
@breadcrumbs_logger_options = options[:breadcrumbs_logger].map(&:to_sym)
|
27
|
+
|
28
|
+
template 'sentry.rb', 'config/initializers/sentry.rb'
|
29
|
+
|
30
|
+
show_alert_message
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def sentry_dsn_key
|
36
|
+
if options[:use_env_variable]
|
37
|
+
"ENV['SENTRY_DSN_KEY']"
|
38
|
+
else
|
39
|
+
"Rails.application.credentials.dig(:sentry, :dsn_key)"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def show_alert_message
|
44
|
+
say "❗️❗️\nThe DSN key for Sentry will be used from `#{sentry_dsn_key}`. You can change this value if it doesn't match with your app.\n", :yellow
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "boring_generators/generator_helper"
|
4
|
+
|
5
|
+
module Boring
|
6
|
+
module Vcr
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
include BoringGenerators::GeneratorHelper
|
9
|
+
|
10
|
+
desc "Adds VCR to the application"
|
11
|
+
source_root File.expand_path("templates", __dir__)
|
12
|
+
|
13
|
+
class_option :testing_framework,
|
14
|
+
type: :string,
|
15
|
+
alias: "-tf",
|
16
|
+
default: "minitest",
|
17
|
+
enum: %w[rspec minitest],
|
18
|
+
desc:
|
19
|
+
"Tell us which test framework you are using. Defaults to minitest"
|
20
|
+
|
21
|
+
class_option :stubbing_libraries,
|
22
|
+
type: :array,
|
23
|
+
alias: "-sl",
|
24
|
+
default: ["webmock"],
|
25
|
+
enum: %w[webmock typhoeus faraday excon],
|
26
|
+
desc:
|
27
|
+
"Tell us stubbing library you want to use separated by space. Defaults to webmock"
|
28
|
+
|
29
|
+
def verify_presence_of_test_helper
|
30
|
+
return if rspec? || (minitest? && File.exist?("test/test_helper.rb"))
|
31
|
+
|
32
|
+
say "We couldn't find test/test_helper.rb. Please configure Minitest and rerun the generator.",
|
33
|
+
:red
|
34
|
+
|
35
|
+
abort
|
36
|
+
end
|
37
|
+
|
38
|
+
def verify_presence_of_rails_helper
|
39
|
+
return if minitest? || (rspec? && File.exist?("spec/rails_helper.rb"))
|
40
|
+
|
41
|
+
say "We couldn't find spec/rails_helper.rb. Please configure RSpec and rerun the generator. Consider running `rails generate boring:rspec:install` to set up RSpec.",
|
42
|
+
:red
|
43
|
+
|
44
|
+
abort
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_vcr_gem
|
48
|
+
say "Adding VCR gems to Gemfile", :green
|
49
|
+
|
50
|
+
check_and_install_gem "vcr", group: :test
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_stubbing_library_gems
|
54
|
+
say "Adding stubbing library gems to Gemfile", :green
|
55
|
+
|
56
|
+
options[:stubbing_libraries].uniq.each do |stubbing_library|
|
57
|
+
check_and_install_gem stubbing_library, group: :test
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def setup_vcr_for_rspec
|
62
|
+
return unless rspec?
|
63
|
+
|
64
|
+
say "Setting up VCR for RSpec", :green
|
65
|
+
|
66
|
+
@stubbing_libraries = format_stubbing_libraries
|
67
|
+
|
68
|
+
template("rspec/vcr.rb", "spec/support/vcr.rb")
|
69
|
+
|
70
|
+
unless all_support_files_are_required?
|
71
|
+
inject_into_file "spec/rails_helper.rb",
|
72
|
+
"require 'support/vcr'\n\n",
|
73
|
+
before: /\A/
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def setup_vcr_for_minitest
|
78
|
+
return unless minitest?
|
79
|
+
|
80
|
+
say "Setting up VCR for Minitest", :green
|
81
|
+
|
82
|
+
vcr_config = <<~RUBY
|
83
|
+
require "vcr"
|
84
|
+
|
85
|
+
VCR.configure do |c|
|
86
|
+
c.cassette_library_dir = "test/vcr_cassettes"
|
87
|
+
c.hook_into #{format_stubbing_libraries}
|
88
|
+
c.ignore_localhost = true
|
89
|
+
c.allow_http_connections_when_no_cassette = true
|
90
|
+
end
|
91
|
+
RUBY
|
92
|
+
|
93
|
+
inject_into_file "test/test_helper.rb", vcr_config, end: /^end\s*\Z/m
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def format_stubbing_libraries
|
99
|
+
options[:stubbing_libraries]
|
100
|
+
.map { |stubbing_library| ":#{stubbing_library}" }
|
101
|
+
.join(", ")
|
102
|
+
end
|
103
|
+
|
104
|
+
def rspec?
|
105
|
+
options[:testing_framework].to_s == "rspec"
|
106
|
+
end
|
107
|
+
|
108
|
+
def minitest?
|
109
|
+
options[:testing_framework].to_s == "minitest"
|
110
|
+
end
|
111
|
+
|
112
|
+
def all_support_files_are_required?
|
113
|
+
line_to_check =
|
114
|
+
"Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f }"
|
115
|
+
rails_file_content_array = File.readlines("spec/rails_helper.rb")
|
116
|
+
rails_file_content_array.any? do |line|
|
117
|
+
line !~ /^\s*#/ &&
|
118
|
+
(
|
119
|
+
line.include?(line_to_check) ||
|
120
|
+
line.include?(line_to_check.gsub("'", '"'))
|
121
|
+
)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'boring_generators/generator_helper'
|
4
|
+
|
2
5
|
module Boring
|
3
6
|
module Webmock
|
4
7
|
class InstallGenerator < Rails::Generators::Base
|
8
|
+
include BoringGenerators::GeneratorHelper
|
9
|
+
|
5
10
|
desc "Adds webmock gem to the application"
|
6
11
|
|
7
12
|
SUPPORTED_TEST_FRAMEWORKS = %w[rspec minitest]
|
8
13
|
|
9
|
-
# can't use "test_framework" option which would be a good naming for this because it's being used by Rails::Generator::Base.
|
14
|
+
# can't use "test_framework" option which would be a good naming for this because it's being used by Rails::Generator::Base. Rails will override this value if we use test_framework so prefixing with "app_" here
|
10
15
|
class_option :app_test_framework,
|
11
16
|
type: :string,
|
12
17
|
desc: "Tell us the framework you use for writing tests in your application. Supported options are #{SUPPORTED_TEST_FRAMEWORKS}",
|
@@ -29,11 +34,7 @@ module Boring
|
|
29
34
|
def add_webmock_gem
|
30
35
|
say "Adding webmock gem", :green
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
Bundler.with_unbundled_env do
|
35
|
-
run "bundle install"
|
36
|
-
end
|
37
|
+
check_and_install_gem "webmock", group: :test
|
37
38
|
end
|
38
39
|
|
39
40
|
def configure_webmock
|