ruby on rails - How to stub method in initialize with rspec -


class party     attr_accessor :number   include validations      def initialize         self.number = proccess_args(2)         puts luhn?     end      def proccess_args(opt)         argv[opt].downcase     end end 

require 'spec_helper'

describe party   before :each      new_method = party.method(:new)     allow(self).to receive(proccess_args).with(2).and_return('add')     @party = party.new    end end 

spec_helper.rb require_relative '../'

require 'yaml' 

how can use rspec, ensure proccess_args not called, simulated in order avoid argv blowing tests? example fake call of proccess_args(2) return "jason wade", , avoid argv[opt] ever being touched rspec.

allow(argv).to receive(:downcase).and_return('whatever')

you telling rspec allow argv receive method called :downcase and_return 'whatever' instead of calling in code being tested. (that part may not particularly useful, it's sort of explanation got click in head.)


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -