mardi 5 avril 2016

rspec a sub-class optparse variable

The main problem that Im facing here is that I can not define/reach the "pos" variable inside my sub-class Optparse below from my rspec code. When I try to run "cp_op" method below, which consist of the output that I want to get, I got an error message saying the pos is "undefined method pos"

What should I do so that I can get the right output from options.pos? which it should be equal to 100

Ruby code:

class Verifier
  def initialize(args)
    @options = Optparse.parse(arg)
  end
   .
   .

  class Optparse
     .
     .
    def self.parse(args)
     .
     .
      options = OpenStruct.new
      options.pos = nil
     .
     .
    end
  end

  def cp_op
    @options.pos
  end
end

RSPEC code

describe Verifier do
  describe '.cp_op' do
    let (:veri) { Verifier.new(["--pos","100"]) }
    #or even this line: let (:veri) {Verifier.new(["--pos", "100"])::Optparse}

    it 'return 100' do
      expect(veri.cp_op).to eql(100)
    end
  end
end

Aucun commentaire:

Enregistrer un commentaire