Skip to content

Instantly share code, notes, and snippets.

View light_test.rb
require 'test_helper'
class LightTest < ActiveSupport::TestCase
test 'arguments are valid' do
assert_raises(ArgumentError) { Light.new(:pink, :unbroken, Arc.new(0, 90)) }
assert_raises(ArgumentError) { Light.new(:white, :test, Arc.new(0, 90)) }
assert_raises(ArgumentError) { Light.new(:white, :unbroken, 10) }
assert_nothing_raised { Light.new(:white, :unbroken, Arc.new(0, 90)) }
end
View light.rb
class Light
COLORS = %i[white green red yellow].freeze
TYPES = %i[unbroken flashing].freeze
attr_reader :color, :type, :arc
def initialize(color, type, arc)
raise ArgumentError unless COLORS.include?(color)
raise ArgumentError unless TYPES.include?(type)
raise ArgumentError unless arc.is_a?(Arc)
View arc_test.rb
require 'test_helper'
class ArcTest < ActiveSupport::TestCase
test 'arguments are valid' do
assert_raises(ArgumentError) { Arc.new(0, 400) }
assert_raises(ArgumentError) { Arc.new(-10, 200) }
assert_raises(ArgumentError) { Arc.new(0, 360) }
assert_nothing_raised { Arc.new(0, 90) }
end
View arc.rb
class Arc
def initialize(from, to)
raise ArgumentError if invalid?(from) || invalid?(to)
@from = from
@to = to
end
def to_s
"#{arc} degrees from #{@from} to #{@to}"
@macuk
macuk / phone2letters.rb
Last active Aug 29, 2015
Phone number to letters converter
View phone2letters.rb
Letters = {
'0' => %w(0),
'1' => %w(1),
'2' => %w(a b c),
'3' => %w(d e f),
'4' => %w(g h i),
'5' => %w(j k l),
'6' => %w(m n o),
'7' => %w(p q r s),
'8' => %w(t u v),
@macuk
macuk / mail-gem-problem.rb
Last active Dec 23, 2015
Mail gem problem
View mail-gem-problem.rb
# - Konfeo.com
# - Mail wysyłany jako organizator
# - ~ 15 000 wysyłanych maili miesięcznie
# ------------------------------------------------------------
# Kodowanie nagłówków maili
require 'mail'
m = Mail.new