Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Chef ServerSpec正则表达式匹配不起作用_Ruby_Regex_Chef Infra_Serverspec - Fatal编程技术网

Ruby Chef ServerSpec正则表达式匹配不起作用

Ruby Chef ServerSpec正则表达式匹配不起作用,ruby,regex,chef-infra,serverspec,Ruby,Regex,Chef Infra,Serverspec,我试图将正则表达式计算为命令的标准值。尽管正则表达式应该匹配,但它似乎没有这样做: > [#] Command "pm2 list" > [#] stdout > [#] should match /.*online.*/ (FAILED - 1) > [#] > [#] Failures: > [#] > [#] 1) Command "pm2 list" stdou

我试图将正则表达式计算为命令的标准值。尽管正则表达式应该匹配,但它似乎没有这样做:

> [#]        Command "pm2 list"
> [#]          stdout
> [#]            should match /.*online.*/ (FAILED - 1)
> [#]
> [#]        Failures:
> [#]
> [#]          1) Command "pm2 list" stdout should match /.*online.*/
> [#]             Failure/Error: its(:stdout) { should match /.*online.*/}
> [#]             ArgumentError:
> [#]               invalid byte sequence in US-ASCII
> [#]               /bin/sh -c pm2\ list
> [#]               ┌──────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬─────────────┐
> [#]        │ App name │ id │ mode │ PID  │ status │ restarted │ uptime │      memory │    watching │
> [#]        ├──────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼─────────────┤
> [#]        │ app      │ 0  │ fork │ 3684 │ online │         0 │ 5m     │ 13.898 MB   │ unactivated │
> [#]        └──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴─────────────┘
> [#]         Use `pm2 desc[ribe] <id>` to get more details
> [#]
> [#]             # /tmp/busser/suites/serverspec/localhost/nodejs_spec.rb:10:in `block (2 levels) in <top (required)>'
> [#]
> [#]        Finished in 0.77549 seconds (files took 0.19867 seconds to load)
> [#]        3 examples, 1 failure

实际错误是US-ASCII中的
无效字节序列。Mixlib shellout非常小心地注意编码,但这不是Serverspec用来运行AFAIK命令的。matcher正在尝试(可能)将UTF-8数据转换为ASCII字符串,但失败了。试试
应该包括('online')
也许?您必须在rspec中插入匹配器代码,以确定它们如何处理字符串

...
process_check = Mixlib::ShellOut.new("pm2 list")
process_check.run_command
if process_check.stdout =~ /(stopped|online)/
...