1
0
Fork 0

Add tests for SendTelegramMessage interactor

This commit is contained in:
Alex Kotov 2020-01-15 15:04:21 +05:00
parent 7efa372b6c
commit 4c691b4653
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
5 changed files with 48 additions and 1 deletions

View File

@ -230,4 +230,8 @@ group :test do
# A set of RSpec matchers for testing Pundit authorization policies.
gem 'pundit-matchers', '~> 1.6'
# WebMock allows stubbing HTTP requests
# and setting expectations on HTTP requests.
gem 'webmock', '~> 3.8'
end

View File

@ -132,6 +132,8 @@ GEM
simplecov (>= 0.7)
term-ansicolor
thor
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.5)
cucumber (3.1.2)
builder (>= 2.1.2)
@ -198,6 +200,7 @@ GEM
gherkin (5.1.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
hashdiff (1.0.0)
hashie (3.6.0)
http-accept (1.7.0)
http-cookie (1.0.3)
@ -392,6 +395,7 @@ GEM
ruby-progressbar (1.10.1)
ruby_dep (1.5.0)
rubyzip (2.0.0)
safe_yaml (1.0.5)
sassc (2.2.1)
ffi (~> 1.9)
sassc-rails (2.1.2)
@ -460,6 +464,10 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webmock (3.8.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
@ -531,6 +539,7 @@ DEPENDENCIES
turbolinks (~> 5.2)
uglifier (>= 4.0)
web-console (>= 3.3.0)
webmock (~> 3.8)
yard (~> 0.9, >= 0.9.20)
RUBY VERSION

View File

@ -3,5 +3,33 @@
require 'rails_helper'
RSpec.describe SendTelegramMessage do
pending "add some examples to (or delete) #{__FILE__}"
subject { described_class.call chat_id: chat_id, text: text }
let(:chat_id) { rand 0...10_000 }
let(:text) { Faker::Lorem.paragraph }
let! :request do
stub_request(
:post,
[
'https://api.telegram.org',
'/bot',
Rails.application.credentials.telegram_bot_api_token,
'/sendMessage',
].join,
).with(
body: {
chat_id: chat_id,
text: text,
},
)
end
after do
expect(request).to have_been_made.once
end
specify do
expect(subject).to be_success
end
end

View File

@ -36,6 +36,7 @@ require_relative 'support/factory_bot'
require_relative 'support/database_cleaner'
require_relative 'support/devise'
require_relative 'support/pundit'
require_relative 'support/webmock'
require_relative 'models/shared_examples/nameable'
require_relative 'models/shared_examples/required_nameable'

5
spec/support/webmock.rb Normal file
View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
require 'webmock/rspec'
WebMock.disable_net_connect! allow_localhost: true