diff options
-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 1d58918a50..7c11957997 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -182,26 +182,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 |