mattt / mtv-music

Ruby library for the MTV Music API

This URL has Read+Write access

mtv-music / test / test_mtv_music_video.rb
100644 53 lines (42 sloc) 1.602 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require File.dirname(__FILE__) + '/test_helper.rb'
 
class TestYahooMusicRelease < Test::Unit::TestCase
  def test_video_initialization_from_alias
    flexmock(Video).should_receive(:fetch_and_parse).
      once.with("video/hznHivqrbHHZBZNXB").
      and_return(Hpricot::XML(fixture(:there_there)))
    
    assert_nothing_raised do
      @video = Video.new("hznHivqrbHHZBZNXB")
    end
  end
  
  def test_artist_nonexistent_id_error
    flexmock(Video).should_receive(:fetch_and_parse).
      once.with("video/nil").
      and_return(Hpricot::XML(fixture(:nil_video)))
    
    assert_raise MTVNetworkServiceError do
      @artist = Video.new("nil")
    end
  end
  
  def test_video_class_attributes_and_associations
    flexmock(Video).should_receive(:fetch_and_parse).
      once.with("video/hznHivqrbHHZBZNXB").
      and_return(Hpricot::XML(fixture(:there_there)))
    
    assert_nothing_raised do
      @video = Video.new("hznHivqrbHHZBZNXB")
    end
    
    assert ! Video.attributes.empty?
    Video.attributes.keys.each do |attribute|
      assert_respond_to @video, attribute
    end
  end
  
  def test_video_instance_variables
    flexmock(Video).should_receive(:fetch_and_parse).
      once.with("video/hznHivqrbHHZBZNXB").
      and_return(Hpricot::XML(fixture(:there_there)))
    
    assert_nothing_raised do
      @video = Video.new("hznHivqrbHHZBZNXB")
    end
    
    assert_equal @video.id, "hznHivqrbHHZDPSP"
    assert_equal @video.title, "There There"
    assert_equal @video.director, "Chris Hopewell"
  end
end