Rails+Rspecで特定の環境でのみテストをする方法をまとめていきます。例えば、APIのテストでlocalではAPIを受け取れないのでstaging環境でのみテストするなどです。
tagを使う
tagを設定することでそのtagのついたテストのみを実行することができます。
https://relishapp.com/rspec/rspec-core/v/3-5/docs/command-line/tag-option
例えば
describe "hoge", :focus
end
上記でコマンド
# focusタグが付いたもののみ実行
bundle exec rspec -t focus
# focusタグが付いたもののみ除外
bundle exec rspec -t ~focus
除外の場合、上記だとなぜか動かず
bundle exec rspec --tag "~focus"
上記のように””で囲ったら動いた