Skip to content

Commit

Permalink
Merge pull request #1 from nodematerial/nodematerial/translate
Browse files Browse the repository at this point in the history
Create Japanese documentation page.
  • Loading branch information
palkan committed Apr 29, 2024
2 parents 35ec461 + 1dfb9da commit 7d75cb2
Show file tree
Hide file tree
Showing 28 changed files with 2,935 additions and 47 deletions.
160 changes: 160 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
[![Gem Version](https://badge.fury.io/rb/test-prof.svg)](https://rubygems.org/gems/test-prof) [![Build](https://github.com/test-prof/test-prof/workflows/Build/badge.svg)](https://github.com/test-prof/test-prof/actions)
[![JRuby Build](https://github.com/test-prof/test-prof/workflows/JRuby%20Build/badge.svg)](https://github.com/test-prof/test-prof/actions)

# TestProf

> Ruby テストのプロファイリングと最適化のためのツールボックス
<img align="right" height="150" width="129"
title="TestProf logo" class="home-logo" src="./assets/images/logo.svg">

TestProf はテストスイートの性能を分析するための様々なツールの詰め合わせです。

どうしてテストスイートの性能が重要なのでしょうか?
第一に、テストは開発者のためのフィードバックループの一部です。(参考: [@searls](https://github.com/searls) [talk](https://vimeo.com/145917204))
そして第二に、テストはデプロイサイクルの一部でもあります。

はっきりと言うと、遅いテストは時間の無駄であり、あなたの活動を非生産的なものにします。

TestProf ツールボックスは以下のようなツールを備えており、テストスイートに含まれるボトルネックを特定するのに役立つでしょう。

- 一般的な Ruby プロファイラのための プラグ・アンド・プレイ ([`ruby-prof`](https://github.com/ruby-prof/ruby-prof), [`stackprof`](https://github.com/tmm1/stackprof))

- Factory の使用状況についての分析器とプロファイラ

- ActiveSupport を活用したプロファイラ

- より速いテストを書くための、RSpec と minitest のための[ヘルパー](#recipes)

- RuboCop で使える Cop (検査ルール)

- その他色々

📑 [ドキュメント](https://test-prof.evilmartians.io)

<p align="center">
<a href="http://bit.ly/test-prof-map-v1">
<img src="./assets/images/coggle.png" alt="TestProf map" width="738">
</a>
</p>

<p align="center">
<a href="https://evilmartians.com/?utm_source=test-prof">
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg"
alt="Sponsored by Evil Martians" width="236" height="54">
</a>
</p>

## TestProf を使用するチーム

- [Discourse](https://github.com/discourse/discourse)[~27% 程度テストスイートの実行時間を削減した](https://twitter.com/samsaffron/status/1125602558024699904)
- [Gitlab](https://gitlab.com/gitlab-org/gitlab-ce)[39% API テストの実行時間を削減した](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/14370)
- [CodeTriage](https://github.com/codetriage/codetriage)
- [Dev.to](https://github.com/thepracticaldev/dev.to)
- [Open Project](https://github.com/opf/openproject)
- [その他色々...](https://github.com/test-prof/test-prof/issues/73)

## 情報リソース

- [TestProf: a good doctor for slow Ruby tests](https://evilmartians.com/chronicles/testprof-a-good-doctor-for-slow-ruby-tests)

- [TestProf II: factory therapy for your Ruby tests](https://evilmartians.com/chronicles/testprof-2-factory-therapy-for-your-ruby-tests-rspec-minitest)

- [TestProf III: guided and automated Ruby test profiling](https://evilmartians.com/chronicles/test-prof-3-guided-and-automated-ruby-test-profiling)

- [Rails Testing on Rocket Fuel: How we made our tests 5x faster](https://www.zerogravity.co.uk/blog/ruby-on-rails-slow-tests)

- Paris.rb, 2018, "99 Problems of Slow Tests" talk [[ビデオ](https://www.youtube.com/watch?v=eDMZS_fkRtk), [スライド](https://speakerdeck.com/palkan/paris-dot-rb-2018-99-problems-of-slow-tests)]

- BalkanRuby, 2018, "Take your slow tests to the doctor" talk [[ビデオ](https://www.youtube.com/watch?v=rOcrme82vC8), [スライド](https://speakerdeck.com/palkan/balkanruby-2018-take-your-slow-tests-to-the-doctor)]

- RailsClub, Moscow, 2017, "Faster Tests" talk [[ビデオ](https://www.youtube.com/watch?v=8S7oHjEiVzs) (ロシア語), [スライド](https://speakerdeck.com/palkan/railsclub-moscow-2017-faster-tests)]

- RubyConfBy, 2017, "Run Test Run" talk [[ビデオ](https://www.youtube.com/watch?v=q52n4p0wkIs), [スライド](https://speakerdeck.com/palkan/rubyconfby-minsk-2017-run-test-run)]

- [Tips to improve speed of your test suite](https://medium.com/appaloosa-store-engineering/tips-to-improve-speed-of-your-test-suite-8418b485205c) by [Benoit Tigeot](https://github.com/benoittgt)

## インストール

`test-prof` gem をアプリケーションに追加してください。

```ruby
group :test do
gem "test-prof", "~> 1.0"
end
```

これだけで完了です。

サポートされるRuby バージョン:

- Ruby (MRI) >= 2.5.0 (**注意:** Ruby 2.2 では TestProf < 0.7.0, Ruby 2.3 では TestProf ~> 0.7.0, Ruby 2.4 では TestProf <0.12.0 を使用してください)

- JRuby >= 9.1.0.0 (**注意:** refinements に依存する機能は 9.2.7+ を必要とする場合があります)

サポートされる RSpec のバージョン (RSpec に関する機能のみ): >= 3.5.0 (より古いバージョンの RSpec に対しては TestProf < 0.8.0 を使用してください)

サポートされる Rails のバージョン (Ralis に関する機能のみ): >= 5.2.0 (より古いバージョンの Rails に対しては TestProf < 1.0 を使用してください)

### RuboCop RSpec によるリント

rubocop-rspec を用いて RSpecファイル を静的解析すると、TestProfが定義している`let_it_be``before_all`とった RSpec 用のコンストラクトを正しく検出できないことがあります。

バージョン2.0 以降の `rubocop-rspec` が使用されていることを確認の上、`.rubocop.yml`に以下の記述を追加してください。

```yaml
inherit_gem:
test-prof: config/rubocop-rspec.yml
```

## プロファイラ

- [RubyProf Integration](./profilers/ruby_prof.md)

- [StackProf Integration](./profilers/stack_prof.md)

- [Event Profiler](./profilers/event_prof.md) (ActiveSupport notifications など)

- [Tag Profiler](./profilers/tag_prof.md)

- [Factory Doctor](./profilers/factory_doctor.md)

- [Factory Profiler](./profilers/factory_prof.md)

- [RSpecDissect Profiler](./profilers/rspec_dissect.md)

## レシピ

テストスイートの性能と効率を向上させるのに役立つ、ちょっとしたコードトリックを紹介します

- [`before_all` Hook](./recipes/before_all.md)

- [`let_it_be` Helper](./recipes/let_it_be.md)

- [AnyFixture](./recipes/any_fixture.md)

- [FactoryDefault](./recipes/factory_default.md)

- [FactoryAllStub](./recipes/factory_all_stub.md)

- [RSpec Stamp](./recipes/rspec_stamp.md)

- [Tests Sampling](./recipes/tests_sampling.md)

- [Active Record Shared Connection](./recipes/active_record_shared_connection.md)

- [Rails Logging](./recipes/logging.md)

## 他のツール

- [RuboCop cops](./misc/rubocop.md)

## 次は何?

良いアイデアあれば、 [このページ](https://github.com/test-prof/test-prof/discussions) から新しい機能を提案してください!

それとも、既に TestProf を使用しているなら、 [あなたの体験をシェアしてください!](https://github.com/test-prof/test-prof/discussions/73)

## ライセンス

この gem は [MIT License](http://opensource.org/licenses/MIT) のもと、オープンソースとして使用することができます。
45 changes: 26 additions & 19 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
* [入門](/getting_started.md)
<!-- markdownlint-disable -->

* 性能解析
* [RubyProfとの統合](/profilers/ruby_prof.md)
* [StackProfとの統合](/profilers/stack_prof.md)
* [Event Profiler](/profilers/event_prof.md)
* [Tag Profiler](/profilers/tag_prof.md)
* [Factory Doctor](/profilers/factory_doctor.md)
* [Factory Profiler](/profilers/factory_prof.md)
* [RSpecDissect Profiler](/profilers/rspec_dissect.md)
* [はじめに](/getting_started.md)
* [プレイブック](/playbook.md)
<a rel="noopener" href="https://github.com/sponsors/test-prof" class="sponsor-link" target="_blank">
<img class='sponsor-badge' src='/assets/images/heart.svg' alt='heart' />
<span>スポンサー</span>
</a>

* レシピー
* [`before_all`](/recipes/before_all.md)
* [`let_it_be`](/recipes/let_it_be.md)
* [AnyFixture](/recipes/any_fixture.md)
* [FactoryDefault](/recipes/factory_default.md)
* [FactoryAllStub](/recipes/factory_all_stub.md)
* [RSpec Stamp](/recipes/rspec_stamp.md)
* [テストのサンプリング](/recipes/tests_sampling.md)
* [Railsのログ出力](/recipes/logging.md)
* プロファイラ
* [Ruby profilers](/profilers/ruby_profilers.md)
* [Event Profiler](/profilers/event_prof.md)
* [Tag Profiler](/profilers/tag_prof.md)
* [Factory Doctor](/profilers/factory_doctor.md)
* [Factory Profiler](/profilers/factory_prof.md)
* [RSpecDissect Profiler](/profilers/rspec_dissect.md)
* [Memory Profiler](/profilers/memory_prof.md)

* レシピ
* [`before_all` Hook](/recipes/before_all.md)
* [`let_it_be` Helper](/recipes/let_it_be.md)
* [AnyFixture](/recipes/any_fixture.md)
* [FactoryDefault](/recipes/factory_default.md)
* [FactoryAllStub](/recipes/factory_all_stub.md)
* [RSpec スタンプ](/recipes/rspec_stamp.md)
* [テストのサンプリング](/recipes/tests_sampling.md)
* [Rails のロギング](/recipes/logging.md)

* その他
* [RuboCopのコップ](/misc/rubocop.md)
* [RuboCop の検査ルール](/misc/rubocop.md)
Binary file added docs/assets/factory-flame.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/coggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/assets/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/testprof.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/tag-prof.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 16 additions & 28 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,55 @@
# 入門

## 前提条件

対応しているRubyのバージョン

* Ruby (MRI) >= 2.5.0
* Ruby 2.2の場合は、TestProf < 0.7.0、
* Ruby 2.3の場合は、TestProf ~> 0.7.0、
* Ruby 2.4の場合は、TestProf < 0.12.0 を使用してください。

* JRuby >= 9.1.0.0(一部のツールはバージョン 9.2.7+ が必要)

RSpecの場合は、対応のバージョンは >=3.5.0 です。もっと古いRSpecには TestProf < 0.8.0 が必要です。
# はじめに

## インストール

ジェム「`test-prof`」を追加してください
`test-prof` gem をアプリケーションに追加してください

```ruby
group :test do
gem "test-prof"
gem "test-prof", "~> 1.0"
end
```

これでインストールが終わりです!
これだけで完了です。TestProfを使用する準備ができました! [プロファイル](/#profilers).

## 設定

TestProfは、全ツールで使用されるいくつかのグローバル設定があります
TestProf には、全ツールで使用されるグローバル設定がいくつかあります

```ruby
TestProf.configure do |config|
# レポートなどを保存するフォルダー (デフォルトは'tmp/test_prof')
config.output_dir = "tmp/test_prof"

# レポートファイルの名前ににタイムスタンプを付ける
# レポートに対し一意なファイル名を付与する(単に、現在のタイムスタンプを追加する)
config.timestamps = true

# 出力をハイライトする
# 色付きで出力する
config.color = true

# ログ出力の宛先(ファイルまたはSTDOUT)
# ログの出力先 (デフォルト)
config.output = $stdout

# カスタムのロガーインスタンスを指定することもできます
# あるいは、カスタムのロガーインスタンスを指定することもできます
config.logger = MyLogger.new
end
```

### レポート区別用の識別子

また、「`TEST_PROF_REPORT`」という環境変数を使用して、レポート名に識別子を追加することができます。これは、異なるセットアップでのレポートを比較したい場合に便利です。
また、「`TEST_PROF_REPORT`」という環境変数を使用して、レポート名に識別子を追加することができます。
これは、異なるセットアップ間でレポートを比較したい場合に役立ちます。

**例:** `bootsnap`を使う場合と使わない場合のロード時間を[`stackprof`](./profilers/stack_prof.md)で比較してみましょう。

```sh
# 一番目のレポートに、「-with-bootsnap」を付けます
# 一番目のレポートに、接頭語「-with-bootsnap」を付けます
$ TEST_STACK_PROF=boot TEST_PROF_REPORT=with-bootsnap bundle exec rake
$ #=> StackProf report generated: tmp/test_prof/stack-prof-report-wall-raw-boot-with-bootsnap.dump

# 二番目のレポートは、bootnapを無効にし、名前に「-no-bootsnap」を付けて作成します

# bootsnapを無効にし、二番目のレポートを作成したい
# Assume that you disabled bootsnap and want to generate a new report
$ TEST_STACK_PROF=boot TEST_PROF_REPORT=no-bootsnap bundle exec rake
$ #=> StackProf report generated: tmp/test_prof/stack-prof-report-wall-raw-boot-no-bootsnap.dump
```

これで、分かりやすい名前の2つのレポートができました
これで、分かりやすい名前のレポートが二つできました
57 changes: 57 additions & 0 deletions docs/misc/rubocop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Custom RuboCop Cops

TestProf comes with the [RuboCop](https://github.com/bbatsov/rubocop) cops that help you write more performant tests.

To enable them, require `test_prof/rubocop` in your RuboCop configuration:

```yml
# .rubocop.yml
require:
- 'test_prof/rubocop'
```

To configure cops to your needs:

```yml
RSpec/AggregateExamples:
AddAggregateFailuresMetadata: false
```

Or you can just require it dynamically:

```sh
bundle exec rubocop -r 'test_prof/rubocop' --only RSpec/AggregateExamples
```

## RSpec/AggregateExamples

This cop encourages you to use one of the greatest features of the recent RSpec – aggregating failures within an example.

Instead of writing one example per assertion, you can group _independent_ assertions together, thus running all setup hooks only once.
That can dramatically increase your performance (by reducing the total number of examples).

Consider an example:

```ruby
# bad
it { is_expected.to be_success }
it { is_expected.to have_header("X-TOTAL-PAGES", 10) }
it { is_expected.to have_header("X-NEXT-PAGE", 2) }
its(:status) { is_expected.to eq(200) }

# good
it "returns the second page", :aggregate_failures do
is_expected.to be_success
is_expected.to have_header("X-TOTAL-PAGES", 10)
is_expected.to have_header("X-NEXT-PAGE", 2)
expect(subject.status).to eq(200)
end
```

Auto-correction will typically add `:aggregate_failures` to examples, but if your project enables it globally, or selectively by e.g. deriving metadata from file location, you may opt-out of adding it using `AddAggregateFailuresMetadata` config option.

This cop supports auto-correct feature, so you can automatically refactor you legacy tests!

**NOTE**: `its` examples shown here have been deprecated as of RSpec 3, but users of the [rspec-its gem](https://github.com/rspec/rspec-its) can leverage this cop to cut out that dependency.

**NOTE**: auto-correction of examples using block matchers, such as `change` is deliberately not supported.
Loading

0 comments on commit 7d75cb2

Please sign in to comment.