How to test variable assignment in RSpec

def hide_gridlines(sheet, hide_gridlines)
  sheet.sheet_view.show_grid_lines = false if hide_gridlines
 end

I need to test this method in RSpec / Ruby, and I want to write two tests, one to see if this code sheet.sheet_view.show_grid_lines = false executes if hide_gridlines is true.

The other is to ensure that code sheet.sheet_view.show_grid_lines = false does not run if hide_gridlines is false.

sheet is a worksheet that comes from the Axlsx Gem, and I created a double, but I'm not sure how to setup the double to have a sheet_view, and then test the variable declaration.

Any pointers on how to test this in RSpec, your help would be appreciated.

Answers


context 'set sheet.sheet_view.show_grid_lines to' do
  let(:sheet_view) { double }
  let(:sheet) { double(sheet_view: sheet_view) }

  specify 'false if hide_gridlines' do
    expect(sheet_view).to receive(:show_grid_lines=).with(false)
    subject.hide_gridlines(sheet, true)
  end

  specify 'true unless hide_gridlines' do
    expect(sheet_view).not_to receive(:show_grid_lines=)
    subject.hide_gridlines(sheet, false)
  end
end

Need Your Help

PHP Cronjob changing sh root

php cron crontab

Some setup background first:

How to display the frames of a video via Qt gui application ?

qt video opencv qt-creator

I am trying to process a video by playing with its frames via the methods of OpenCV library and display these frames with imshow method of opencv/highgui with no problem here.