Skip to content

Instantly share code, notes, and snippets.

@masarakki
masarakki / sample_of_alias_class_method.rb
Created December 2, 2010 08:28
HOW TO alias class method in ruby
class BaseClass
def self.find
"find"
end
end
# in class definition
class ClassA < BaseClass
def self.find_with_my_name
find_without_my_name + " ClassA"
@masarakki
masarakki / auto_define_mock_method
Created October 8, 2010 03:55
auto mock_xxxx hack
#
# write it in the bottom of spec/spec_helper.rb
#
def method_missing(name, *args)
if matched = name.to_s.match(/mock_(.*)/)
klass = matched[1].classify.constantize
var_name = "@#{name.to_s}"
self.class.send(:define_method, name) do |*stubs|
stubs = stubs.try(:first) || {}
instance_variable_get(var_name) ||
#
# extension for rspec
# this extension enables to check should_receive in stub_chain
# you must require this file in 'spec/spec_helper.rb'
#
#
# Example:
# in controller,
#
# def index