Skip to content

Commit

Permalink
capybara config
Browse files Browse the repository at this point in the history
  • Loading branch information
jparr committed Dec 7, 2023
1 parent 61d4d7a commit 9b9284d
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# list environment variables in a .env file
# prefer rails credentials `rails credentials:edit`
# required variables can be specified in `initializers/dotenv.rb`
# generate a template file with `$ dotenv -t .env`
# SOMEVARIABLE=xxxxxsecretvariablexxxxx
# SOMEVARIABLE=xxxxxenvvariablexxxxx
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.2
3.2.2
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ A Rails Application Template for use at Ministry of Velocity

Reference: [Rails Application Templates](https://guides.rubyonrails.org/rails_application_templates.html)


### Locally
```bash
rails new <myproject> --skip-test --skip-jbuilder -d postgresql -c tailwind -m ./template.rb
```

### Remotely
```bash
rails new <myproject> --skip-test --skip-jbuilder -d postgresql -c tailwind -m 'https://raw.githubusercontent.com/jparr/minifast-rails/main/template.rb'
```
36 changes: 36 additions & 0 deletions README_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

### Local dev
Start redis
```bash
brew services start redis
```

start dev server
```bash
dev
```


* Deployment instructions

* ...
29 changes: 29 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'capybara/cuprite'
require 'capybara/rspec'

Capybara.default_driver = :rack_test
Capybara.javascript_driver = :cuprite
Capybara.server = :puma, {Silent: true}

Capybara.register_driver(:cuprite) do |app|
Capybara::Cuprite::Driver.new(
app,
window_size: [1920, 1080],
headless: false
)
end

module FakeCapybaraPage
def page
Nokogiri::HTML::DocumentFragment.parse(response.body)
end
end

RSpec.configure do |config|
config.include FakeCapybaraPage, type: :request
config.include Capybara::RSpecMatchers, type: :request
config.include ActionView::RecordIdentifier, type: :request
config.include Capybara::RSpecMatchers, type: :component
config.before(:each, type: :system) { driven_by(:rack_test) }
config.before(:each, js: true, type: :system) { driven_by(:cuprite) }
end
5 changes: 5 additions & 0 deletions spec/support/view_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'view_component/test_helpers'

RSpec.configure do |config|
config.include ViewComponent::TestHelpers, type: :component
end
8 changes: 6 additions & 2 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def rails_7_or_newer?

gem_group :test do
gem 'capybara'
gem 'selenium-webdriver'
gem 'cuprite'
gem 'shoulda-matchers', '~> 5.0'
gem 'webdrivers'
end
Expand All @@ -70,8 +70,11 @@ def rails_7_or_newer?
after_bundle do
generate 'rspec:install'
directory 'spec/support'
uncomment_lines 'spec/rails_helper.rb', /'spec', 'support', '\*\*', '\*.rb'/

copy_file '.erb-lint.yml'
copy_file '.rubocop.yml'
copy_file 'README_template.md', 'README.md'

run 'bundle binstubs erb_lint'
run 'bundle binstubs rubocop'
Expand All @@ -81,6 +84,7 @@ def rails_7_or_newer?

inject_into_file 'config/application.rb', after: 'config.load_defaults 7.0' do
<<-RUBY
config.view_component.generate.sidecar = true
config.generators do |generator|
Expand All @@ -102,7 +106,7 @@ def rails_7_or_newer?

# todo: better readme template

run 'bin/rubocop -A'
run 'bin/rubocop -a'

say 'App successfully created!', :green
end

0 comments on commit 9b9284d

Please sign in to comment.