diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-09-11 07:55:24 -0700 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-09-29 08:31:08 -0700 |
commit | 1852c179a7f84a42b591689eb5076defa90c7431 (patch) | |
tree | 8c4825b867a150e43b5e7fabe1c72873d81d27fa | |
parent | ce03bb01bff58fac8d65b402e4f1fd424f85ca6e (diff) | |
download | chef-1852c179a7f84a42b591689eb5076defa90c7431.tar.gz |
Refactoring matchers into their own folders/files
-rw-r--r-- | spec/spec_helper.rb | 23 | ||||
-rw-r--r-- | spec/support/shared/matchers.rb | 17 | ||||
-rw-r--r-- | spec/support/shared/matchers/exit_with_code.rb | 28 | ||||
-rw-r--r-- | spec/support/shared/matchers/match_environment_variable.rb | 17 |
4 files changed, 45 insertions, 40 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 50289451af..ed0a8f89f6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -185,26 +185,3 @@ module WEBrick end end end - -# Lifted from http://stackoverflow.com/questions/1480537/how-can-i-validate-exits-and-aborts-in-rspec -RSpec::Matchers.define :exit_with_code do |exp_code| - actual = nil - match do |block| - begin - block.call - rescue SystemExit => e - actual = e.status - end - actual and actual == exp_code - end - failure_message_for_should do |block| - "expected block to call exit(#{exp_code}) but exit" + - (actual.nil? ? " not called" : "(#{actual}) was called") - end - failure_message_for_should_not do |block| - "expected block not to call exit(#{exp_code})" - end - description do - "expect block to call exit(#{exp_code})" - end -end diff --git a/spec/support/shared/matchers.rb b/spec/support/shared/matchers.rb deleted file mode 100644 index 2e1c660c19..0000000000 --- a/spec/support/shared/matchers.rb +++ /dev/null @@ -1,17 +0,0 @@ - -require 'rspec/expectations' -require 'spec/support/platform_helpers' - -RSpec::Matchers.define :match_environment_variable do |varname| - match do |actual| - expected = if windows? && ENV[varname].nil? - # On Windows, if an environment variable is not set, the command - # `echo %VARNAME%` outputs %VARNAME% - "%#{varname}%" - else - ENV[varname].to_s - end - - actual == expected - end -end diff --git a/spec/support/shared/matchers/exit_with_code.rb b/spec/support/shared/matchers/exit_with_code.rb new file mode 100644 index 0000000000..957586c85d --- /dev/null +++ b/spec/support/shared/matchers/exit_with_code.rb @@ -0,0 +1,28 @@ +require 'rspec/expectations' + +# Lifted from http://stackoverflow.com/questions/1480537/how-can-i-validate-exits-and-aborts-in-rspec +RSpec::Matchers.define :exit_with_code do |exp_code| + actual = nil + match do |block| + begin + block.call + rescue SystemExit => e + actual = e.status + end + actual and actual == exp_code + end + + failure_message_for_should do |block| + "expected block to call exit(#{exp_code}) but exit" + + (actual.nil? ? " not called" : "(#{actual}) was called") + end + + failure_message_for_should_not do |block| + "expected block not to call exit(#{exp_code})" + end + + description do + "expect block to call exit(#{exp_code})" + end + +end diff --git a/spec/support/shared/matchers/match_environment_variable.rb b/spec/support/shared/matchers/match_environment_variable.rb new file mode 100644 index 0000000000..c8c905f44a --- /dev/null +++ b/spec/support/shared/matchers/match_environment_variable.rb @@ -0,0 +1,17 @@ + +require 'rspec/expectations' +require 'spec/support/platform_helpers' + +RSpec::Matchers.define :match_environment_variable do |varname| + match do |actual| + expected = if windows? && ENV[varname].nil? + # On Windows, if an environment variable is not set, the command + # `echo %VARNAME%` outputs %VARNAME% + "%#{varname}%" + else + ENV[varname].to_s + end + + actual == expected + end +end |