ruby on rails - writing spec for method that hits a web service -


i'm writing spec verify video model create proper thumbnail vimeo video when created. looks this:

    "creates thumbnail url"       vimeo_url = "http://player.vimeo.com/video/12345"       vid = factory.build(:video, video_url:vimeo_url)       # thumbnail created when saved       vid.save!        expect         uri.parse(vid.thumbnail_url)       end.to_not raise_error     end 

the problem test super slow because has hit vimeo.com. i'm trying stub method calls server. 2 questions:

1) correct way/time stub something

2) if yes, how stub it? in video model have method called get_vimeo_thumbnail() hits vimeo.com. want stub method. if in spec vid.stub(:get_vimeo_thumbnail).and_return("http://someurl.com") doesn't work. when run test still hits vimeo.com.

the vcr gem worth considering. hits real web service first time run , records response can replayed next time run test (making subsequent tests fast).

i can't see wrong stub call making if calling stub before save!.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -