-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtldr_web.rb
86 lines (71 loc) · 2.1 KB
/
tldr_web.rb
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
# frozen_string_literal: true
# Run the template, e.g.
# rails new -T -d postgresql -a propshaft -css tailwind -m ../path/to/this/file
gsub_file 'Gemfile', /^gem 'jbuilder'/, '# gem \'jbuilder\''
append_to_file 'Gemfile', <<~RUBY
gem 'devise'
gem 'cssbundling-rails'
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem 'factory_bot'
gem 'shoulda-matchers'
gem 'database_cleaner-active_record'
gem 'faker'
gem 'vcr'
gem 'webmock'
end
RUBY
after_bundle do
# Install Devise
run 'rails generate devise:install'
run 'rails generate devise User'
# Install Rspec
run 'rails generate rspec:install'
# Enable the spec/support folder
gsub_file 'spec/rails_helper.rb',
/# Dir\[Rails.root.join\('spec', 'support', '\*\*', '\*\.rb'\)\].sort.each { \|f\| require f \}/, "Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }"
# Create spec/support folder
run 'mkdir -p spec/support'
# Add shoulda matchers support file
create_file 'spec/support/shoulda_matchers.rb', <<-RUBY
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
RUBY
# Add database_cleaner support file
create_file 'spec/support/database_cleaner.rb', <<-RUBY
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do |example|
DatabaseCleaner.strategy = if %i[feature request].include?(example.metadata[:type])
:truncation
else
:transaction
end
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
RUBY
# Add FactoryBot support file
create_file 'spec/support/factory_bot.rb', <<-RUBY
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
RUBY
# Devise localhost configs
inject_into_file 'config/environments/development.rb', before: "end\n" do
<<~RUBY
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
RUBY
end
end