1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-08-28 15:26:18 +03:00

Update rubocop, add appraisal gem

Этот коммит содержится в:
Max Melentiev
2017-11-16 22:49:04 +03:00
родитель da93abaaf7
Коммит 1a30b430df
25 изменённых файлов: 146 добавлений и 70 удалений

1
.gitignore поставляемый
Просмотреть файл

@@ -1,6 +1,7 @@
/.bundle/
/.yardoc
/Gemfile.lock
/gemfiles/*.lock
/_yardoc/
/coverage/
/doc/

Просмотреть файл

@@ -1,30 +1,52 @@
Rails: {Enabled: true}
Style/Alias: {Enabled: false}
Style/AlignParameters:
Layout/AlignParameters:
# Disable, till rubocop supports combination of styles.
# Use one of this styles where appropriate, keep it clean, compact and readable.
Enabled: false
# EnforcedStyle:
# - with_first_parameter
# - with_fixed_indentation
# Breaks
#
# I18n.t(key,
# param: val,
# # ...
# )
Layout/ClosingParenthesisIndentation: {Enabled: false}
Layout/DotPosition: {EnforcedStyle: trailing}
Layout/FirstParameterIndentation: {EnforcedStyle: consistent}
# Same as Layout/ClosingParenthesisIndentation
Layout/MultilineMethodCallBraceLayout: {Enabled: false}
Layout/MultilineMethodCallIndentation: {EnforcedStyle: indented}
Layout/MultilineOperationIndentation: {EnforcedStyle: indented}
Layout/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space}
# Offences named scopes and `expect {}.to change {}`.
Lint/AmbiguousBlockAssociation: {Enabled: false}
Naming/PredicateName: {Enabled: false}
Naming/VariableNumber: {EnforcedStyle: snake_case}
Style/Alias: {Enabled: false}
Style/AndOr: {EnforcedStyle: conditionals}
Style/ClosingParenthesisIndentation: {Enabled: false}
Style/Documentation: {Enabled: false}
Style/DotPosition: {EnforcedStyle: trailing}
Style/FirstParameterIndentation: {EnforcedStyle: consistent}
Style/IfUnlessModifier: {Enabled: false}
# Consistent to other definitions.
Style/EmptyMethod: {EnforcedStyle: expanded}
Style/ModuleFunction: {Enabled: false}
Style/MultilineMethodCallIndentation: {EnforcedStyle: indented}
Style/MultilineOperationIndentation: {EnforcedStyle: indented}
Style/NestedParenthesizedCalls: {Enabled: false}
Style/PredicateName: {Enabled: false}
Style/SignalException: {EnforcedStyle: only_raise}
Style/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space}
Style/TrailingCommaInArguments: {Enabled: false}
Style/TrailingCommaInLiteral: {EnforcedStyleForMultiline: comma}
Metrics/AbcSize: {Max: 21}
# Other metrics are just enough.
# This one offences all specs, routes and some initializers.
Metrics/BlockLength: {Enabled: false}
Metrics/LineLength: {Max: 100}
Metrics/MethodLength: {Max: 30}
Metrics/CyclomaticComplexity: {Max: 8}

Просмотреть файл

@@ -2,9 +2,9 @@ language: ruby
cache: bundler
rvm:
- 2.2.3
env:
- RAILS=4
- RAILS=5
- RAILS=5_1
gemfile:
- gemfiles/rails_42.gemfile
- gemfiles/rails_50.gemfile
- gemfiles/rails_51.gemfile
notifications:
email: false

14
Appraisals Обычный файл
Просмотреть файл

@@ -0,0 +1,14 @@
appraise 'rails-51' do
gem 'actionpack', '~> 5.1'
gem 'railties', '~> 5.1'
end
appraise 'rails-50' do
gem 'actionpack', '~> 5.0'
gem 'railties', '~> 5.0'
end
appraise 'rails-42' do
gem 'actionpack', '~> 4.2'
gem 'railties', '~> 4.2'
end

19
Gemfile
Просмотреть файл

@@ -2,24 +2,11 @@ source 'https://rubygems.org'
gemspec
group :development do
case ENV['RAILS']
when '5_1'
gem 'railties', '5.1.0'
gem 'actionpack', '5.1.0'
when '5'
gem 'railties', '5.0.2'
gem 'actionpack', '5.0.2'
when '4'
gem 'railties', '~> 4.2'
gem 'actionpack', '~> 4.2'
else
gem 'railties'
gem 'actionpack'
end
gem 'appraisal', '~> 2.2'
gem 'sdoc', '~> 0.4.1'
gem 'pry', '~> 0.10.1'
gem 'pry-byebug', '~> 3.2.0'
gem 'sdoc', '~> 0.4.1'
gem 'telegram-bot-types', '~> 0.3.0'
@@ -27,7 +14,7 @@ group :development do
gem 'rspec-its', '~> 1.1.0'
gem 'rspec-rails', '~> 3.5.0'
gem 'rubocop', '~> 0.37.0'
gem 'rubocop', '~> 0.51.0'
gem 'coveralls', '~> 0.8.2', require: false
end

Просмотреть файл

@@ -507,7 +507,7 @@ Yes, it's threadsafe too.
## Development
After checking out the repo, run `bin/setup` to install dependencies.
Then, run `rake spec` to run the tests.
Then, run `appraisal rake spec` to run the tests.
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`.
@@ -515,16 +515,6 @@ To release a new version, update the version number in `version.rb`,
and then run `bundle exec rake release`, which will create a git tag for the version,
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
### Different Rails versions
To setup development for specific major Rails version use:
```
RAILS=5 bundle install
# or
RAILS=5 bundle update
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/telegram-bot-rb/telegram-bot.

Просмотреть файл

@@ -3,6 +3,7 @@ set -euo pipefail
IFS=$'\n\t'
bundle install
appraisal install
bin/install_git_hooks
# Do any other automated setup that you need to do here

20
gemfiles/rails_42.gemfile Обычный файл
Просмотреть файл

@@ -0,0 +1,20 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "actionpack", "~> 4.2"
gem "railties", "~> 4.2"
group :development do
gem "pry", "~> 0.10.1"
gem "pry-byebug", "~> 3.2.0"
gem "sdoc", "~> 0.4.1"
gem "telegram-bot-types", "~> 0.3.0"
gem "rspec", "~> 3.5.0"
gem "rspec-its", "~> 1.1.0"
gem "rspec-rails", "~> 3.5.0"
gem "rubocop", "~> 0.51.0"
gem "coveralls", "~> 0.8.2", require: false
end
gemspec path: "../"

20
gemfiles/rails_50.gemfile Обычный файл
Просмотреть файл

@@ -0,0 +1,20 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "actionpack", "~> 5.0"
gem "railties", "~> 5.0"
group :development do
gem "pry", "~> 0.10.1"
gem "pry-byebug", "~> 3.2.0"
gem "sdoc", "~> 0.4.1"
gem "telegram-bot-types", "~> 0.3.0"
gem "rspec", "~> 3.5.0"
gem "rspec-its", "~> 1.1.0"
gem "rspec-rails", "~> 3.5.0"
gem "rubocop", "~> 0.51.0"
gem "coveralls", "~> 0.8.2", require: false
end
gemspec path: "../"

20
gemfiles/rails_51.gemfile Обычный файл
Просмотреть файл

@@ -0,0 +1,20 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "actionpack", "~> 5.1"
gem "railties", "~> 5.1"
group :development do
gem "pry", "~> 0.10.1"
gem "pry-byebug", "~> 3.2.0"
gem "sdoc", "~> 0.4.1"
gem "telegram-bot-types", "~> 0.3.0"
gem "rspec", "~> 3.5.0"
gem "rspec-its", "~> 1.1.0"
gem "rspec-rails", "~> 3.5.0"
gem "rubocop", "~> 0.51.0"
gem "coveralls", "~> 0.8.2", require: false
end
gemspec path: "../"

Просмотреть файл

@@ -35,7 +35,7 @@ module Telegram
def request(method, uri, query = {}, body = nil)
res = http_request(method, uri, query.merge(token: token), body)
status = res.status
return JSON.parse(res.body) if 300 > status
return JSON.parse(res.body) if status < 300
result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier
err_msg = "#{res.reason}: #{result && result['info'] || '-'}"
raise Error, err_msg

Просмотреть файл

@@ -49,7 +49,7 @@ module Telegram
def request(action, body = {})
res = http_request("#{base_uri}#{action}", self.class.prepare_body(body))
status = res.status
return JSON.parse(res.body) if 300 > status
return JSON.parse(res.body) if status < 300
result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier
err_msg = result && result['description'] || '-'
if result
@@ -63,7 +63,7 @@ module Telegram
end
# Splited to the sections similar to API docs.
%w(
%w[
deleteWebhook
getUpdates
getWebhookInfo
@@ -124,7 +124,7 @@ module Telegram
getGameHighScores
sendGame
setGameScore
).each do |method|
].each do |method|
define_method(method.underscore) { |*args| request(method, *args) }
end

Просмотреть файл

@@ -78,7 +78,7 @@ module Telegram
autoload :TypedUpdate, 'telegram/bot/updates_controller/typed_update'
PAYLOAD_TYPES = %w(
PAYLOAD_TYPES = %w[
message
edited_message
channel_post
@@ -88,7 +88,7 @@ module Telegram
callback_query
shipping_query
pre_checkout_query
).freeze
].freeze
CMD_REGEX = %r{\A/([a-z\d_]{,31})(@(\S+))?(\s|$)}i
CONFLICT_CMD_REGEX = Regexp.new("^(#{PAYLOAD_TYPES.join('|')}|\\d)")

Просмотреть файл

@@ -39,7 +39,7 @@ module Telegram
Instrumentation.instrument(:respond_with, type: type) { super }
end
%i(answer_callback_query answer_inline_query).each do |type|
%i[answer_callback_query answer_inline_query].each do |type|
define_method(type) do |*args|
Instrumentation.instrument(:respond_with, type: type) { super(*args) }
end

Просмотреть файл

@@ -17,7 +17,7 @@ module Telegram
payload = event.payload
additions = UpdatesController.log_process_action(payload)
message = "Completed in #{event.duration.round}ms"
message << " (#{additions.join(' | ')})" unless additions.blank?
message << " (#{additions.join(' | ')})" if additions.present?
message
end
end

Просмотреть файл

@@ -2,7 +2,7 @@ module Telegram
module Bot
class UpdatesController
module Testing
IVARS_TO_KEEP = %i(@_session).freeze
IVARS_TO_KEEP = %i[@_session].freeze
# Perform multiple dispatches on same instance.
def dispatch_again(bot = nil, update = nil)

Просмотреть файл

@@ -50,7 +50,7 @@ module Telegram
end
rescue Interrupt
@running = false
rescue => e
rescue StandardError => e
logger.error { ([e.message] + e.backtrace).join("\n") } if logger
end
end

Просмотреть файл

@@ -27,7 +27,7 @@ end
Rails.application.initialize!
# # Controllers
%w(default other named).each do |bot_name|
%w[default other named].each do |bot_name|
controller = Class.new(Telegram::Bot::UpdatesController) do
define_method :start do |*|
respond_with :message, text: "from #{bot_name}"

Просмотреть файл

@@ -19,7 +19,7 @@ RSpec.describe Telegram::Bot::Client do
it 'encodes nested hashes to json' do
expected = input.dup
%i(c d e).each { |x| expected[x] = expected[x].to_json }
%i[c d e].each { |x| expected[x] = expected[x].to_json }
should eq expected
end
end
@@ -35,7 +35,7 @@ RSpec.describe Telegram::Bot::Client do
subject { described_class.new(*args) }
context 'when multiple args are given' do
let(:args) { %w(secret superbot) }
let(:args) { %w[secret superbot] }
its(:token) { should eq args[0] }
its(:username) { should eq args[1] }
its(:base_uri) { should include args[0] }

Просмотреть файл

@@ -45,7 +45,7 @@ RSpec.describe Telegram::Bot::ClientStub do
end
context 'when username and token are given' do
let(:args) { %w(token superbot) }
let(:args) { %w[token superbot] }
its(:token) { should eq args[0] }
its(:username) { should eq args[1] }
end

Просмотреть файл

@@ -5,7 +5,8 @@ require 'action_dispatch/testing/integration'
RSpec.describe 'Integrations helper', :telegram_bot do
include ActionDispatch::Integration::Runner
def reset_template_assertion; end
def reset_template_assertion
end
let(:app) do
app = Telegram::Bot::Middleware.new(bot, controller)
@@ -38,7 +39,7 @@ RSpec.describe 'Integrations helper', :telegram_bot do
describe '#dispatch_message' do
subject { -> { dispatch_message "/start #{args.join ' '}", options } }
let(:args) { %w(asd qwe) }
let(:args) { %w[asd qwe] }
let(:options) { {} }
it { should respond_with_message "Start: #{args.inspect}, option: " }
@@ -59,7 +60,7 @@ RSpec.describe 'Integrations helper', :telegram_bot do
it { should respond_with_message "Start: #{args.inspect}, option: " }
context 'with args' do
let(:args) { %w(asd qwe) }
let(:args) { %w[asd qwe] }
it { should respond_with_message "Start: #{args.inspect}, option: " }
end

Просмотреть файл

@@ -65,7 +65,7 @@ RSpec.describe Telegram::Bot::UpdatesController::MessageContext do
context 'when message has new command' do
let(:text) { '/action a s d' }
its(:call) { should eq [:action_result, *%w(a s d)] }
its(:call) { should eq [:action_result, 'a', 's', 'd'] }
it { should change { session[:context] }.to nil }
end
end

Просмотреть файл

@@ -9,11 +9,11 @@ RSpec.describe Telegram::Bot::UpdatesController::TypedUpdate do
context 'when `update` is a virtus model' do
subject { controller }
%w(
%w[
message
inline_query
chosen_inline_result
).each do |type|
].each do |type|
context "with #{type}" do
type_class = Telegram::Bot::Types.const_get(type.camelize)
let(:payload_type) { type }

Просмотреть файл

@@ -107,7 +107,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
it { should eq [false, :unsupported_payload_type, []] }
end
%w(message channel_post).each do |type|
%w[message channel_post].each do |type|
context "when payload is edited_#{type}" do
let(:payload_type) { "edited_#{type}" }
it { should eq [false, payload_type, [payload]] }
@@ -123,11 +123,11 @@ RSpec.describe Telegram::Bot::UpdatesController do
context 'with command' do
let(:text) { "/test#{"@#{mention}" if mention} arg 1 2" }
let(:mention) {}
it { should eq [true, 'test', %w(arg 1 2)] }
it { should eq [true, 'test', %w[arg 1 2]] }
context 'with mention' do
let(:mention) { bot.username }
it { should eq [true, 'test', %w(arg 1 2)] }
it { should eq [true, 'test', %w[arg 1 2]] }
end
context 'with mention for other bot' do
@@ -143,7 +143,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
end
end
custom_payload_types = %w(
custom_payload_types = %w[
message
edited_message
channel_post
@@ -151,7 +151,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
inline_query
chosen_inline_result
callback_query
)
]
(described_class::PAYLOAD_TYPES - custom_payload_types).each do |type|
context "when payload is #{type}" do
let(:payload_type) { type }
@@ -163,11 +163,11 @@ RSpec.describe Telegram::Bot::UpdatesController do
context 'when `update` is a virtus model' do
subject { controller }
let(:update) { Telegram::Bot::Types::Update.new(super()) }
%w(
%w[
message
inline_query
chosen_inline_result
).each do |type|
].each do |type|
context "with #{type}" do
type_class = Telegram::Bot::Types.const_get(type.camelize)
let(:payload_type) { type }
@@ -194,7 +194,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
describe '#process' do
subject { -> { controller.process(:action, *args) } }
let(:args) { [:arg1, :arg2] }
let(:args) { %i[arg1 arg2] }
let(:controller_class) do
Class.new(described_class) do
attr_reader :acted, :hooked

Просмотреть файл

@@ -1,4 +1,3 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'telegram/bot/version'
@@ -20,9 +19,10 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '~> 2.0'
spec.add_dependency 'activesupport', '>= 4.0', '< 5.2'
spec.add_dependency 'actionpack', '>= 4.0', '< 5.2'
spec.add_dependency 'activesupport', '>= 4.0', '< 5.2'
spec.add_dependency 'httpclient', '~> 2.7'
spec.add_development_dependency 'bundler', '~> 1.11'
spec.add_development_dependency 'rake', '~> 10.0'
end