Skip to content

Commit

Permalink
bing/test_api.rb: adding some basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
godfat committed Nov 4, 2011
1 parent 06ccb5e commit 54d4754
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/client/bing/test_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

require 'rest-more/test'

describe RC::Bing do
after do
WebMock.reset!
RR.verify
end

def stub_with body, query={}
stub_request(:get, 'http://api.bing.net/json.aspx').
with(:query => {'JsonType' => 'raw', 'Version' => '2.2'}.merge(query)).
to_return(:body => body)
end

should 'get right' do
stub_with('{"status":"OK"}')
RC::Bing.new.get('').should.eq({'status' => 'OK'})
end

should 'be able to set AppId' do
RC::Bing.new(:AppId => 'QQ').AppId.should.eq 'QQ'
end

should 'use AppId for requests' do
stub_with('{}', 'AppId' => 'zz')
RC::Bing.new(:AppId => 'zz').get('').should.eq({})
end

should 'raise correct error' do
stub_with('{"SearchResponse":{"Errors":[{"Code":2003}]}}')
lambda{RC::Bing.new.get('')}.should.raise(RC::Bing::Error::NoAccess)
end
end

0 comments on commit 54d4754

Please sign in to comment.