2014-01-23 5 views
1

정확한 테스트 용어를 아는 사람이 있습니까? RSpec에이GoogleDrive API에 대한 RSpec 테스트 작성 방법

it "sends the request into Google spreadsheet" do 
    expect{ 
      post :create, request: FactoryGirl.attributes_for(:request) 
     }.to change(GoogleDrive::#some code that looks in the spreadsheet, :rows).by(1) 

같은 것, 그래서 내 컨트롤러는 아래 참고로, 내가 지금까지 배운 내용에서

def save_spreadsheet 
    connection = GoogleDrive.login(ENV['g_username'], ENV['g_password']) 
    ss = connection.spreadsheet_by_title('Test') 
    ws = ss.worksheets[0] 
    row = 1 + ws.num_rows #finds last row 
    ws[row, 1] = self.name 
    ... 
    ws.save 
    end 

답변

0

확인 방법 컨트롤러를 호출하고, 구글 스프레드 시트에 데이터를 저장

1) 테스트가 먼저 save_spreadsheet 메소드를 누르는 것은 좋지 않습니다. (이후 모든 테스트는 새로운 데이터 행을 생성 할 것이기 때문입니다.) 다음과 같은 이유로 테스트를 작성하지 않을 것입니다. 대신에 이것을 뽑아 내고 싶을 것입니다.

2) 실제로 테스트를하고 싶었지만 실제로 Rspec에서 비 Rails API를 테스트 할 수는 없습니다. 이 예제에서는 GoogleDrive 내부를보고 무엇이 있는지 확인할 수있는 테스트 기능이 없습니다.

관련 문제