Last active
July 8, 2019 00:09
-
-
Save webuilder240/022acd0cd304d7d396934f3e7ce88514 to your computer and use it in GitHub Desktop.
VCRのCassetteファイル名をRSpecのDescriptionに設定する(日本語の場合は日本語まま設定されます。)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/models/user_spec_rb/request!/example.comにリクエストができること.yml にファイルが作成されます。 | |
# また、:(コロン)が含まれる場合、MacのFinderからでは/(スラッシュ)に見えます。 | |
## https://qiita.com/uasi/items/996b24185dffb003105a | |
# rails_helperなどでvcr_helper.rbを使えるようにしている前提のコードになります。 | |
require 'rails_helper' | |
RSpec.describe User, type: :model do | |
describe 'request!' do | |
it 'example.comにリクエストができること' do |example| | |
VCR.use_cassette(VcrHelper.cassette_name_from_example(example)) do | |
Api.request | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module VcrHelper | |
def self.cassette_name_from_example(example) | |
"#{(example.metadata[:rerun_file_path].split('/').delete_if { |a| a == "." } + example.metadata[:full_description].split(' ')).join('/')}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment