test/songkickr/test_remote.rb in songkickr-0.2.2 vs test/songkickr/test_remote.rb in songkickr-0.3.0

- old
+ new

@@ -1,6 +1,7 @@ require 'helper' +require 'vcr_helper' class TestRemote < Test::Unit::TestCase context "Given a remote with no api key" do should "raise an APIKeyNotSet exception when created with no key" do assert_raise APIKeyNotSet do @@ -9,47 +10,90 @@ end end context "Given an invalid Resource" do setup do - FakeWeb.register_uri(:get, 'http://api.songkick.com/api/3.0/events/123.json?apikey=omgwtfbbq_fake_key', :body => fixture_file('resource_not_found.json')) - FakeWeb.register_uri(:get, 'http://api.songkick.com/api/3.0/venues/123.json?apikey=omgwtfbbq_fake_key', :body => fixture_file('resource_not_found.json')) - @remote = Songkickr::Remote.new 'omgwtfbbq_fake_key' + @remote = Songkickr::Remote.new api_key end - should "raise an ResouceNotFound exception when search a songkick event id doesn't exist" do - assert_raise ResouceNotFound do - @remote.event(123) + should "raise a ResourceNotFound exception when search a songkick event id doesn't exist" do + VCR.use_cassette('invalid_event_id') do + assert_raise ResourceNotFound do + @remote.event(123123123123123123123123) + end end end - should "raise an ResouceNotFound exception when search a songkick venue id doesn't exist" do - assert_raise ResouceNotFound do - @remote.venue(123) + should "raise an ResourceNotFound exception when search a songkick venue id doesn't exist" do + VCR.use_cassette('invalid_venue_id') do + assert_raise ResourceNotFound do + @remote.venue(123123123123123123123123) + end end end + + should "raise an ResourceNotFound exception when search a user doesn't exist" do + VCR.use_cassette('invalid_user') do + assert_raise ResourceNotFound do + @remote.users_tracked_artists("fffffffbbbbbbbbaaaarrrrrrrr") + end + end + end + end -# TODO: Fix this later context "Given a remote with an invalid api key" do setup do - stub_get('http://api.songkick.com/api/3.0/events.json', 'events.json') @remote = Songkickr::Remote.new 'omgwtfbbq_fake_key' end - + should "generate a remote" do assert_not_nil @remote end - - # to make it work it needs: - # 1) registering GET http://api.songkick.com/api/3.0/events.json?apikey=omgwtfbbq_fake_key - # and its variants with fakeweb OR allowing real http connections - # 2) checking that returned json equals fixtures/invalid_api_key.json - # - #should "generate nil results" do - # [{}, ':artist_name => ""', ':artist_name => "Madonna"'].each do |remote_params| - # assert_nil @remote.send(:events, remote_params).results - # end - #end + + should "raise an API Error when the API key is wrong" do + VCR.use_cassette('invalid_api_key') do + assert_raise APIError do + @remote.event(17522) + end + end + end + end - + + + context "Given a valid resource" do + setup do + @remote = Songkickr::Remote.new api_key + end + + should "return the correct event for an existing event id " do + VCR.use_cassette('valid_event') do + result = @remote.event(17522) + assert_equal 17522, result.id + end + end + + + should "return the correct venue for a given venue id " do + VCR.use_cassette('valid_venue') do + result = @remote.venue(17522) + assert_equal 17522, result.id + end + end + + should "return the correct tracked artists for an existing user" do + VCR.use_cassette('valid_user') do + result = @remote.users_tracked_artists("nigelpurves") + assert_equal "2:54", result.results.first.display_name + end + end + + + end + + + def api_key + 'hFYxiInE4DBpH5KL' + end + end