简体   繁体   English

如何为GoogleDrive API编写RSpec测试

[英]How to write an RSpec test for GoogleDrive API

Does anyone know the correct testing terminology? 有人知道正确的测试术语吗? My controller saves data into a Google Spreadsheet, so the Rspec would be something like 我的控制器将数据保存到Google Spreadsheet中,因此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) 

Below is the method that the controller calls, FYI 以下是控制器调用的方法,仅供参考

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

OK from what I've learned to date, you actually wouldn't write a test for this, because: 从我到目前为止所学的知识来看还可以,实际上您不会为此编写测试,因为:

1) it's not good convention to have tests hit the save_spreadsheet method in the first place (since then every test will create a new row of data). 1)按照惯例,首先要使测试命中save_spreadsheet方法是不好的习惯(因为每个测试都会创建新的数据行)。 Instead you'll want to stub this out. 相反,您将需要对此进行存根。

2) Even if you were ok with that and somehow wanted to write a test, you actually can't write a test in Rspec for a significant number of non-Rails APIs; 2)即使您可以接受并且以某种方式想要编写测试,您实际上也无法在Rspec中为大量非Rails API编写测试; there's no test feature in this example case that will allow you to look inside the GoogleDrive and see what's there 在此示例情况下,没有测试功能,可让您查看GoogleDrive的内部内容并查看其中的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM