LoginSignup
0

More than 5 years have passed since last update.

rspecコマンドがspecディレクトリを読み込むまでの流れ

Posted at

:warning: てrspecを使う分には全く不要な知識なので、余程のことが無い限りここから先を読む必要はありません。

--

諸事情で rspec コマンドを引数無しで実行した際に spec ディレクトリ以下の xxx_spec.rb ファイルが指定される流れを追ったので、それを記録として書き残す。バージョンは3.5.4とする

  1. rspec コマンドを実行すると RSpec::Core::Runner.invoke が実行される
  2. RSpec::Core::Runner.invoke すると RSpec::Core::ConfigureOptions が作られRSpec::Core::Parser が呼び出された結果@options インスタンス変数に {:files_or_directories_to_run=>[]} が追加される
  3. その後 RSpec::Core::Runner#run が実行され、その過程で先程の RSpec::Core::ConfigureOptions に対し #configure が実行されるRSpec::Core::ConfigureOptions#process_options_into が呼ばれ、その中で先程の @options の値から RSpec::Core::Configuration#files_or_directories_to_run= が引数無しで実行される
  4. 引数が無いので default_path が使われその default_path"spec" が入っている
  5. こうして RSpec::Core::Configuration#files_or_directories_to_run["spec"] になり、RSpec::Core::Configuration#files_to_run に spec 以下の xxx_spec.rb が入る。RSpecはテストでこの #files_to_run を使う。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0