Skip to content

Instantly share code, notes, and snippets.

@tjackiw
Created June 22, 2012 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjackiw/2970940 to your computer and use it in GitHub Desktop.
Save tjackiw/2970940 to your computer and use it in GitHub Desktop.
Adding SMS capabilities to your Rails Application
require 'test_helper'
class MockedTwilioClient
def method_missing(*args)
self
end
end
class UsersControllerTest < ActionController::TestCase
test "#new" do
get :new
assert_response :success
assert_template :new
end
test "#create succeeds" do
mock(Twilio::REST::Client).new('',''){ MockedTwilioClient.new }
assert_difference 'User.count' do
post :create, user: {name: 'John Doe', email: 'john@doe.com', phone: '555-444-3434'}
assert_response :ok
end
end
test "#create fails on validation" do
assert_no_difference 'User.count' do
post :create, user: {name: 'Joe'}
assert_response :ok
assert_template :new
assert !assigns(:user).valid?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment