1
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?

More than 3 years have passed since last update.

【Rails】Rspecで特定のテストを流す方法まとめ

Posted at

行数を指定して特定のテストを流す

①下記2点のいずれかを行う

#####it式をfitと記述する

fit 'trueはtrueであること' do
  expect(true).to eq true
end
it式に「focus: true」オプションを付与する
it 'trueはtrueであること', focus: true do
  expect(true).to eq true
end

②Rspec実行コマンドでファイルの末尾に行数を指定する

ターミナル
$ bundle exec rspec spec/models/robo_test_spec.rb:20

タグ付けを行って特定のテストを流す

describe '四則演算', study: :calc do
  context '足し算', calc_type: :addition do
    it '1 + 1は2であること', easy: true do
      expect(1 + 1).to eq 2
    end

    it '100 + 200は300であること', difficult: true do
      expect(100 + 200).to eq 300
    end
  end

  context '引き算', calc_type: :subtraction do
    it '1 - 1は0であること', easy: true do
      expect(1 - 1).to eq 0
    end

    it '300 - 200は100であること', difficult: true do
      expect(300 - 200).to eq 100
    end
  end
end
ターミナル
$ bundle exec rspec spec/models/robo_test_spec.rb --tag study:calc
$ bundle exec rspec spec/models/robo_test_spec.rb --tag calc_type:addition
$ bundle exec rspec spec/models/robo_test_spec.rb --tag easy # Boolean指定の場合はキーのみでOK
1
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
1
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?