Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: "CI"
name: CI
on:
push:
branches: ["master"]
branches: [ master ]
pull_request:
branches: ["master"]
branches: [ master ]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
Expand All @@ -12,26 +12,18 @@ concurrency:
jobs:
run_specs:
name: Rspec
runs-on: ubuntu-latest
runs-on: blacksmith-4vcpu-ubuntu-2404
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OutlawAndy Since this is public repo and running on Github, do we need to (or want to) switch to Blacksmith?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question. I don't know. blacksmith is significantly faster, but might be safest to switch back. 👍

timeout-minutes: 10
env:
CI: true
RAILS_ENV: test

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Run specs
run: bundle exec rspec --format documentation --format RspecJunitFormatter --out tmp/rspec.xml

- name: Publish Rspec Test Results
uses: mikepenz/action-junit-report@v4
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
with: { bundler-cache: true }
- run: bundle exec rspec --format documentation --format RspecJunitFormatter --out tmp/rspec.xml
- uses: mikepenz/action-junit-report@v6
if: success() || failure()
with:
check_name: Rspec Test Results
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ log

*.gem
.history

.DS_Store
15 changes: 12 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in rolemodel_rails.gemspec
# Specify your gem's dependencies in rolemodel-rails.gemspec.
gemspec

# Gems which are necessary to boot the included test applications,
# but should not be bundled with this gem may be added here.
gem 'pg'
gem 'propshaft'
gem 'puma'
gem 'stimulus-rails'
gem 'turbo-rails'

# Start debugger with binding.b [https://github.com/ruby/debug]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the alias or keep it long form (binding.break)? Fine either way if binding.b is common knowledge.

gem 'debug', '>= 1.0.0'
57 changes: 41 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rolemodel_rails (0.27.2)
rolemodel-rails (1.0.0)
rails (> 7.1)

GEM
Expand Down Expand Up @@ -90,7 +90,10 @@ GEM
connection_pool (3.0.2)
crass (1.0.6)
date (3.5.1)
diff-lcs (1.5.0)
debug (1.11.1)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.6.2)
drb (2.2.3)
erb (6.0.1)
erubi (1.13.1)
Expand Down Expand Up @@ -137,17 +140,27 @@ GEM
nokogiri (1.19.0)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.19.0-x86_64-linux-gnu)
racc (~> 1.4)
parallel (1.27.0)
parser (3.3.8.0)
ast (~> 2.4.1)
racc
pg (1.6.3)
pg (1.6.3-arm64-darwin)
pp (0.6.3)
prettyprint
prettyprint (0.2.0)
prism (1.9.0)
propshaft (1.3.1)
actionpack (>= 7.0.0)
activesupport (>= 7.0.0)
rack
psych (5.3.1)
date
stringio
puma (7.2.0)
nio4r (~> 2.0)
racc (1.8.1)
rack (3.2.4)
rack-session (2.1.1)
Expand Down Expand Up @@ -196,19 +209,19 @@ GEM
regexp_parser (2.10.0)
reline (0.6.3)
io-console (~> 0.5)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.1)
rspec (3.13.2)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.6)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.1)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.8)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.1)
rspec-support (~> 3.13.0)
rspec-support (3.13.7)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.78.0)
Expand All @@ -232,10 +245,15 @@ GEM
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
securerandom (0.4.1)
stimulus-rails (1.3.4)
railties (>= 6.0.0)
stringio (3.2.0)
thor (1.5.0)
timeout (0.6.0)
tsort (0.2.0)
turbo-rails (2.0.23)
actionpack (>= 7.1.0)
railties (>= 7.1.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.1.4)
Expand All @@ -250,18 +268,25 @@ GEM
zeitwerk (2.7.4)

PLATFORMS
ruby
arm64-darwin-25
x86_64-linux

DEPENDENCIES
benchmark
bundler (~> 4)
debug (>= 1.0.0)
generator_spec (~> 0.10)
pg
propshaft
puma
rake (~> 13)
rolemodel_rails!
rolemodel-rails!
rspec (~> 3)
rspec_junit_formatter
rubocop
rubocop-rails
stimulus-rails
turbo-rails

BUNDLED WITH
4.0.5
4.0.8
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Attempts to solve the pain of:

## Precondition

The rolemodel_rails gem expects to be added to an existing Rails project. Typically those are started with:
The rolemodel-rails gem expects to be added to an existing Rails project. Typically those are started with:

```shell
rails new <app-name> --javascript=webpack --database=postgresql --skip-test
Expand All @@ -28,9 +28,7 @@ rails db:create
Add this line to your application's Gemfile:

```ruby
group :development do
gem 'rolemodel_rails', github: 'RoleModel/rolemodel_rails'
end
gem 'rolemodel-rails', group: :development
```

And then execute:
Expand Down Expand Up @@ -115,7 +113,7 @@ e.g.
bin/new_generator testing/fantasitic_specs 'A Fantastic Testing Framework'
```

We use the embeded Rails apps (`example_rails*`) to test generators against. They reference the rolemodel_rails gem by local path,
We use the embeded Rails apps (`example_rails*`) to test generators against. They reference the rolemodel-rails gem by local path,
so you can navigate into one of them and run your generator for immediate feedback while developing.

