lundi 23 mars 2020

Rspec - Mock the model method

I have following methods,

Model/Summary.cs

def show_summary
    device_lastest_reading = lastest_reading
  end

Model/Reading.cs

def lastest_reading
    select_readings(start_date, last_date)
  end

The lastest_reading method get the values from a hardware. I have created a DummyReading.rb for RSPEC and placed the lastest_reading method as like below,

DummyReading.rb

def lastest_reading
    {
      :a=>13,
      :b=>"7666",
      :c=>6729690,
    }
  end

here is what i tried,

it "should return summary data" do
        allow(DummyReading.lastest_reading).to receive(Model.show_summary).and_return({})
      end

I an getting error "undefined methodto_sym' for {}:Hash`"

In rspec how to mock/stub this device_lastest_reading variable.

Thank you.

Aucun commentaire:

Enregistrer un commentaire