如何使用Rspec存根method_options


Class CLI < Thor
desc "run [age]" "user passes age"
method_option :age,type:'numeric'
def run
variable=options[:a] if options[:a].present?
call_method(a)
end
end

如果我想测试下面的行,我如何使用Rspec模拟options[:a]

variable=options[:a] if options[:a].present?

此外,如何测试局部变量是否更新?

您可以模拟"选项">

let(:cli) { CLI.new }
allow(cli).to receive(:options){ { a:2 } }

相关内容

最新更新