Skip to content

Instantly share code, notes, and snippets.

View zaagan's full-sized avatar
🤘
Hey !! Have a nice day

Ozesh Thapa zaagan

🤘
Hey !! Have a nice day
View GitHub Profile
@zaagan
zaagan / rspec_model_testing_template.rb
Created February 9, 2020 12:36 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@zaagan
zaagan / Ruby Basics - Custom Exceptions.rb
Created January 27, 2020 17:59
Ruby Basics - Custom Exceptions
class CustomException < StandardError
attr_reader :message, :error_id
def initialize(message, error_id)
@message = message
@error_id = error_id
end
end
begin
@zaagan
zaagan / Ruby Basics - Exception Handling.rb
Created January 27, 2020 17:58
Ruby Basics - Exception Handling
# Example 1
begin
x = 5 / 0
rescue
puts "Ohh no !!!"
ensure
puts "This will always execute"
end
# Example 2
@zaagan
zaagan / Ruby Basics - Upto & Downto.rb
Created January 27, 2020 17:17
Ruby Basics - Upto & Downto
1.upto 5 do |i|
puts i
end
# 1
# ...
# 5
5.downto 1 do |i|
puts i
end
@zaagan
zaagan / Ruby Basics - Case Statements.rb
Created January 27, 2020 17:04
Ruby Basics - Case Statements
number = 1
case number
when 1 then puts "One"
when 2 then puts "Two"
else puts "Zero"
end
@zaagan
zaagan / Ruby Basics - If Else Operators.rb
Created January 27, 2020 15:53
Ruby Basics - If Else Operators
cond1 = cond3 = true
cond2 = cond4 = false
if cond1 and cond3 then puts "1" end
if cond1 and not cond3 then puts "2" end
if cond1 or cond2 then puts '3' end
if cond1 && cond3 then puts '1' end
if cond1 && !cond3 then puts '2' end
if cond1 || cond2 then puts '3' end
@zaagan
zaagan / Ruby Basics - Inverse Predicate.rb
Created January 27, 2020 15:50
Ruby Basics - Inverse Predicate
response = :greeting
if response != :greeting
puts 'Hey'
# ignore
else
puts 'Ok'
end
# Similar to
@zaagan
zaagan / Ruby Basics - If Elsif.rb
Created January 27, 2020 15:47
Ruby Basics - If Elsif
response = :greeting
if response == :greeting
puts "Hello !"
elsif response == :shout
puts "Don't yel"
else
puts "Huh ?"
end
@zaagan
zaagan / Ruby Basics - If Else.rb
Created January 27, 2020 15:45
Ruby Basics - If Else
response = :greeting
# If Statement
if response == :greeting
puts "Hello !"
end
# Good
if response == :greeting then puts "Hello !" end
@zaagan
zaagan / Ruby Basics - Modules.rb
Created January 27, 2020 14:38
Ruby Basicsl - Modules
module Math
def add(x, y)
x + y
end
def sub(x, y)
x - y
end
module More