5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Qiita株式会社Advent Calendar 2024

Day 5

rspec でディレクトリベースで実行可否を選択したかった

Last updated at Posted at 2024-12-04

やりたいこと

  • rspec で特定のディレクトリ毎にテストを実行するしないを切り替えたりしたい

いかにも

  • --tag で,できそう

手で書くのは面倒

  • rspec-rails には,infer_spec_type_from_file_location! がある

とりあえず

コピーしたら,うまくいってそう

spec/spec_helper.rb
RSpec.configure do |config|
  %w(
    sub_dir1
  ).each do |type|
    dir_parts = ['spec', type]
    escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
    config.define_derived_metadata(file_path: escaped_path) do |metadata|
      metadata[:type] ||= type
    end
  end
(snip)
$ rspec --tag type:sub_dir1
$ rspec --tag ~type:sub_dir1

というのを書いて

普通にディレクトリ指定すればいいことに気付いた

$ rspec spec/sub_dir1

オチ

ハンマーと釘ということで

Refs

5
0
0

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
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?