Is there a way to mock the Clickatell::API.
What I Need:
Clickatell::API.authenticate('api_id', 'user', 'password') =>
<Clickatell::API:0x19a7f62 @auth_options={:session_id=>"session_id"}>
Thanks
Thanks for the reply.
What want to do is test a controller:
if Rails.env.production? || Rails.env.test?
begin
api = Clickatell::API.authenticate('api_id', 'user', 'password')
message_id = api.send_message(user.clickatel_phone_number, "Hello
World")
message_status = api.message_status(message_id)
### Update a object
user.update_attributes(:password => otp)
rescue SocketError => e
logger.debug(e.message)
flash[:notice] = "Connection to Clickatell Server is down'
end
end
I have 2 scenarios.
The First is the user is on the internet and can get to the
Clickatell::API, it generates a password, updates the user.password
and sends password via sms.
The Second is the user is not on the internet then should not try to
send sms and keep the password.
I want to mock the function authenticate and if it authenticate and
can send a message and then changes the user object (Mock what happens
when request is send to Clickatell::Api). Otherwise if its not on the
internet it should raise a SocketError (Mock the SocketError)
it "should make a http request to clickatell" do
lambda{
stub_request(:get, "http://api.clickatell.com/http/auth?
api_id=api_id&password=password&user=user").to_return(:body
=>{:auth_options => {:session_id => "session_id"}})
}.should_not raise_error ### this does not work
### this also does not work
mock("Clickatell::API", "authenticate" => {:auth_options =>
{:session_id => "76485fa246812ad2be7da75346490a6a"}})
lambda {post :controller_action, :user_info => {:user_id =>
1}.should change(user, :password)
end
Thanks for the reply will try it when I'm back at the office.
Gerhard
Clickatell::API.stubs(:authenticate).raises(SocketError)
I hope that helps.
--
You received this message because you are subscribed to the Google Groups
"mocha-developer" group.
To post to this group, send email to mocha-d...@googlegroups.com.
To unsubscribe from this group, send email to
mocha-develop...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/mocha-developer?hl=en.