This file contains 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
# 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: |
This file contains 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 CustomException < StandardError | |
attr_reader :message, :error_id | |
def initialize(message, error_id) | |
@message = message | |
@error_id = error_id | |
end | |
end | |
begin |
This file contains 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
# Example 1 | |
begin | |
x = 5 / 0 | |
rescue | |
puts "Ohh no !!!" | |
ensure | |
puts "This will always execute" | |
end | |
# Example 2 |
This file contains 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
1.upto 5 do |i| | |
puts i | |
end | |
# 1 | |
# ... | |
# 5 | |
5.downto 1 do |i| | |
puts i | |
end |
This file contains 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
number = 1 | |
case number | |
when 1 then puts "One" | |
when 2 then puts "Two" | |
else puts "Zero" | |
end |
This file contains 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
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 |
This file contains 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
response = :greeting | |
if response != :greeting | |
puts 'Hey' | |
# ignore | |
else | |
puts 'Ok' | |
end | |
# Similar to |
This file contains 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
response = :greeting | |
if response == :greeting | |
puts "Hello !" | |
elsif response == :shout | |
puts "Don't yel" | |
else | |
puts "Huh ?" | |
end |
This file contains 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
response = :greeting | |
# If Statement | |
if response == :greeting | |
puts "Hello !" | |
end | |
# Good | |
if response == :greeting then puts "Hello !" end | |
This file contains 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
module Math | |
def add(x, y) | |
x + y | |
end | |
def sub(x, y) | |
x - y | |
end | |
module More |