Skip to content

Commit

Permalink
Add VCR (#287)
Browse files Browse the repository at this point in the history
* Add VCR

Write all requests to cassetes.
* Speed up specs.
* Don't make new requests for every run of existing specs.

* Remove environment variables from CI

They're not needed anymore with VCR,
also it seems that secret token had empty value and broke specs.
  • Loading branch information
AlexWayfer authored Aug 18, 2023
1 parent e6c23c7 commit f6e9756
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ jobs:
ruby:
- 2.7
- 3.2
env:
BOT_API_ENV: test
BOT_API_TOKEN: ${{ secrets.BOT_API_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem 'pry'
gem 'rake', '~> 13.0'

gem 'rspec', '~> 3.4'
gem 'vcr', '~> 6.0'

gem 'rubocop', '~> 1.54.1'
gem 'rubocop-performance', '~> 1.18'
Expand Down
42 changes: 42 additions & 0 deletions spec/cassettes/Telegram_Bot_Api/_call/has_result.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions spec/cassettes/Telegram_Bot_Api/_call/has_status.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions spec/cassettes/Telegram_Bot_Api/_call/returns_hash.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions spec/cassettes/Telegram_Bot_Client/_run/returns_hash.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/lib/telegram/bot/api_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Telegram::Bot::Api do
RSpec.describe Telegram::Bot::Api, :vcr do
let(:token) { ENV.fetch('BOT_API_TOKEN') }
let(:environment) { ENV.fetch('BOT_API_ENV', :test) }
let(:endpoint) { 'getMe' }
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/telegram/bot/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Telegram::Bot::Client do
RSpec.describe Telegram::Bot::Client, :vcr do
subject(:client) { described_class.new(token, environment: environment) }

let(:token) { ENV.fetch('BOT_API_TOKEN') }
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/telegram/bot/exceptions/response_error_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Telegram::Bot::Exceptions::ResponseError do
RSpec.describe Telegram::Bot::Exceptions::ResponseError, :vcr do
subject(:error) do
described_class.new(response)
rescue StandardError => e
Expand Down
17 changes: 17 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# frozen_string_literal: true

require 'dotenv/load'

ENV['BOT_API_ENV'] ||= 'test'
ENV['BOT_API_TOKEN'] ||= 'test_api_token'

require 'vcr'

VCR.configure do |config|
config.cassette_library_dir = "#{__dir__}/cassettes"
config.default_cassette_options = { record_on_error: false }
config.hook_into :faraday
config.configure_rspec_metadata!

config.filter_sensitive_data('<BOT_API_TOKEN>') do
ENV.fetch('BOT_API_TOKEN')
end
end

require_relative '../lib/telegram/bot'

0 comments on commit f6e9756

Please sign in to comment.