5
5

More than 5 years have passed since last update.

serverspecをデバックする

Last updated at Posted at 2014-05-21

目的

Pythonのversionをテストしたい

前提条件

pryがインストールされていること

テスト

STDOUTに出力されることを期待していた。

specコード

describe command('/usr/bin/python -V') do
  it { should return_stdout "Python 2.6.6" }
end

しかし、テストに失敗した。

Failures:

  1) Command "/usr/bin/python -V" should return stdout "Python 2.6.6"
     Failure/Error: it { should return_stdout "Python 2.6.6\n" }
       expected Command "/usr/bin/python -V" to return stdout "Python 2.6.6"
     # ./spec/base/version_spec.rb:5:in `block (2 levels) in <top (required)>'

specinfraのコードbinding.pryをしこんで見たところ

[3] pry(#<SpecInfra::Backend::Ssh>)> ret
=> {:stdout=>"", :stderr=>"Python 2.6.6\n", :exit_status=>0, :exit_signal=>nil}

:stderr!!!

変更後

describe command('/usr/bin/python -V') do
  it { should return_stdout "" }
  it { should return_stderr "Python 2.6.6" }
  it { should return_exit_status 0 }
end

結果

Command "/usr/bin/python -V"
  should return stdout ""
  should return stderr "Python 2.6.6"
  should return exit status 0

Finished in 3.74 seconds
3 examples, 0 failures

ということで、うまくマッチしなかったときのデバック方法でした。
他にいい方法がありましたら誰かコメント下さい。m(-_-)m

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5