Skip to content

Commit

Permalink
bumped up rspec; cleaned up specs
Browse files Browse the repository at this point in the history
  • Loading branch information
philm committed Jan 12, 2013
1 parent 85c0f9c commit 04a4639
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 181 deletions.
46 changes: 23 additions & 23 deletions spec/fixtures/yml/verb_responses.yml
@@ -1,42 +1,42 @@
play_mp3:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Play loop="1">http://foo.com/cowbell.mp3</Play></Response>

play_mp3_two_times:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Play loop="2">http://foo.com/cowbell.mp3</Play></Response>

play_mp3_two_times_with_pause:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Play>http://foo.com/cowbell.mp3</Play><Pause/><Play>http://foo.com/cowbell.mp3</Play></Response>

gather:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather/></Response>

gather_with_action:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather action="http://foobar.com"/></Response>

gather_with_get_method:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather method="GET"/></Response>

gather_with_timeout:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather timeout="10"/></Response>

gather_with_finish_key:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather finishOnKey="*"/></Response>

gather_with_num_digits:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather numDigits="5"/></Response>

record:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Record></Record></Response>
response: <?xml version="1.0" encoding="UTF-8"?><Response><Record/></Response>

record_with_action:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Record action="http://foobar.com"/></Response>

record_with_get_method:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Record method="GET"/></Response>

record_with_timeout:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Record timeout="10"/></Response>

record_with_finish_key:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Record finishOnKey="*"/></Response>

Expand All @@ -45,30 +45,30 @@ record_with_max_length:

dial:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial>415-123-4567</Dial></Response>

dial_with_action:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial action="http://foobar.com">415-123-4567</Dial></Response>

dial_with_get_method:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial method="GET">415-123-4567</Dial></Response>

dial_with_timeout:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial timeout="10">415-123-4567</Dial></Response>

dial_with_hangup_on_star:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial hangupOnStar="true">415-123-4567</Dial></Response>

dial_with_time_limit:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial timeLimit="3600">415-123-4567</Dial></Response>

dial_with_caller_id:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial callerId="858-987-6543">415-123-4567</Dial></Response>

dial_with_redirect:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial>415-123-4567</Dial><Redirect>http://www.foo.com/nextInstructions</Redirect></Response>

dial_with_number_and_send_digits:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial><Number sendDigits="wwww1928">415-123-4567</Number></Dial></Response>
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial><Number sendDigits="wwww1928">415-123-4567</Number></Dial></Response>

dial_multiple_numbers:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial><Number>415-123-4567</Number><Number>415-123-4568</Number><Number>415-123-4569</Number></Dial></Response>
Expand All @@ -78,9 +78,9 @@ dial_conference:

dial_muted_conference:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial><Conference mute="true">MyRoom</Conference></Dial></Response>

hangup:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Hangup/></Response>
response: <?xml version="1.0" encoding="UTF-8"?><Response><Hangup/></Response>

reject:
response: <?xml version="1.0" encoding="UTF-8"?><Response><Reject/></Response>
response: <?xml version="1.0" encoding="UTF-8"?><Response><Reject/></Response>
26 changes: 13 additions & 13 deletions spec/support/twilio_helpers.rb
@@ -1,35 +1,35 @@
module TwilioHelpers #:nodoc:
def stub_http_request(http_method, fixture_name, *opts)

def stub_http_request(http_method, fixture_name, *opts)
if opts
request_options = opts.pop if opts.last.is_a?(Hash)
resource = opts.pop
end
fake_response = fixture(fixture_name)

fake_response = fixture(fixture_name)
url = twilio_url(resource)

if request_options
stub_request(http_method, url).with(request_options).to_return(:body => fake_response)
else
stub_request(http_method, url).to_return(:body => fake_response)
end

return fake_response, url
end

def stub_get(fixture, *opts)
stub_http_request(:get, fixture, *opts)
stub_http_request(:get, fixture, *opts)
end

def stub_post(fixture, *opts)
stub_http_request(:post, fixture, *opts)
end

def stub_put(fixture, *opts)
stub_http_request(:put, fixture, *opts)
end

def stub_delete(fixture, *opts)
stub_http_request(:delete, fixture, *opts)
end
Expand All @@ -38,9 +38,9 @@ def verb_response(verb)
path = File.join(File.dirname(__FILE__), "../fixtures/yml/verb_responses.yml")
YAML.load_file(path)[verb.to_s]['response']
end

private

def twilio_url(url=nil)
"https://mysid:mytoken@api.twilio.com:443/2010-04-01/Accounts/mysid#{'/' + url if url}"
end
Expand Down
16 changes: 8 additions & 8 deletions spec/twilio/account_spec.rb
@@ -1,21 +1,21 @@
require 'spec_helper'

describe 'Account' do
describe 'Account' do
before(:all) do
Twilio.connect('mysid', 'mytoken')
end
it "gets an account" do

it "gets an account" do
response, url = stub_get(:account)
Twilio::Account.get.should == response

Twilio::Account.get.should eql response
WebMock.should have_requested(:get, twilio_url)
end

it "updates name" do
response, url = stub_put(:account_renamed)
Twilio::Account.update_name('Bubba').should == response

Twilio::Account.update_name('Bubba').should eql response
WebMock.should have_requested(:put, twilio_url).with(:body => {:FriendlyName => 'Bubba'})
end
end
48 changes: 24 additions & 24 deletions spec/twilio/available_phone_numbers_spec.rb
@@ -1,52 +1,52 @@
require 'spec_helper'

describe "Available Phone Numbers" do
describe "Available Phone Numbers" do
before(:all) do
Twilio.connect('mysid', 'mytoken')
end

