Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running rake task from outside of the Rails app directory is not working as expected #30

Open
etagwerker opened this issue Dec 20, 2024 · 0 comments

Comments

@etagwerker
Copy link
Member

Environment

Ruby:

➜  fastruby.io git:(main) ✗ ruby -v
ruby 3.1.6p260 (2024-05-29 revision a777087be6) [arm64-darwin23]

Rails Stats:

➜  fastruby.io git:(main) ✗ gem update rails_stats
Updating installed gems
Updating rails_stats
Fetching rails_stats-2.0.1.gem
Successfully installed rails_stats-2.0.1
Parsing documentation for rails_stats-2.0.1
Installing ri documentation for rails_stats-2.0.1
Done installing documentation for rails_stats after 0 seconds
Parsing documentation for rails_stats-2.0.1
Done installing documentation for rails_stats after 0 seconds
Gems updated: rails_stats

Current

Calling rake stats with parameters (requesting JSON output) is working as expected:

➜  fastruby.io git:(main) ✗ bundle exec rake stats\[fastruby.io,json\]

Directory: /Users/etagwerker/Projects/ombulabs/fastruby.io

[{"name":"Mailers","files":"4","lines":"63","loc":"55","classes":"4","methods":"7","m_over_c":"1","loc_over_m":"5"},{"name":"Models","files":"6","lines":"106","loc":"92","classes":"6","methods":"7","m_over_c":"1","loc_over_m":"11"},{"name":"Dashboards","files":"3","lines":"275","loc":"161","classes":"3","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Libs","files":"1","lines":"111","loc":"87","classes":"1","methods":"1","m_over_c":"1","loc_over_m":"85"},{"name":"Workers","files":"2","lines":"18","loc":"14","classes":"2","methods":"2","m_over_c":"1","loc_over_m":"5"},{"name":"Fields","files":"2","lines":"14","loc":"12","classes":"2","methods":"2","m_over_c":"1","loc_over_m":"4"},{"name":"Javascripts","files":"20","lines":"8604","loc":"8380","classes":"0","methods":"1853","m_over_c":"0","loc_over_m":"2"},{"name":"Jobs","files":"1","lines":"2","loc":"2","classes":"1","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Controllers","files":"13","lines":"502","loc":"396","classes":"13","methods":"59","m_over_c":"4","loc_over_m":"4"},{"name":"Helpers","files":"4","lines":"27","loc":"22","classes":"0","methods":"3","m_over_c":"0","loc_over_m":"5"},{"name":"Services","files":"3","lines":"134","loc":"109","classes":"3","methods":"14","m_over_c":"4","loc_over_m":"5"},{"name":"Channels","files":"2","lines":"8","loc":"8","classes":"2","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Libraries","files":"1","lines":"126","loc":"91","classes":"2","methods":"7","m_over_c":"3","loc_over_m":"11"},{"name":"Configuration","files":"37","lines":"726","loc":"293","classes":"1","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Gems","files":"2","lines":"37","loc":"22","classes":"1","methods":"1","m_over_c":"1","loc_over_m":"20"},{"name":"Controller Tests","files":"8","lines":"480","loc":"396","classes":"0","methods":"1","m_over_c":"0","loc_over_m":"394"},{"name":"Spec Support","files":"5","lines":"214","loc":"79","classes":"0","methods":"2","m_over_c":"0","loc_over_m":"37"},{"name":"Feature Tests","files":"8","lines":"368","loc":"280","classes":"0","methods":"5","m_over_c":"0","loc_over_m":"54"},{"name":"Mailer Tests","files":"1","lines":"62","loc":"47","classes":"0","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Model Tests","files":"2","lines":"182","loc":"138","classes":"0","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Routing Tests","files":"1","lines":"45","loc":"40","classes":"0","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Service Tests","files":"1","lines":"20","loc":"17","classes":"0","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Total","files":"127","lines":"12124","loc":"10741","classes":"41","methods":"1964","m_over_c":"47","loc_over_m":"3","code_to_test_ratio":"0.1","total":true}]

Trying to generate the same report with console output is producing unexpected results:

➜  fastruby.io git:(main) ✗ bundle exec rake stats\[fastruby.io,stdout\]

Directory: /Users/etagwerker/Projects/ombulabs/fastruby.io

Could not find command "stats[fastruby.io,stdout]".
➜  fastruby.io git:(main) ✗ bundle exec rake stats\[fastruby.io,console\]

Directory: /Users/etagwerker/Projects/ombulabs/fastruby.io

Could not find command "stats[fastruby.io,console]".

Expected

As far as I know, calling the rake task with a format that is != json should generate a report like this one: https://gist.github.com/etagwerker/bc227cd1107a67483c4fe736bcd84c94

More Details

I tested v2.0.1 within a Rails application. Added this to my Gemfile:

group :development, :test do
  gem "rails_stats"
end

I can see that the right version is installed:

➜  fastruby.io git:(main) ✗ bundle info rails_stats
  * rails_stats (2.0.1)
	Summary: Analyze a Rails project
	Homepage: https://github.com/fastruby/rails_stats
	Path: /Users/etagwerker/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rails_stats-2.0.1

Running bundle exec rake stats works fine within the fastruby.io directory.

➜  fastruby.io git:(main) ✗ rake stats
The dependency `tzinfo-data` wasn't found. It may not be present in your Gemfile.lock. This often happens when a dependency isn't installed on your platform.
The dependency `tzinfo-data` wasn't found. It may not be present in your Gemfile.lock. This often happens when a dependency isn't installed on your platform.
+------------------------------------|------------|----------------+
|                               Name | Total Deps | 1st Level Deps |
+------------------------------------|------------|----------------+
|                     ombu_labs-auth | 70         | 5              |
|  administrate-field-active_storage | 59         | 2              |
|                  ombu_labs-hubspot | 55         | 3              |
|            ombu_labs-notifications | 50         | 3              |
|                  invisible_captcha | 46         | 1              |
|                              rails | 45         | 13             |
|                       administrate | 37         | 7              |
|                       sentry-rails | 32         | 2              |
| jekyll-external-link-accessibility | 30         | 2              |
|                  jekyll-images-cdn | 30         | 2              |
|                         sass-rails | 29         | 1              |
|                        rspec-rails | 28         | 7              |
|                     jekyll-authors | 27         | 1              |
|                  jekyll-categories | 27         | 1              |
|                        jekyll-feed | 27         | 1              |
|               jekyll-redirect-from | 27         | 1              |
|                             jekyll | 26         | 14             |
|         active_storage_validations | 25         | 4              |
|                        web-console | 25         | 4              |
|                          webpacker | 25         | 4              |
|                       dotenv-rails | 24         | 2              |
|                  factory_bot_rails | 24         | 2              |
|           rails-controller-testing | 18         | 3              |
|                      rubocop-rails | 16         | 3              |
|                         email_spec | 12         | 3              |
|                       html-proofer | 12         | 7              |
|                           capybara | 11         | 8              |
|                           standard | 11         | 2              |
|                    convertkit-ruby | 10         | 3              |
|                      rubocop-rspec | 10         | 1              |
|                        sentry-ruby | 10         | 3              |
|                       sidekiq-cron | 9          | 2              |
|                        friendly_id | 7          | 1              |
|                         aws-sdk-s3 | 6          | 3              |
|                           jbuilder | 5          | 1              |
|                               reek | 5          | 4              |
|                   shoulda-matchers | 5          | 1              |
|              spring-watcher-listen | 5          | 2              |
|                        rails_stats | 4          | 2              |
|                   image_processing | 3          | 2              |
|                             listen | 3          | 2              |
|                         overcommit | 3          | 3              |
|                 selenium-webdriver | 3          | 3              |
|                            sidekiq | 3          | 3              |
|                   dotenv_validator | 2          | 2              |
|                  font-awesome-sass | 2          | 1              |
|              rspec_junit_formatter | 2          | 1              |
|                    jekyll-titleize | 1          | 1              |
|                         next_rails | 1          | 1              |
|                               puma | 1          | 1              |
|                          rack-cors | 1          | 1              |
|                 rack-mini-profiler | 1          | 1              |
|                          recaptcha | 1          | 1              |
|                  sitemap_generator | 1          | 1              |
|                           uglifier | 1          | 1              |
|                             byebug | 0          | 0              |
|                    jekyll-paginate | 0          | 0              |
|                       newrelic_rpm | 0          | 0              |
|                               pagy | 0          | 0              |
|                                 pg | 0          | 0              |
|                             spring | 0          | 0              |
|                             stripe | 0          | 0              |
|                            timecop | 0          | 0              |
|                        tzinfo-data | 0          | 0              |
+------------------------------------|------------|----------------+

      Declared Gems   64
         Total Gems   219
  Unpinned Versions   40
        Github Refs   4

