Skip to content

Instantly share code, notes, and snippets.

View BernardoMG's full-sized avatar

Bernardo Graça BernardoMG

View GitHub Profile
require 'converter'
RSpec.describe Converter do
describe '#to_binary' do
it 'converts a number to binary' do
result = Converter.to_binary(2)
expect(result).to eq('10')
end
end
> gem install converter-1.0.0.gem
> irb # ruby shell
>> require 'converter'
=> true
>> Converter.to_binary(2)
=> "10"
>> Converter.to_number("10")
=> 2
class Converter
def self.to_binary(number)
number.to_s(2)
end
def self.to_number(binary_number)
binary_number.to_i(2)
end
end
Gem::Specification.new do |spec|
spec.name = 'converter'
spec.version = '1.0.0'
spec.required_ruby_version = '>= 2.5.0'
spec.add_development_dependency 'rspec', '~> 3.7'
s.files = ['lib/converter.rb']
s.require_paths = ['lib']
spec.summary = 'Converts an integer to binary and vice versa.'
spec.author = 'Bernardo Graça'
end
require 'test_helper'
require 'sidekiq/testing' # test mode
class PrinterWorkerTest < ActiveSupport::TestCase
test 'should enqueue one job with success' do
PrinterWorker.perform_async("Buy me a pizza for dinner, please!")
assert_equal 1, PrinterWorker.jobs.size
PrinterWorker.drain
assert_equal 0, PrinterWorker.jobs.size
class PrinterWorker
include Sidekiq::Worker
sidekiq_options queue: :default, retry: 0, backtrace: true
def perform(message)
@message = message
print_message_on_console
end
Rails.application.routes.draw do
mount Sidekiq::Web => '/sidekiq'
end
Sidekiq.configure_server do |config|
config.redis = { url: "redis://host-url:port" }
config.super_fetch! # ensure reliability
end
Sidekiq.configure_client do |config|
config.redis = { url: "redis://host-url:port" }
end
@BernardoMG
BernardoMG / application.rb
Last active May 5, 2019 10:55
aplication.rb
require_relative 'boot'
require 'rails/all'
require 'sidekiq-pro'
require 'sidekiq/pro/web'
Bundler.require(*Rails.groups)
module SidekiqConfig