【发布时间】:2015-06-02 18:59:09
【问题描述】:
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
需要'spec_helper'
describe Party do
before :each do
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'
如何使用 rspec 来确保 proccess_args 未被实际调用,而是被模拟以避免 ARGV 破坏我的测试?例如,我想伪造 proccess_args(2) 的调用以返回“Jason Wade”,并避免 ARGV[opt] 被 rspec 触及。
【问题讨论】:
-
向您展示规格文件会很有帮助
-
我已经包含了测试
标签: ruby-on-rails ruby rspec rspec-rails