context "Local Number" do
it "is searchable" do
it "is searchable" do
response, url = stub_get(:available_phone_numbers_local, 'AvailablePhoneNumbers/US/Local')
Twilio::AvailablePhoneNumbers.search_local.should == response

Twilio::AvailablePhoneNumbers.search_local.should eql response
WebMock.should have_requested(:get, url)
end
it "is searchable by area code" do

it "is searchable by area code" do
response, url = stub_get(:available_phone_numbers_local_search, 'AvailablePhoneNumbers/US/Local?AreaCode=510')
Twilio::AvailablePhoneNumbers.search_local(:area_code => 510).should == response

Twilio::AvailablePhoneNumbers.search_local(:area_code => 510).should eql response
WebMock.should have_requested(:get, url)
end
it "is searchable by postal code" do

it "is searchable by postal code" do
response, url = stub_get(:available_phone_numbers_local_search, 'AvailablePhoneNumbers/US/Local?InPostalCode=94612')
Twilio::AvailablePhoneNumbers.search_local(:postal_code => 94612).should == response

Twilio::AvailablePhoneNumbers.search_local(:postal_code => 94612).should eql response
WebMock.should have_requested(:get, url)
end
it "is searchable using multiple parameters" do

it "is searchable using multiple parameters" do
response, url = stub_get(:available_phone_numbers_local_search, 'AvailablePhoneNumbers/US/Local?NearLatLong=37.806940%2C-122.270360&InRateCenter=OKLD0349T&NearNumber=15105551213&Distance=50&InRegion=CA&InLata=722&Contains=510555****&Page=2&PageSize=30')
Twilio::AvailablePhoneNumbers.search_local(:in_region => 'CA', :contains => '510555****', :near_lat_long => '37.806940,-122.270360', :near_number => '15105551213', :in_lata => 722, :in_rate_center => 'OKLD0349T', :distance => 50, :page => 2, :page_size => 30).should == response

Twilio::AvailablePhoneNumbers.search_local(:in_region => 'CA', :contains => '510555****', :near_lat_long => '37.806940,-122.270360', :near_number => '15105551213', :in_lata => 722, :in_rate_center => 'OKLD0349T', :distance => 50, :page => 2, :page_size => 30).should eql response
WebMock.should have_requested(:get, url)
end
end

context "Toll-free Number" do
it "is searchable" do
it "is searchable" do
response, url = stub_get(:available_phone_numbers_toll_free, 'AvailablePhoneNumbers/US/TollFree')
Twilio::AvailablePhoneNumbers.search_toll_free.should == response

Twilio::AvailablePhoneNumbers.search_toll_free.should eql response
WebMock.should have_requested(:get, url)
end
it "is searchable as a vanity number" do

it "is searchable as a vanity number" do
response, url = stub_get(:available_phone_numbers_toll_free_search, 'AvailablePhoneNumbers/US/TollFree?Contains=STORM')
Twilio::AvailablePhoneNumbers.search_toll_free(:contains => 'STORM').should == response

Twilio::AvailablePhoneNumbers.search_toll_free(:contains => 'STORM').should eql response
WebMock.should have_requested(:get, url)
end
end
Expand Down
48 changes: 24 additions & 24 deletions spec/twilio/call_spec.rb
Expand Up @@ -5,60 +5,60 @@
Twilio.connect('mysid', 'mytoken')
@call_sid = 'CA42ed11f93dc08b952027ffbc406d0868'
end

it "can be made" do
response, url = stub_post(:call_new, 'Calls')
Twilio::Call.make('4158675309', '4155551212', 'http://localhost:3000/call_handler').should == response

Twilio::Call.make('4158675309', '4155551212', 'http://localhost:3000/call_handler').should eql response
WebMock.should have_requested(:post, url)
end

it "can be redirected" do
response, url = stub_post(:call_redirected, "Calls/#{@call_sid}")
Twilio::Call.redirect(@call_sid, 'http://localhost:3000/redirect_handler').should == response

Twilio::Call.redirect(@call_sid, 'http://localhost:3000/redirect_handler').should eql response
WebMock.should have_requested(:post, url)
end

it "gets a list of calls" do
response, url = stub_get(:calls, 'Calls')
Twilio::Call.list.should == response

Twilio::Call.list.should eql response
WebMock.should have_requested(:get, url)
end

it "gets a specific call" do
response, url = stub_get(:calls, "Calls/#{@call_sid}")
Twilio::Call.get(@call_sid).should == response

Twilio::Call.get(@call_sid).should eql response
WebMock.should have_requested(:get, url)
end

it "gets a list of call segments" do
response, url = stub_get(:calls, "Calls/#{@call_sid}/Segments")
Twilio::Call.segments(@call_sid).should == response

Twilio::Call.segments(@call_sid).should eql response
WebMock.should have_requested(:get, url)
end

it "gets a specific call segment" do
response, url = stub_get(:calls, "Calls/#{@call_sid}/Segments/abc123")
Twilio::Call.segments(@call_sid, 'abc123').should == response

Twilio::Call.segments(@call_sid, 'abc123').should eql response
WebMock.should have_requested(:get, url)
end

it "gets a list of call recordings" do
response, url = stub_get(:recordings, "Calls/#{@call_sid}/Recordings")
Twilio::Call.recordings(@call_sid).should == response

Twilio::Call.recordings(@call_sid).should eql response
WebMock.should have_requested(:get, url)
end

it "gets a list of call notifications" do
response, url = stub_get(:notifications, "Calls/#{@call_sid}/Notifications")
Twilio::Call.notifications(@call_sid).should == response

Twilio::Call.notifications(@call_sid).should eql response
WebMock.should have_requested(:get, url)
end
end

0 comments on commit 04a4639

Please sign in to comment.