{"id":28507648,"url":"https://github.com/moznion/be-let-it-be","last_synced_at":"2026-03-07T07:33:00.798Z","repository":{"id":297992576,"uuid":"998515994","full_name":"moznion/be-let-it-be","owner":"moznion","description":"A command-line tool that automatically converts RSpec's `let` and `let!` declarations to `let_it_be` where it's safe to do so. The tool runs your tests after each conversion to ensure they still pass, making the optimization process safe and reliable.","archived":false,"fork":false,"pushed_at":"2026-02-09T14:01:04.000Z","size":40,"stargazers_count":9,"open_issues_count":8,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-09T18:48:33.746Z","etag":null,"topics":["rspec","ruby","test-performance","test-prof"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/be-let-it-be","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moznion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-08T19:18:34.000Z","updated_at":"2025-09-19T07:41:46.000Z","dependencies_parsed_at":"2026-02-09T16:03:59.485Z","dependency_job_id":null,"html_url":"https://github.com/moznion/be-let-it-be","commit_stats":null,"previous_names":["moznion/be-let-it-be"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/moznion/be-let-it-be","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Fbe-let-it-be","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Fbe-let-it-be/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Fbe-let-it-be/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Fbe-let-it-be/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moznion","download_url":"https://codeload.github.com/moznion/be-let-it-be/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Fbe-let-it-be/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30209736,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T05:23:27.321Z","status":"ssl_error","status_checked_at":"2026-03-07T05:00:17.256Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rspec","ruby","test-performance","test-prof"],"created_at":"2025-06-08T21:00:28.959Z","updated_at":"2026-03-07T07:33:00.779Z","avatar_url":"https://github.com/moznion.png","language":"Ruby","readme":"# be-let-it-be\n\n[![Ruby](https://github.com/moznion/be-let-it-be/actions/workflows/main.yml/badge.svg)](https://github.com/moznion/be-let-it-be/actions/workflows/main.yml) [![Gem Version](https://badge.fury.io/rb/be-let-it-be.svg?icon=si%3Arubygems)](https://badge.fury.io/rb/be-let-it-be)\n\nA command-line tool that automatically converts RSpec's `let` and `let!` declarations to `let_it_be` where it's safe to do so. The tool runs your tests after each conversion to ensure they still pass, making the optimization process safe and reliable.\n\n## Motivation\n\nOne of the main motivations is to improve test speed.\n\n### What is `let_it_be`?\n\n`let_it_be` is a helper provided by the [test-prof](https://github.com/test-prof/test-prof) gem that caches test data across examples instead of recreating it for each test. This can significantly improve test performance, especially for expensive object creation like database records.\n\n### Performance Benefits\n\nUsing `let_it_be` can significantly improve test performance by:\n\n- Reducing database queries\n- Minimizing object instantiation overhead\n- Sharing immutable test data across examples\n\nPerformance gains are especially noticeable with:\n\n- Factory-created database records\n- Complex object initialization\n- Large test suites\n\n## How It Works\n\n1. Parse: Analyzes your RSpec file using Ruby's Abstract Syntax Tree\n2. Identify: Finds all `let` and `let!` declarations\n3. Convert \u0026 Test: For each declaration:\n  - Converts it to `let_it_be`\n  - Runs your tests\n  - Keeps the change if tests pass, reverts if they fail\n4. Save: Writes the successfully converted file, or it outputs the result if it's in dryrun mode\n\n## Example Conversion\n\nBefore:\n\n```ruby\nRSpec.describe User do\n  let!(:admin) { create(:user, admin: true) }\n  let(:user) { create(:user) }\n  let(:posts) { user.posts }\n  let(:mutable_array) { [] }\n\n  it \"modifies the array\" do\n    mutable_array \u003c\u003c 1\n    expect(mutable_array).to eq([1])\n  end\nend\n```\n\nAfter:\n\n```ruby\nRSpec.describe User do\n  let_it_be(:admin) { create(:user, admin: true) }\n  let_it_be(:user) { create(:user) }\n  let(:posts) { user.posts }  # Kept as 'let' due to dependency\n  let(:mutable_array) { [] }  # Kept as 'let' because tests modify it\n\n  it \"modifies the array\" do\n    mutable_array \u003c\u003c 1\n    expect(mutable_array).to eq([1])\n  end\nend\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngroup :development, :test do\n  gem 'be-let-it-be'\nend\n```\n\nAnd then execute:\n\n```bash\n$ bundle install\n```\n\nOr install it yourself as:\n\n```bash\n$ gem install be-let-it-be\n```\n\n## Prerequisites\n\n- Ruby 3.3.0 or higher\n- Your project must have [test-prof](https://github.com/test-prof/test-prof) installed, as `let_it_be` is a feature provided by that gem\n\n## Usage\n\n### Basic Usage\n\nConvert a single spec file:\n\n```bash\nbe-let-it-be convert spec/models/user_spec.rb\n```\n\n### Options\n\n- `--dryrun` - Show what would be converted without making actual changes\n- `--dryrun-exit-code` - Exit code to use in dryrun mode when any convertible declarations are present (default: 1)\n- `--verbose` - Display detailed processing information\n- `--rspec_cmd` - Customize the RSpec command used for verification (default: \"rspec\")\n\n### Examples\n\n```bash\n# Dry-run to preview changes\nbe-let-it-be convert spec/models/user_spec.rb --dryrun\n\n# Verbose output for debugging\nbe-let-it-be convert spec/models/user_spec.rb --verbose\n\n# Use custom RSpec command\nbe-let-it-be convert spec/models/user_spec.rb --rspec_cmd=\"rspec --format progress\"\n```\n\n## When NOT to Use `let_it_be`\n\nThe tool automatically detects when conversions would break tests, but it's good to understand when `let_it_be` isn't appropriate:\n\n- Mutable objects: When tests modify the object state\n- Test-specific state: When the value depends on test-specific setup\n- Fresh instances: When each test requires a completely new instance\n\n## Current Limitations\n\n- Originally, the replacement of `let` and `let!` should adopt the combination that provides the most optimized execution time. However, attempting to do so would likely cause combinatorial explosion, making it non-trivial to implement. Therefore, we currently use a simple approach of replacing them in order of appearance. We plan to address this optimization in the future.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/moznion/be-let-it-be. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/moznion/be-let-it-be/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the be-let-it-be project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/moznion/be-let-it-be/blob/main/CODE_OF_CONDUCT.md).\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Fbe-let-it-be","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoznion%2Fbe-let-it-be","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Fbe-let-it-be/lists"}