my_object.should_receive(:my_method).with(my_param).and_return(my_result)
expect_sent(my_object).my_method(my_param) == my_result
it "expect_send should add expectaction" do
user = Object.new
expect_sent(User).find(1) == user
User.find(1).should == user
end
module SpecHelper
def expect_sent receiver
ExpectSent.new receiver
end
end
class ExpectSent
instance_methods.each { |m|
undef_method m unless [:inspect, :__send__, :object_id].include? m
}
def initialize receiver
@receiver = receiver
end
def method_missing name, *args
AndReturn.new @receiver.should_receive(name).with(*args)
end
end
class AndReturn
def initialize from
@from = from
end
def == result
@from.and_return result
end
end
Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/Sof66O9blDs/11731