| name | new-gem |
|---|---|
| description | Bootstrap a new Ruby gem with RSpec, RuboCop, rubocop-rspec, SimpleCov, CI, and standard metadata. |
Bootstrap a new Ruby gem using the arguments provided: $ARGUMENTS
The arguments should be parsed as: GEM_NAME followed by an optional summary in quotes.
Example: /new-gem my_gem "A short description of the gem"
All file edits, file creation, shell commands (bundle gem, bundle install,
bundle exec rspec, bundle exec rubocop, rubocop -A), and generated-file
modifications described in the steps below are pre-authorized by the user.
Proceed through every step without pausing for confirmation. Only stop to ask
if something fails unexpectedly or falls outside the scope of these steps.
-
Scaffold with
bundle gemusing these flags:--test=rspec--ci=github--changelog--linter=rubocop--mit--no-git(we manage git separately)- Do NOT use
--rubocop(removed;--linter=rubocopcovers it). - Do NOT use
--extunless the user explicitly requests a C extension.
-
Add
rubocop-rspec,rubocop-performance, andsimplecovto the Gemfile and update.rubocop.ymlto load the RuboCop plugins (notrequire, which is deprecated in newer RuboCop):Add to the Gemfile:
gem "simplecov", require: false
Update
.rubocop.yml:plugins: - rubocop-rspec - rubocop-performance AllCops: NewCops: enable TargetRubyVersion: 3.2
Add SimpleCov to the top of
spec/spec_helper.rb(before any other requires):require "simplecov" SimpleCov.start
-
Fill in gemspec metadata:
- Set
spec.summaryto the provided summary (or a sensible placeholder). - Set
spec.descriptionto a longer form of the summary. - Remove or fill in any
TODOstrings so the gemspec is immediately valid. - Set
spec.homepage,spec.metadata["source_code_uri"], andspec.metadata["changelog_uri"]to placeholder URLs the user can update later. - Ensure
spec.required_ruby_versionis set to>= 3.2.
- Set
-
Create a smoke spec at
spec/<gem_name>_spec.rb:# frozen_string_literal: true RSpec.describe <GemModule> do it "has a version number" do expect(<GemModule>::VERSION).not_to be_nil end end
-
Create
.rspecwith:--require spec_helper --format documentation --color -
Create
.gitignorewith:.rspec_status -
Run validation:
bundle installbundle exec rspec— confirm specs pass.bundle exec rubocop— fix any auto-correctable offenses withrubocop -A, then report remaining issues.
-
Report results to the user: list created files, test results, and any RuboCop issues that need manual attention.
Run this section only when the user asks to push the gem to GitHub. These steps were proven out on the polysemic gem.
-
Confirm visibility with the user (public vs private) — this is a hard-to-reverse choice for anything sensitive, so ask before creating.
-
Update gemspec URLs from the placeholders to the real repo:
spec.homepage = "https://github.com/<owner>/<gem>"spec.metadata["source_code_uri"] = "https://github.com/<owner>/<gem>"spec.metadata["changelog_uri"] = "https://github.com/<owner>/<gem>/blob/main/CHANGELOG.md"
-
Replace placeholders in generated files:
LICENSE.txt— replaceCopyright (c) <YEAR> TODO: Write your namewith the real author.- Author/email in the gemspec, if still
TODO.
-
Add
/coverage/to.gitignoreso SimpleCov output isn't committed. -
Init and commit:
git init -b main git add <explicit list of files — do NOT use "git add ." since coverage/ may exist> git commit -m "Initial commit: scaffold <gem> gem"
-
Create the repo and push:
gh repo create <owner>/<gem> \ --private \ # or --public per user choice --description "<gem summary>" \ --source=. --remote=origin --push
-
If the push fails, diagnose and recover:
Permission denied (publickey)— the default SSH config can't reach GitHub for this account. Ask the user how they'd like to authenticate (e.g. a per-account SSH host alias they've configured locally). Do not guess the alias. Once they supply it,git remote set-url origin <their-url>andgit push -u origin main.refusing to allow an OAuth App to create or update workflow ... without 'workflow' scope— the gh token lacks theworkflowscope needed to push.github/workflows/main.yml. Either switch to SSH or ask the user to rungh auth refresh -s workflow.
- Do not create unnecessary files beyond what
bundle gemand the steps above produce. - Prefer editing generated files over creating new ones.
- Do not commit unless the user asks. The user has a separate
/tasteful-commitscommand for that.
- Prompt the user for author name, email, and GitHub username instead of placeholders.
- Automate publishing to RubyGems.org (
gem build+gem push).