Sunday 15 July 2012

ruby - Chef ServerSpec Regex Match Not Working -



ruby - Chef ServerSpec Regex Match Not Working -

i'm trying math regex stdout of command. though regex should match doesn't seem doing such:

> [#] 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 │ > [#] └──────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴─────────────┘ > [#] utilize `pm2 desc[ribe] <id>` 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 load) > [#] 3 examples, 1 failure

why regex not matching?

a similar regex running within cookbook works fine:

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

the actual error invalid byte sequence in us-ascii. mixlib-shellout careful encoding-aware, isn't serverspec uses run commands afaik. matcher trying convert (probably) utf-8 info ascii string, failing. seek should include('online') perhaps? have dive matcher code in rspec of how process strings.

ruby regex chef serverspec

No comments:

Post a Comment