我有一个 RSpec 文件
./spec/pkg/abc_spec.rb
,使用 aruba
,测试在命令花费很长时间时经常崩溃,但如果命令快速返回则不会崩溃。
堆栈跟踪失败;
# /home/skenvy/.rvm/gems/ruby-3.1.0/gems/aruba-2.1.0/lib/aruba/rspec.rb:35:in `block (3 levels) in <top (required)>'
# /home/skenvy/.rvm/gems/ruby-3.1.0/gems/aruba-2.1.0/lib/aruba/platforms/local_environment.rb:22:in `call'
# /home/skenvy/.rvm/gems/ruby-3.1.0/gems/aruba-2.1.0/lib/aruba/platforms/unix_platform.rb:79:in `with_environment'
# /home/skenvy/.rvm/gems/ruby-3.1.0/gems/aruba-2.1.0/lib/aruba/api/core.rb:222:in `block in with_environment'
# /home/skenvy/.rvm/gems/ruby-3.1.0/gems/aruba-2.1.0/lib/aruba/platforms/unix_environment_variables.rb:189:in `nest'
# /home/skenvy/.rvm/gems/ruby-3.1.0/gems/aruba-2.1.0/lib/aruba/api/core.rb:220:in `with_environment'
# /home/skenvy/.rvm/gems/ruby-3.1.0/gems/aruba-2.1.0/lib/aruba/rspec.rb:34:in `block (2 levels) in <top (required)>'
# /home/skenvy/.rvm/gems/ruby-3.1.0/gems/aruba-2.1.0/lib/aruba/rspec.rb:25:in `block (2 levels) in <top (required)>'
有问题的 spec
./spec/pkg/abc_spec.rb
看起来像这样(实际命令已被替换为睡眠时间);
require "aruba/rspec"
RSpec.describe "long running test", :type => :aruba do
context "long command" do
before { run_command('bash -c "sleep 20 && echo yikes"') }
it { expect(last_command_started).to have_output "yikes" }
end
end
有什么方法可以防止它在测试耗时较长的命令时出错吗?
Aruba 测试可以配置为允许长时间运行的命令。
run_command
将遵循 exit_timeout
配置,可以在 spec 文件中设置,例如;
Aruba.configure do |config|
# some time longer than your run_command should take
config.exit_timeout = 21
end
对于提供的块,使用这个有效的
Aruba.configure
的完整示例是;
require "aruba/rspec"
Aruba.configure do |config|
config.exit_timeout = 21
end
RSpec.describe "long running test", :type => :aruba do
context "long command" do
before { run_command('bash -c "sleep 20 && echo yikes"') }
it { expect(last_command_started).to have_output "yikes" }
end
end