From 5bf8a518bb45b581f81d831b4eeb7a4f4cc2d4b1 Mon Sep 17 00:00:00 2001 From: Oleksii Dashkevych Date: Sat, 29 Jan 2022 14:19:09 +0200 Subject: [PATCH] Add Github Actions and update Rubocop (#128) * Add Github Actions and update Rubocop * Fix * Remove support for ruby 2.3 and 2.4 * Fix --- .github/workflows/ruby.yml | 34 ++++++++++++++++ .rubocop.yml | 6 +++ .rubocop_todo.yml | 67 ++++++++++++++++++++++++++++++++ .travis.yml | 26 ------------- README.md | 1 - redis-session-store.gemspec | 8 ++-- spec/redis_session_store_spec.rb | 32 ++++++++------- spec/support.rb | 2 +- 8 files changed, 130 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/ruby.yml create mode 100644 .rubocop_todo.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 0000000..963c933 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,34 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby + +name: Ruby + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + + runs-on: ubuntu-latest + strategy: + matrix: + ruby: [2.5, 2.6, 2.7, head, jruby-9.2.20.1, jruby-head] + + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + continue-on-error: true + - name: Run tests + run: bundle exec rake + continue-on-error: true diff --git a/.rubocop.yml b/.rubocop.yml index 9b135d8..4bcdbbb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,9 @@ +inherit_from: .rubocop_todo.yml + +require: + - rubocop-rake + - rubocop-rspec + AllCops: DisplayCopNames: true Exclude: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..b1d9b68 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,67 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2022-01-29 11:55:33 UTC using RuboCop version 1.25.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'redis-session-store.gemspec' + +# Offense count: 6 +# Configuration parameters: Prefixes. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/redis_session_store_spec.rb' + +# Offense count: 2 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 9 + +# Offense count: 5 +# Configuration parameters: AssignmentOnly. +RSpec/InstanceVariable: + Exclude: + - 'spec/redis_session_store_spec.rb' + +# Offense count: 8 +# Configuration parameters: . +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + EnforcedStyle: receive + +# Offense count: 5 +RSpec/MultipleExpectations: + Max: 2 + +# Offense count: 17 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 10 + +# Offense count: 13 +RSpec/NestedGroups: + Max: 5 + +# Offense count: 2 +RSpec/StubbedMock: + Exclude: + - 'spec/redis_session_store_spec.rb' + +# Offense count: 20 +RSpec/SubjectStub: + Exclude: + - 'spec/redis_session_store_spec.rb' + +# Offense count: 16 +# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. +RSpec/VerifiedDoubles: + Exclude: + - 'spec/redis_session_store_spec.rb' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f7fda10..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: ruby -cache: bundler -rvm: -- 2.3 -- 2.4 -- 2.5 -- 2.6 -- ruby-head -matrix: - include: - - rvm: jruby-9.2.19.0 - name: "Latest JRuby" - allow_failures: - - rvm: ruby-head - - name: "Latest JRuby" -notifications: - email: false -deploy: - provider: rubygems - api_key: - secure: jL1lH/wfeRa5MoZRHvkXcZP/Ch7huFxqzbvhEV7UZhiDUBnApcJWkb346jeLEDYnFObUhqhaCZ1/l4fDeSFg2GgatSfEnoWATFVkIf1e4TTGAePlS+4qqsGOcr+XrjP6CEf4o4JACdLuSoT9dtUFj0xkFLnDWILxneXIrqDE9VU= - gem: redis-session-store - on: - tags: true - repo: roidrage/redis-session-store - rvm: 2.6.6 diff --git a/README.md b/README.md index fd3594c..c37e919 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Redis Session Store -[![Build Status](https://travis-ci.org/roidrage/redis-session-store.svg?branch=master)](https://travis-ci.org/roidrage/redis-session-store) [![Code Climate](https://codeclimate.com/github/roidrage/redis-session-store.svg)](https://codeclimate.com/github/roidrage/redis-session-store) [![Gem Version](https://badge.fury.io/rb/redis-session-store.svg)](http://badge.fury.io/rb/redis-session-store) diff --git a/redis-session-store.gemspec b/redis-session-store.gemspec index 36d8a86..178b70a 100644 --- a/redis-session-store.gemspec +++ b/redis-session-store.gemspec @@ -4,7 +4,7 @@ Gem::Specification.new do |gem| gem.email = ['meyer@paperplanes.de'] gem.summary = 'A drop-in replacement for e.g. MemCacheStore to ' \ 'store Rails sessions (and Rails sessions only) in Redis.' - gem.description = gem.summary + ' For great glory!' + gem.description = "#{gem.summary} For great glory!" gem.homepage = 'https://github.com/roidrage/redis-session-store' gem.license = 'MIT' @@ -21,6 +21,8 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'fakeredis', '~> 0.8' gem.add_development_dependency 'rake', '~> 13' gem.add_development_dependency 'rspec', '~> 3' - gem.add_development_dependency 'rubocop', '~> 0.81' - gem.add_development_dependency 'simplecov', '~> 0.17' + gem.add_development_dependency 'rubocop', '~> 1.25' + gem.add_development_dependency 'rubocop-rake', '~> 0.6' + gem.add_development_dependency 'rubocop-rspec', '~> 2.8' + gem.add_development_dependency 'simplecov', '~> 0.21' end diff --git a/spec/redis_session_store_spec.rb b/spec/redis_session_store_spec.rb index f00a90a..16578fb 100644 --- a/spec/redis_session_store_spec.rb +++ b/spec/redis_session_store_spec.rb @@ -1,20 +1,19 @@ require 'json' describe RedisSessionStore do + subject(:store) { described_class.new(nil, options) } + let :random_string do "#{rand}#{rand}#{rand}" end + let :default_options do + store.instance_variable_get(:@default_options) + end let :options do {} end - subject(:store) { RedisSessionStore.new(nil, options) } - - let :default_options do - store.instance_variable_get(:@default_options) - end - it 'assigns a :namespace to @default_options' do expect(default_options[:namespace]).to eq('rack:session') end @@ -35,7 +34,7 @@ end it 'creates a redis instance' do - expect(store.instance_variable_get(:@redis)).to_not be_nil + expect(store.instance_variable_get(:@redis)).not_to be_nil end it 'assigns the :host option to @default_options' do @@ -96,7 +95,7 @@ end it 'creates a redis instance' do - expect(store.instance_variable_get(:@redis)).to_not be_nil + expect(store.instance_variable_get(:@redis)).not_to be_nil end it 'assigns the :host option to @default_options' do @@ -228,6 +227,7 @@ context 'when session id is not provided' do context 'when session id is nil' do let(:session_id) { nil } + it 'returns false' do expect(store.send(:session_exists?, :env)).to eq(false) end @@ -235,6 +235,7 @@ context 'when session id is empty string' do let(:session_id) { '' } + it 'returns false' do allow(store).to receive(:current_session_id).with(:env).and_return('') expect(store.send(:session_exists?, :env)).to eq(false) @@ -404,14 +405,15 @@ context 'marshal' do let(:options) { { serializer: :marshal } } - it_should_behave_like 'serializer' + + it_behaves_like 'serializer' end context 'json' do let(:options) { { serializer: :json } } let(:encoded_data) { '{"some":"data"}' } - it_should_behave_like 'serializer' + it_behaves_like 'serializer' end context 'hybrid' do @@ -419,13 +421,13 @@ let(:expected_encoding) { '{"some":"data"}' } context 'marshal encoded data' do - it_should_behave_like 'serializer' + it_behaves_like 'serializer' end context 'json encoded data' do let(:encoded_data) { '{"some":"data"}' } - it_should_behave_like 'serializer' + it_behaves_like 'serializer' end end @@ -445,7 +447,7 @@ def self.dump(_value) let(:options) { { serializer: custom_serializer } } let(:expected_encoding) { 'somedata' } - it_should_behave_like 'serializer' + it_behaves_like 'serializer' end end @@ -521,7 +523,7 @@ def self.dump(_value) %w(on_redis_down on_session_load_error).each do |h| context 'when nil' do it 'does not explode at init' do - expect { store }.to_not raise_error + expect { store }.not_to raise_error end end @@ -529,7 +531,7 @@ def self.dump(_value) let(:options) { { "#{h}": ->(*) { true } } } it 'does not explode at init' do - expect { store }.to_not raise_error + expect { store }.not_to raise_error end end diff --git a/spec/support.rb b/spec/support.rb index a1bad2f..bd34153 100644 --- a/spec/support.rb +++ b/spec/support.rb @@ -13,7 +13,7 @@ module Session class SessionId attr_reader :public_id - def initialize(public_id) + def initialize(_public_id) @public_id end end