> [!IMPORTANT]
Expand Down Expand Up @@ -146,6 +144,19 @@ RSpec.describe Rolemodel::Testing::JasminePlaywrightGenerator, type: :generator
end
```

If the generator you're testing depends on being run after another generator, you should run that one first.

e.g.

```ruby
RSpec.describe Rolemodel::MyGenerator, type: :generator do
before do
run_generator_against_test_app(generator: ::Rolemodel::PrereqGenerator)
run_generator_against_test_app
end
end
```

Additional information about testing generators and the available assertions & matchers can be found at the following resources.

* [Rails Guide](https://guides.rubyonrails.org/generators.html#testing-generators)
Expand Down
10 changes: 5 additions & 5 deletions bin/bump_version
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require 'bundler/setup'
require 'rolemodel_rails/version'
require 'rolemodel/version'
require 'rake/file_list'
require 'thor'

Expand All @@ -17,15 +17,15 @@ class VersionBumper < Thor::Group
source_root File.expand_path('../', __FILE__)

def bump_version
gsub_file 'lib/rolemodel_rails/version.rb', /^ VERSION = .*/, " VERSION = '#{new_version_string}'"
gsub_file 'lib/rolemodel/version.rb', /^ VERSION = .*/, " VERSION = '#{new_version_string}'"
end

def update_lockfile
run_clean_bundle_install
end

def build_gem
run 'gem build rolemodel_rails.gemspec'
run 'gem build rolemodel-rails.gemspec'
end

def update_current_example_app
Expand Down Expand Up @@ -54,9 +54,9 @@ class VersionBumper < Thor::Group
def current_version
Gem::Version.new(
if options.patch?
RolemodelRails::VERSION + '.0'
Rolemodel::VERSION + '.0'
else
options[:version] || RolemodelRails::VERSION
options[:version] || Rolemodel::VERSION
end
)
end
Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "rolemodel_rails"
require "rolemodel-rails"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
35 changes: 35 additions & 0 deletions bin/dummy_app_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require "rails/generators/rails/app/app_generator"

Rails::Generators::AppGenerator.define_method(:rails_version_specifier) do
"~> #{RAILS_VERSION}"
end

class BuilderClass < Rails::AppBuilder
# inherit these from Rolemodel::Rails
def ruby_version = nil
def node_version = nil

def generate_test_dummy
invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path) ], {
dummy_app: true,
force: true,
database: 'postgresql',
javascript: 'webpack',
skip_bootsnap: true,
skip_brakeman: true,
skip_bundler_audit: true,
skip_ci: true,
skip_git: true,
skip_jbuilder: true,
skip_kamal: true,
skip_rubocop: true,
skip_solid: true,
skip_test: true,
skip_thruster: true,
}
end

def test_dummy_config
template 'boot.rb', "#{dummy_path}/config/boot.rb", force: true
end
end
14 changes: 14 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.

ENGINE_ROOT = File.expand_path("..", __dir__)
ENGINE_PATH = File.expand_path("../lib/rolemodel/engine", __dir__)
APP_PATH = File.expand_path("../example_rails8/config/application", __dir__)

# Set up gems listed in the Gemfile.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])

require "rails/all"
require "rails/engine/commands"
36 changes: 19 additions & 17 deletions bin/recreate_current_example
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#!/usr/bin/env bash
RAILS_VERSION=`gem search ^rails$ --remote | grep -oE 'rails \((\d\.[0-9]+\.[0-9]+)\)' | head -1 | cut -d' ' -f2 | tr -d '()'`
MAJOR_VERSION_NUMBER=${RAILS_VERSION%%.*}
#!/usr/bin/env ruby

set -euo pipefail
IFS=$'\n\t'
set -vx
RAILS_VERSION = ARGV[0] || '8.1.2'

if ! gem list rails -i -v $RAILS_VERSION --silent; then
gem install rails -v $RAILS_VERSION
fi
require_relative 'dummy_app_builder'
RAILS_MAJOR_VERSION_NUMBER = Gem::Version.new(RAILS_VERSION).segments.first

rm -fr example_rails$MAJOR_VERSION_NUMBER
class RecreateCurrentExample < Rails::Generators::AppBase
source_root File.expand_path('templates', __dir__)

rails _"$RAILS_VERSION"_ new --skip-keeps --skip-git --skip-jbuilder -j webpack -d postgresql example_rails$MAJOR_VERSION_NUMBER
def recreate_example
shell.mute do
build(:generate_test_dummy)
build(:test_dummy_config)
end
end

cd example_rails$MAJOR_VERSION_NUMBER
private

bundle add --group development --path '..' --version '> 0.20' rolemodel_rails
bundle install
def dummy_path
@dummy_path ||= "./example_rails#{RAILS_MAJOR_VERSION_NUMBER}"
end

rm config/credentials.yml.enc
rm config/master.key
def get_builder_class = BuilderClass
end

cd -
RecreateCurrentExample.start(["--app-path=example_rails#{RAILS_MAJOR_VERSION_NUMBER}"])
2 changes: 1 addition & 1 deletion bin/recreate_legacy_example
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rails _"$RAILS_VERSION"_ new --skip-keeps --skip-git --skip-jbuilder -j webpack

cd example_rails7

bundle add --group development --path '..' --version '> 0.20' rolemodel_rails
bundle add --group development --path '..' --version '> 0.20' rolemodel-rails
bundle install

rm config/credentials.yml.enc
Expand Down
Loading