Question

Does anyone know the correct testing terminology? My controller saves data into a Google Spreadsheet, so the Rspec would be something like

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
Was it helpful?

Solution

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). 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; there's no test feature in this example case that will allow you to look inside the GoogleDrive and see what's there

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top