55
66class VideoServiceTest < MiniTest ::Test
77
8- class VideoRepoMock
8+ class VideoRepoStub
99 def videos
1010 [ { 'youtubeID' => 'blahblahblah' , 'views' => 3 , 'monthlyViews' => 3 } ]
1111 end
1212 end
1313
14- class YoutubeVideoClientMock
15- def get_video_stats ( ids = :NotGiven )
14+ class YoutubeVideoClientStub
15+ def video_stats ( ids = :NotGiven )
1616 { 'items' =>
1717 [
1818 {
@@ -26,16 +26,15 @@ def get_video_stats(ids=:NotGiven)
2626 end
2727
2828 def test_video_list_returns_video_list
29- video_service = VideoService . new ( video_repo : VideoRepoMock . new )
29+ video_service = VideoService . new ( video_repo : VideoRepoStub . new , video_client : YoutubeVideoClientStub . new )
3030 video_array = [ { 'youtubeID' => 'blahblahblah' , 'views' => 3 , 'monthlyViews' => 3 } ]
31- youtube_response = YoutubeVideoClientMock . new . get_video_stats ( )
3231 video_json = JSON . generate ( video_array )
33- video_service . stub ( :get_youtube_stats_on_videos , youtube_response ) do
34- result = JSON . parse ( video_service . video_list )
35- actual = JSON . parse ( video_json )
36- assert_equal ( result [ 0 ] [ 'youtubeID' ] , result [ 0 ] [ 'youtubeID' ] )
37- assert_equal ( result [ 0 ] [ 'views' ] , result [ 0 ] [ 'views' ] )
38- assert_in_delta ( result [ 0 ] [ 'monthlyViews' ] , result [ 0 ] [ 'monthlyViews' ] , 0.1 )
39- end
32+
33+ result = JSON . parse ( video_service . video_list )
34+ actual = JSON . parse ( video_json )
35+ assert_equal ( result [ 0 ] [ 'youtubeID' ] , result [ 0 ] [ 'youtubeID' ] )
36+ assert_equal ( result [ 0 ] [ 'views' ] , result [ 0 ] [ 'views' ] )
37+ assert_in_delta ( result [ 0 ] [ 'monthlyViews' ] , result [ 0 ] [ 'monthlyViews' ] , 0.1 )
38+
4039 end
4140end
0 commit comments