Skip to content

Commit

Permalink
fix specs, add rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
patodevilla committed Mar 19, 2024
1 parent 7a8ac1e commit 78e823e
Show file tree
Hide file tree
Showing 23 changed files with 377 additions and 196 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test

on: [pull_request]

# permissions:
# contents: read

jobs:
lint:
runs-on: ubuntu-latest
# env:
# BUNDLE_ONLY: rubocop

steps:
- uses: actions/checkout@v4

- name: Set up Ruby 3.2.2
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.2
bundler-cache: true

- name: Run Tests
run: bundle exec rake
# run: bundle exec rubocop --parallel
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status
.byebug_history
Gemfile.lock
11 changes: 11 additions & 0 deletions .rubocop-rspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
###########################################################
#################### Rubocop Rspec ########################
###########################################################

# You can find all configuration options for rubocop-rspec here: https://docs.rubocop.org/rubocop-rspec/cops.html

# RSpec/PendingWithoutReason:
# Enabled: false

# RSpec/FilePath:
# Enabled: false
77 changes: 77 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# see example at https://gist.github.com/jhass/a5ae80d87f18e53e7b56

# <% unless ENV['BYPASS_RUBOCOP_TODO'] %>
# inherit_from:
# <% else %>
# inherit_from:
# - '.rubocop-todo.yml'
# <% end %>

inherit_from:
- .rubocop_todo.yml
- .rubocop-rspec.yml

require:
- rubocop-rspec
- rubocop-rake
- rubocop-performance

AllCops:
NewCops: enable
# TargetRubyVersion: 2.7.8
# TargetRailsVersion: 6.1.4
# Exclude:
# - 'Gemfile.lock'

Naming/VariableNumber:
Enabled: false

Layout/SpaceInsideHashLiteralBraces:
Enabled: false

Layout/EmptyLinesAroundModuleBody:
EnforcedStyle: empty_lines_special
Enabled: false

Layout/TrailingEmptyLines:
Enabled: false
EnforcedStyle: final_blank_line

Layout/EmptyLinesAroundClassBody:
Enabled: false

Style/RaiseArgs:
EnforcedStyle: compact

Naming/MethodParameterName:
Enabled: false

Naming/VariableName:
Enabled: false

Layout/FirstHashElementIndentation:
Enabled: false

Layout/CaseIndentation:
EnforcedStyle: end

Metrics/ParameterLists:
Enabled: false

Style/Lambda:
EnforcedStyle: literal

Layout/IndentationWidth:
Enabled: false

Layout/EndAlignment:
Enabled: false

Layout/ElseAlignment:
Enabled: false

Style/TrivialAccessors:
Enabled: false

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
46 changes: 46 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-03-19 18:55:09 UTC using RuboCop version 1.62.1.
# 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: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 14

# Offense count: 1
RSpec/BeforeAfterAll:
Exclude:
- '**/spec/spec_helper.rb'
- '**/spec/rails_helper.rb'
- '**/spec/support/**/*.rb'
- 'spec/sidekiq_bouncer/bouncer_spec.rb'

# Offense count: 2
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 7

# Offense count: 3
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 4

# Offense count: 1
RSpec/SubjectStub:
Exclude:
- 'spec/sidekiq_bouncer/bouncer_spec.rb'

# Offense count: 6
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/sidekiq_bouncer.rb'
- 'lib/sidekiq_bouncer/bounceable.rb'
- 'lib/sidekiq_bouncer/bouncer.rb'
- 'lib/sidekiq_bouncer/config.rb'
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

13 changes: 0 additions & 13 deletions CHANGELOG.md

This file was deleted.

15 changes: 14 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
source "https://rubygems.org"
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in sidekiq-bouncer.gemspec
gemspec

# gem 'bundler', '2.4.22'
gem 'debug', '>= 1.0.0'
gem 'rake', '~> 13.1'
gem 'rspec', '~> 3.9'

# rubocop
gem 'rubocop', '~> 1.62'
gem 'rubocop-performance', '~> 1.20'
gem 'rubocop-rake', '~> 0.6'
gem 'rubocop-rspec', '~> 2.27.1'
50 changes: 0 additions & 50 deletions Gemfile.lock

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class FooWorker
# The default delay is 60 seconds. You can optionally override it.
register_bouncer(delay: optional_delay_override, delay_buffer: optional_delay_buffer_override)

def perform(param1, param2)
return unless self.class.bouncer.let_in?(param1, param2) #pass all args received from perform
def perform(param1, param2, debounce_key = nil)
return unless self.class.bouncer.let_in?(debounce_key) # last argument is added as debounce_key

# Do your thing.
end
end

# Call `.bouncer.debounce(...)` instead of `.perform_in/perform_async(...)`.
FooWorker.bouncer.debounce(param1, param2)
FooWorker.bouncer.debounce(param1, param2, key_or_args_indices: [0, 1])
```

## Development
Expand Down
11 changes: 8 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
# frozen_string_literal: true

require 'bundler/gem_tasks'

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

task :default => :spec
require 'rubocop/rake_task'
RuboCop::RakeTask.new

task default: %i[spec rubocop]
7 changes: 4 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "sidekiq_bouncer"
require 'bundler/setup'
require 'sidekiq_bouncer'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +11,5 @@ require "sidekiq_bouncer"
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start(__FILE__)
4 changes: 3 additions & 1 deletion lib/sidekiq_bouncer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'sidekiq_bouncer/config'
require 'sidekiq_bouncer/version'
require 'sidekiq_bouncer/bounceable'
Expand All @@ -13,7 +15,7 @@ def config
end

# Yield self to allow configuing in a block
def configure(&block)
def configure(&)
yield config
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/sidekiq_bouncer/bounceable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SidekiqBouncer
module Bounceable

Expand Down
Loading

0 comments on commit 78e823e

Please sign in to comment.