Skip to content

Instantly share code, notes, and snippets.

View Karlotcha's full-sized avatar

Karlotcha Hoa Karlotcha

  • San Francisco - California
View GitHub Profile
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@Karlotcha
Karlotcha / gist:7083263
Created October 21, 2013 12:42
Tail call recursion - Fibonacci
# tail call optimization
RubyVM::InstructionSequence.compile_option = {:tailcall_optimization => true,:trace_instruction => false}
# Fibonacci sequence
def fib(n,tail,tail2)
return 1 if n == 1
return 1 if n == 2
return tail + tail2 if n == 3
fib(n-1, tail2, tail+tail2)
end