2014-01-23 72 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内部并查看有哪些内容