2015-01-15 1 views
1

캐 러셀에 대한 다형성 모델을 제공하는 비대화 형 컨트롤러를 리팩토링하는 중입니다. 나는 회귀 할 수있는 항목을 찾고 돌려주는 것을 처리하는 클래스 메쏘드를 만들려고 노력하고있다.Rspec 메서드 내에서 생성 된 객체를 스텁하는 방법

내 RSPEC 테스트에서 메소드를 스텁하고 싶습니다. 'is_something?' params의 결과로 발견 된 장소에서.

def self.find_carouselable(params) 
    ....... 
    elsif params[:venue_id].present? 
     venue=Venue.friendly.find(params[:venue_id]) 
     if venue.is_something? 
     do this 
     else 
     do that 
     end 
    end 
    end 

I는 입력 된 데이터의 결과로 생성되는 객체 스텁 방법을 작동하지 못할 - 나는 확실하지 않다 이것은 스터 빙 또는 조롱 호출되는 경우를?

context "carouselable is a venue" do 
    before do 
     allow(the_venue).to receive(:is_something?).and_return(true) 
    end 

    it "returns the instance of the carouselable object" do 
     expect(CopperBoxCarouselItem.find_carouselable(venue_params)).to eq the_venue 
    end 
    end 

많은 감사

당신은처럼 장소 비트를 스텁 필요

답변

2

그래서

 before do 
     allow(Venue).to receive(:friendly).and_return(some_venues) 
     allow(some_venues).to receive(:find).and_return(venue) 
     allow(venue).to receive(:is_something?).and_return(true) 
     end 
관련 문제