控制台命令输出的rspec测试

控制台命令输出的rspec测试,rspec,sh,fastlane,Rspec,Sh,Fastlane,我在ruby中有以下代码片段 lizard_cli_version = Gem::Version.new(`lizard --version`.scan(/(?:\d+\.?){3}/).first) required_version = Gem::Version.new(Fastlane::Lizard::CLI_VERSION) if lizard_cli_version < required_version UI.user_error!("Your lizard version

我在ruby中有以下代码片段

lizard_cli_version = Gem::Version.new(`lizard --version`.scan(/(?:\d+\.?){3}/).first)
required_version = Gem::Version.new(Fastlane::Lizard::CLI_VERSION)
if lizard_cli_version < required_version
  UI.user_error!("Your lizard version is outdated, please upgrade to at least version #{Fastlane::Sentry::CLI_VERSION} and start your lane again!")
end
这是输出

Failures:

  1) Fastlane::Actions::LizardAction Lizard there is no lizard installed states lizard is needed and how to install
     Failure/Error: expect(FastlaneCore::UI).to receive(:user_error).with(/You have to install lizard using/)

       (FastlaneCore::UI (class)).user_error(/Your lizard version is outdated/)
           expected: 1 time with arguments: (/Your lizard version is outdated/)
           received: 0 times
     # ./spec/lizard_spec.rb:15:in `block (4 levels) in <top (required)>'

Finished in 1.48 seconds (files took 3.55 seconds to load)
17 examples, 1 failure
故障:
1) 快速通道::动作::蜥蜴动作蜥蜴没有安装蜥蜴状态需要蜥蜴以及如何安装蜥蜴
失败/错误:期望(FastlaneCore::UI)。接收(:user\u Error)。使用(/必须使用/)安装lizard
(FastlaneCore::UI(类))。用户错误(/您的蜥蜴版本已过时/)
预期:1次,参数:(/您的lizard版本已过时/)
收到:0次
#./spec/lizard_spec.rb:15:in'block(4层)in'
在1.48秒内完成(加载文件需要3.55秒)
17例,1例失败

有人对如何使这项工作起作用有任何建议吗?

了解这些信息并不容易,但可能是这方面的问题

expect(Fastlane::Actions).to receive(:sh).and_raise("1.14.1")
也许你想要的是使用
和_return
而不是
和_raise

expect(Fastlane::Actions).to receive(:sh).and_return("1.14.1")
在您的代码中,使用
Fastlane::Actions.sh
获取
lizard--version

Gem::Version.new(Fastlane::Actions.sh("lizard --version").scan(/(?:\d+\.?){3}/).first)

要知道问题出在哪里并不容易,但可能是这方面的问题

expect(Fastlane::Actions).to receive(:sh).and_raise("1.14.1")
也许你想要的是使用
和_return
而不是
和_raise

expect(Fastlane::Actions).to receive(:sh).and_return("1.14.1")
在您的代码中,使用
Fastlane::Actions.sh
获取
lizard--version

Gem::Version.new(Fastlane::Actions.sh("lizard --version").scan(/(?:\d+\.?){3}/).first)

当您运行测试时,您会得到什么响应?另外,请显示包含生成错误的代码片段的类和方法。运行测试时您会得到什么响应?另外,请显示包含生成错误的代码片段的类和方法。失败:1)Fastlane::Actions::Lizard Lizard版本1.14.1安装状态Lizard需要升级到至少1.14.10失败/错误:预期执行Fastlane::FastFile.new.parse(“lane:test do lizard end”).runner.execute(:test)end.to raise_error(/您的蜥蜴版本已过时/)预期/您的蜥蜴版本已过时/但未引发任何问题。#/spec/lizard_spec.rb:20:in“block(4个级别)in”在1.41秒内完成(加载文件需要3.73秒)您应该使用
Actions.sh
获取“蜥蜴版”(而不是反勾号)因此,您可以执行Benito概述的expect。我在答案中添加了一行注释@LyndseyFergusonFailures:1)Fastlane::Actions::Lizard Lizard version 1.14.1安装状态Lizard需要升级到至少1.14.10失败/错误:expect do Fastlane::FastFile.new.parse(“lane:test do lizard end“).runner.execute(:test)end.to raise_error(/您的蜥蜴版本已过时/)预期/您的蜥蜴版本已过时/但未引发任何问题。#/spec/lizard_spec.rb:20:in“block(4个级别)in”在1.41秒内完成(加载文件需要3.73秒)你应该使用
Actions.sh
来获得“蜥蜴版”(而不是反勾号),这样你就可以执行Benito概述的expect。我在答案中添加了一行@LyndseyFerguson的注释