+----------------------+---------+---------+---------+---------+---------+-----+-------+
| Name                 | Files   | Lines   |     LOC | Classes | Methods | M/C | LOC/M |
+----------------------+---------+---------+---------+---------+---------+-----+-------+
| Channels             |       2 |       8 |       8 |       2 |       0 |   0 |     0 |
| Configuration        |      37 |     726 |     293 |       1 |       0 |   0 |     0 |
| Controller Tests     |       8 |     480 |     396 |       0 |       1 |   0 |   394 |
| Controllers          |      13 |     502 |     396 |      13 |      59 |   4 |     4 |
| Dashboards           |       3 |     275 |     161 |       3 |       0 |   0 |     0 |
| Feature Tests        |       8 |     368 |     280 |       0 |       5 |   0 |    54 |
| Fields               |       2 |      14 |      12 |       2 |       2 |   1 |     4 |
| Gems                 |       2 |      37 |      22 |       1 |       1 |   1 |    20 |
| Helpers              |       4 |      27 |      22 |       0 |       3 |   0 |     5 |
| Javascripts          |      20 |    8604 |    8380 |       0 |    1853 |   0 |     2 |
| Jobs                 |       1 |       2 |       2 |       1 |       0 |   0 |     0 |
| Libraries            |       1 |     126 |      91 |       2 |       7 |   3 |    11 |
| Libs                 |       1 |     111 |      87 |       1 |       1 |   1 |    85 |
| Mailer Tests         |       1 |      62 |      47 |       0 |       0 |   0 |     0 |
| Mailers              |       4 |      63 |      55 |       4 |       7 |   1 |     5 |
| Model Tests          |       2 |     182 |     138 |       0 |       0 |   0 |     0 |
| Models               |       6 |     106 |      92 |       6 |       7 |   1 |    11 |
| Routing Tests        |       1 |      45 |      40 |       0 |       0 |   0 |     0 |
| Service Tests        |       1 |      20 |      17 |       0 |       0 |   0 |     0 |
| Services             |       3 |     134 |     109 |       3 |      14 |   4 |     5 |
| Spec Support         |       5 |     214 |      79 |       0 |       2 |   0 |    37 |
| Workers              |       2 |      18 |      14 |       2 |       2 |   1 |     5 |
+----------------------+---------+---------+---------+---------+---------+-----+-------+
| Code                 |     101 |   10753 |    9744 |      41 |    1956 |  47 |     2 |
| Tests                |      26 |    1371 |     997 |       0 |       8 |   0 |   122 |
| Total                |     127 |   12124 |   10741 |      41 |    1964 |  47 |     3 |
+----------------------+---------+---------+---------+---------+---------+-----+-------+
  Code LOC: 9744     Test LOC: 997     Code to Test Ratio: 1:0.1  Files: 127
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant