This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> gem install converter-1.0.0.gem | |
> irb # ruby shell | |
>> require 'converter' | |
=> true | |
>> Converter.to_binary(2) | |
=> "10" | |
>> Converter.to_number("10") | |
=> 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PrinterWorker | |
include Sidekiq::Worker | |
sidekiq_options queue: :default, retry: 0, backtrace: true | |
def perform(message) | |
@message = message | |
print_message_on_console | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
mount Sidekiq::Web => '/sidekiq' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'boot' | |
require 'rails/all' | |
require 'sidekiq-pro' | |
require 'sidekiq/pro/web' | |
Bundler.require(*Rails.groups) | |
module SidekiqConfig |