Skip to content
Browse files

updates mspec to d664929940b1f38f6686a6c2aea041feb975418b

  • Loading branch information...
1 parent 53b78ca commit 3483523e3fdca409387a9b1009e3190b0570f32a @Watson1978 Watson1978 committed Feb 2, 2012
Showing with 864 additions and 485 deletions.
  1. +4 −0 mspec/Gemfile
  2. +39 −159 mspec/README
  3. +5 −51 mspec/Rakefile
  4. +6 −3 mspec/lib/mspec/commands/mspec.rb
  5. +6 −1 mspec/lib/mspec/helpers/const_lookup.rb
  6. +12 −14 mspec/lib/mspec/helpers/datetime.rb
  7. +26 −5 mspec/lib/mspec/helpers/ruby_exe.rb
  8. +3 −0 mspec/lib/mspec/matchers.rb
  9. +20 −0 mspec/lib/mspec/matchers/be_nan.rb
  10. +28 −0 mspec/lib/mspec/matchers/infinity.rb
  11. +28 −0 mspec/lib/mspec/matchers/signed_zero.rb
  12. +1 −0 mspec/lib/mspec/runner/formatters.rb
  13. +96 −0 mspec/lib/mspec/runner/formatters/junit.rb
  14. +3 −0 mspec/lib/mspec/utils/options.rb
  15. +1 −1 mspec/lib/mspec/utils/script.rb
  16. +38 −0 mspec/mspec.gemspec
  17. +2 −2 mspec/spec/commands/mkspec_spec.rb
  18. +1 −1 mspec/spec/commands/mspec_ci_spec.rb
  19. +1 −1 mspec/spec/commands/mspec_run_spec.rb
  20. +6 −6 mspec/spec/commands/mspec_spec.rb
  21. +28 −22 mspec/spec/commands/mspec_tag_spec.rb
  22. +1 −1 mspec/spec/expectations/expectations_spec.rb
  23. +2 −2 mspec/spec/expectations/should_spec.rb
  24. +2 −2 mspec/spec/guards/background_spec.rb
  25. +2 −3 mspec/spec/guards/bug_spec.rb
  26. +2 −2 mspec/spec/guards/compliance_spec.rb
  27. +2 −2 mspec/spec/guards/conflict_spec.rb
  28. +2 −2 mspec/spec/guards/endian_spec.rb
  29. +2 −2 mspec/spec/guards/extensions_spec.rb
  30. +2 −2 mspec/spec/guards/feature_spec.rb
  31. +4 −5 mspec/spec/guards/guard_spec.rb
  32. +2 −2 mspec/spec/guards/noncompliance_spec.rb
  33. +2 −2 mspec/spec/guards/platform_spec.rb
  34. +2 −2 mspec/spec/guards/quarantine_spec.rb
  35. +2 −2 mspec/spec/guards/runner_spec.rb
  36. +2 −2 mspec/spec/guards/specified_spec.rb
  37. +2 −2 mspec/spec/guards/superuser_spec.rb
  38. +2 −2 mspec/spec/guards/support_spec.rb
  39. +2 −2 mspec/spec/guards/tty_spec.rb
  40. +2 −2 mspec/spec/guards/user_spec.rb
  41. +2 −2 mspec/spec/guards/version_spec.rb
  42. +3 −2 mspec/spec/helpers/argv_spec.rb
  43. +3 −2 mspec/spec/helpers/const_lookup_spec.rb
  44. +3 −2 mspec/spec/helpers/datetime_spec.rb
  45. +3 −2 mspec/spec/helpers/ducktype_spec.rb
  46. +3 −2 mspec/spec/helpers/encode_spec.rb
  47. +2 −2 mspec/spec/helpers/enumerator_class_spec.rb
  48. +3 −3 mspec/spec/helpers/environment_spec.rb
  49. +3 −2 mspec/spec/helpers/fixture_spec.rb
  50. +4 −3 mspec/spec/helpers/flunk_spec.rb
  51. +3 −2 mspec/spec/helpers/fmode_spec.rb
  52. +2 −3 mspec/spec/helpers/fs_spec.rb
  53. +3 −2 mspec/spec/helpers/hash_spec.rb
  54. +3 −5 mspec/spec/helpers/io_spec.rb
  55. +3 −2 mspec/spec/helpers/language_version_spec.rb
  56. +3 −2 mspec/spec/helpers/mock_to_path_spec.rb
  57. +3 −2 mspec/spec/helpers/numeric_spec.rb
  58. +38 −2 mspec/spec/helpers/ruby_exe_spec.rb
  59. +3 −1 mspec/spec/helpers/scratch_spec.rb
  60. +3 −2 mspec/spec/helpers/stasy_spec.rb
  61. +3 −2 mspec/spec/helpers/tmp_spec.rb
  62. +2 −2 mspec/spec/matchers/base_spec.rb
  63. +2 −2 mspec/spec/matchers/be_an_instance_of_spec.rb
  64. +2 −2 mspec/spec/matchers/be_ancestor_of_spec.rb
  65. +2 −2 mspec/spec/matchers/be_close_spec.rb
  66. +2 −2 mspec/spec/matchers/be_computed_by_function_spec.rb
  67. +2 −2 mspec/spec/matchers/be_computed_by_spec.rb
  68. +2 −2 mspec/spec/matchers/be_empty_spec.rb
  69. +3 −3 mspec/spec/matchers/be_false_spec.rb
  70. +2 −2 mspec/spec/matchers/be_kind_of_spec.rb
  71. +28 −0 mspec/spec/matchers/be_nan_spec.rb
  72. +3 −3 mspec/spec/matchers/be_nil_spec.rb
  73. +3 −3 mspec/spec/matchers/be_true_spec.rb
  74. +2 −2 mspec/spec/matchers/be_valid_dns_name_spec.rb
  75. +2 −2 mspec/spec/matchers/complain_spec.rb
  76. +2 −2 mspec/spec/matchers/eql_spec.rb
  77. +2 −2 mspec/spec/matchers/equal_element_spec.rb
  78. +2 −2 mspec/spec/matchers/equal_spec.rb
  79. +2 −2 mspec/spec/matchers/equal_utf16_spec.rb
  80. +3 −3 mspec/spec/matchers/have_class_variable_spec.rb
  81. +2 −2 mspec/spec/matchers/have_constant_spec.rb
  82. +4 −4 mspec/spec/matchers/have_data_spec.rb
  83. +2 −2 mspec/spec/matchers/have_instance_method_spec.rb
  84. +3 −3 mspec/spec/matchers/have_instance_variable_spec.rb
  85. +2 −2 mspec/spec/matchers/have_method_spec.rb
  86. +2 −2 mspec/spec/matchers/have_private_instance_method_spec.rb
  87. +2 −2 mspec/spec/matchers/have_private_method_spec.rb
  88. +2 −2 mspec/spec/matchers/have_protected_instance_method_spec.rb
  89. +2 −2 mspec/spec/matchers/have_public_instance_method_spec.rb
  90. +2 −2 mspec/spec/matchers/have_singleton_method_spec.rb
  91. +2 −2 mspec/spec/matchers/include_spec.rb
  92. +34 −0 mspec/spec/matchers/infinity_spec.rb
  93. +3 −3 mspec/spec/matchers/match_yaml_spec.rb
  94. +2 −2 mspec/spec/matchers/output_spec.rb
  95. +2 −2 mspec/spec/matchers/output_to_fd_spec.rb
  96. +2 −2 mspec/spec/matchers/raise_error_spec.rb
  97. +2 −2 mspec/spec/matchers/respond_to_spec.rb
  98. +32 −0 mspec/spec/matchers/signed_zero_spec.rb
  99. +2 −2 mspec/spec/matchers/stringsymboladapter_spec.rb
  100. +12 −12 mspec/spec/mocks/mock_spec.rb
  101. +1 −1 mspec/spec/mocks/proxy_spec.rb
  102. +1 −1 mspec/spec/runner/actions/debug_spec.rb
  103. +1 −1 mspec/spec/runner/actions/gdb_spec.rb
  104. +1 −1 mspec/spec/runner/actions/tag_spec.rb
  105. +1 −1 mspec/spec/runner/actions/taglist_spec.rb
  106. +4 −4 mspec/spec/runner/context_spec.rb
  107. +1 −1 mspec/spec/runner/example_spec.rb
  108. +1 −1 mspec/spec/runner/exception_spec.rb
  109. +2 −2 mspec/spec/runner/filters/tag_spec.rb
  110. +1 −1 mspec/spec/runner/formatters/describe_spec.rb
  111. +2 −2 mspec/spec/runner/formatters/dotted_spec.rb
  112. +2 −2 mspec/spec/runner/formatters/html_spec.rb
  113. +147 −0 mspec/spec/runner/formatters/junit_spec.rb
  114. +2 −2 mspec/spec/runner/formatters/unit_spec.rb
  115. +3 −3 mspec/spec/runner/formatters/yaml_spec.rb
  116. +1 −1 mspec/spec/runner/mspec_spec.rb
  117. +1 −1 mspec/spec/runner/shared_spec.rb
  118. +1 −1 mspec/spec/runner/tag_spec.rb
  119. +0 −7 mspec/spec/spec_helper.rb
  120. +1 −1 mspec/spec/utils/name_map_spec.rb
  121. +11 −1 mspec/spec/utils/options_spec.rb
  122. +4 −4 mspec/spec/utils/script_spec.rb
  123. +1 −1 mspec/spec/utils/version_spec.rb
  124. +1 −1 mspec/upstream
View
4 mspec/Gemfile
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in mspec.gemspec
+gemspec
View
198 mspec/README
@@ -1,197 +1,77 @@
-= Overview
+1. Overview
MSpec is a specialized framework that is syntax-compatible with RSpec for
-basic things like +describe+, +it+ blocks and +before+, +after+ actions. MSpec
+basic things like 'describe', 'it' blocks and 'before', 'after' actions. MSpec
contains additional features that assist in writing the RubySpecs used by
multiple Ruby implementations.
MSpec attempts to use the simplest Ruby language features so that beginning
-Ruby implementations can run the Ruby specs. So, for example, there is not
-great concern given to constant clashes. Namespacing (or module scoping) is
-not used because implementing this correctly took a significant amount of work
-in Rubinius and it is likely that other implementations would also face
-difficulties.
+Ruby implementations can run the Ruby specs.
MSpec is not intended as a replacement for RSpec. MSpec attempts to provide a
subset of RSpec's features in some cases and a superset in others. It does not
-provide all the matchers, for instance. However, MSpec provides several
-extensions to facilitate writing the Ruby specs in a manner compatible with
-multiple Ruby implementations.
-
-First, MSpec offers a set of guards to control execution of the specs. These
-guards not only enable or disable execution but also annotate the specs with
-additional information about why they are run or not run. Second, MSpec
-provides a different shared spec implementation specifically designed to ease
-writing specs for the numerous aliased methods in Ruby. The MSpec shared spec
-implementation should not conflict with RSpec's own shared behavior facility.
-Third, MSpec provides various helper methods to simplify some specs, for
-example, creating temporary file names. Finally, MSpec has several specialized
-runner scripts that includes a configuration facility with a default project
-file and user-specific overrides.
-
-Caveats:
-
-* Use RSpec to run the MSpec specs. There are no plans currently to make
- the MSpec specs runnable by MSpec.
-* Don't mock the #hash method as MSpec's Mock implementation uses Hash
- internally. This can be replaced if necessary, but at this point there is no
- compelling need to do so.
-
-
-== Architecture
-
-
-== Matchers
-
-Matchers are additional aids for the verification process. The default
-is of course to #should or #should_not using the #== operator and its
-friends but the matchers add a new set of 'operators' to help in the
-task. They reside in `mspec/matchers/`. There are two broad categories,
-those that apply to an individual object and those that apply to a
-block:
-
-=== Object
-
-- `base` implements the standard #==, #< #<= #>= #> and #=~ with their
- normal semantics for the objects that you invoke them on.
-
-- `be_ancestor_of` is equivalent to checking `obj.ancestors.include?`.
-
-- `be_close` is a "delta" for floating-point math. Due to the very
- nature of it, floating-point comparisons should never be treated as
- exact. By default the tolerance is 0.00003 but it can be altered if
- so desired. So `0.23154.should be_close(0.23157)` would succeed
- (which is usually close enough for floating point unless you are
- doing some scientific computing.)
-
-- `be_empty` checks `obj.empty?`
-
-- `be_kind_of` is equivalent to `obj.kind_of?`
-
-- `include` is `obj.include?`
-
-=== Block
-
-All of these should be applied to a block created with `lambda` or `proc`:
-
-- `complain` is probably clearer stated as `lambda {...}.should complain`;
- it checks that the block issues a warning. The message can be checked
- against either a String or a Regexp.
-
-- `output` checks that the block produces the given output (stdout as well
- as stderr, in that order) matched either to a String or a Regexp. This one
- uses overrides so if that is a problem (for e.g. speccing Readline or
- something) see below.
-
-- `output_to_fd` is a lower-level version and actually verifies that output
- to a certain file descriptor is correct whether from an in-/output stream
- or an actual file. Also can check with either a String or a Regexp.
+provide all the matchers, for instance.
-- `raise_error` verifies the exception type (if any) raised by the block it
- is associated with. The exception class can be given for finer-grained
- control (inheritance works normally so Exception would catch everything.)
+However, MSpec provides several extensions to facilitate writing the Ruby
+specs in a manner compatible with multiple Ruby implementations.
-== Nested 'describe' blocks
+ 1. MSpec offers a set of guards to control execution of the specs. These
+ guards not only enable or disable execution but also annotate the specs
+ with additional information about why they are run or not run.
-MSpec supports nesting one 'describe' block inside another. The examples in
-the nested block are evaluated with all the before/after blocks of all the
-containing 'describe' blocks. The following example illustrates this:
+ 2. MSpec provides a different shared spec implementation specifically
+ designed to ease writing specs for the numerous aliased methods in Ruby.
+ The MSpec shared spec implementation should not conflict with RSpec's own
+ shared behavior facility.
-describe "Some#method" do
- before :each do
- @obj = 1
- end
+ 3. MSpec provides various helper methods to simplify some specs, for
+ example, creating temporary file names.
- describe "when passed String" do
- before :each do
- @meth = :to_s
- end
+ 4. MSpec has several specialized runner scripts that includes a
+ configuration facility with a default project file and user-specific
+ overrides.
- it "returns false" do
- # when this example is evaluated, @obj = 1 and @meth = :to_s
- end
- end
-end
-The output when using the SpecdocFormatter (selected with -fs to the runners)
-will be as follows:
+2. Bundler
-Some#method when passed String
-- returns false
+A Gemfile and Gemfile.lock is provide. Use Bundler to install gem
+dependencies. To install Bundler, run the following:
+ $ gem install bundler
-== Shared 'describe' blocks
+To install the gem dependencies with Bundler, run the following:
-MSpec supports RSpec-style shared 'describe' blocks. MSpec also provides a
-convenience method to assist in writing specs for the numerous aliased methods
-that Ruby provides. The following example illustrates shared blocks:
+ $ RUBYLIB=lib ruby -S bundle install
-describe :someclass_some_method, :shared => true do
- it "does something" do
- end
-end
-describe "SomeClass#some_method" do
- it_should_behave_like "someclass_some_method"
-end
+3. Running Specs
-The first argument to 'describe' for a shared block is an object that
-duck-types as a String. The representation of the object must be unique. This
-example uses a symbol. This was the convention for the previous facility that
-MSpec provided for aliased method (#it_behaves_like). However, this convention
-is not set in stone (but the uniqueness requirement is). Note that the
-argument to the #it_should_behave_like is a String because at this time RSpec
-will not find the shared block by the symbol.
+Use RSpec to run the MSpec specs. There are no plans currently to make the
+MSpec specs runnable by MSpec.
-MSpec continues to support the #it_behaves_like convenience method for
-specifying aliased methods. The syntax is as follows:
+After installing the gem dependencies, the specs can be run as follows:
-it_behaves_like :symbol_matching_shared_describe, :method [, :object]
+ $ ruby -S rspec
-describe :someclass_some_method, :shared => true do
- it "returns true" do
- obj.send(@method).should be_true
- end
+Or
- it "returns something else" do
- @object.send(@method).should be_something_else
- end
-end
+ $ ruby -S rake
-# example #1
-describe "SomeClass#some_method" do
- it_behaves_like :someclass_some_method, :other_method
-end
+To run an individual spec file, use the following example:
-# example #2
-describe "SomeOtherClass#some_method" do
- it_behaves_like :someclass_some_method, :some_method, OtherClass
-end
+ $ ruby -S rspec spec/helpers/ruby_exe_spec.rb
-The first form above (#1) is used for typical aliases. That is, methods with
-different names on the same class that behave identically. The
-#it_behaves_like helper creates a before(:all) block that sets @method to
-:other_method. The form of the first example block in the shared block
-illustrates the typical form of a spec for an aliased method.
-The second form above (#2) is used for methods on different classes that are
-essentially aliases, even though Ruby does not provide a syntax for specifying
-such methods as aliases. Examples are the methods on File, FileTest, and
-File::Stat. In this case, the #it_behaves_like helper sets both @method and
-@object in the before(:all) block (@method = :some_method, @object =
-OtherClass in this example).
+4. Documentation
-For shared specs that fall outside of either of these two narrow categories,
-use nested or shared 'describe' blocks as appropriate and use the
-#it_should_behave_like method directly.
+See http://rubyspec.org
-== Guards
-Since Ruby is not completely isolated from its platform or execution environment, the spec files may contain guards: conditions placed around a spec or a set of specs to enable or disable them.
+5. Source Code
-You can find an overview of the current guards and their usage in: http://rubyspec.org/wiki/mspec/Guards .
+See https://github.com/rubyspec/mspec
-== Helpers
+6. License
-== Runners
+See the LICENSE in the source code.
View
56 mspec/Rakefile
@@ -1,53 +1,7 @@
-require 'rubygems'
+require 'bundler/gem_tasks'
+require 'bundler/setup'
+require 'rspec/core/rake_task'
-begin
- require 'spec/rake/spectask'
+RSpec::Core::RakeTask.new(:spec)
- Spec::Rake::SpecTask.new
- task :default => :spec
-rescue LoadError
- task :default do
- STDERR.puts "Please install RSpec 1.6.x to run MSpec specs"
- end
-end
-
-require 'rake/gempackagetask'
-
-$:.unshift File.expand_path(File.dirname(__FILE__) + '/lib')
-require 'mspec/version'
-
-spec = Gem::Specification.new do |s|
- s.name = %q{mspec}
- s.version = MSpec::VERSION.to_s
-
- s.specification_version = 2 if s.respond_to? :specification_version=
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Brian Ford"]
- s.date = %q{2010-03-13}
- s.email = %q{bford@engineyard.com}
- s.has_rdoc = true
- s.extra_rdoc_files = %w[ README LICENSE ]
- s.executables = ["mkspec", "mspec", "mspec-ci", "mspec-run", "mspec-tag"]
- s.files = FileList[ '{bin,lib,spec}/**/*.{yaml,txt,rb}', 'Rakefile', *s.extra_rdoc_files ]
- s.homepage = %q{http://rubyspec.org}
- s.rubyforge_project = 'http://rubyforge.org/projects/mspec'
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.5}
- s.summary = <<EOS
-MSpec is a specialized framework that is syntax-compatible
-with RSpec for basic things like describe, it blocks and
-before, after actions.
-
-MSpec contains additional features that assist in writing
-the RubySpecs used by multiple Ruby implementations. Also,
-MSpec attempts to use the simplest Ruby language features
-so that beginning Ruby implementations can run it.
-EOS
-
- s.rdoc_options << '--title' << 'MSpec Gem' <<
- '--main' << 'README' <<
- '--line-numbers'
-end
-
-Rake::GemPackageTask.new(spec){ |pkg| pkg.gem_spec = spec }
+task :default => :spec
View
9 mspec/lib/mspec/commands/mspec.rb
@@ -42,10 +42,10 @@ def options(argv=ARGV)
end
options.on("-A", "--valgrind", "Run under valgrind") do
- config[:flags] << '--valgrind'
+ config[:use_valgrind] = true
end
- options.on("--warnings", "Don't suppress warnings") do
+ options.on("--warnings", "Don't supress warnings") do
config[:flags] << '-w'
ENV['OUTPUT_WARNINGS'] = '1'
end
@@ -159,7 +159,10 @@ def run
if config[:multi] and config[:command] == "ci"
multi_exec argv
else
- if config[:use_gdb]
+ if config[:use_valgrind]
+ more = ["--db-attach=#{config[:use_gdb] ? 'yes' : 'no'}", config[:target]] + argv
+ exec "valgrind", *more
+ elsif config[:use_gdb]
more = ["--args", config[:target]] + argv
exec "gdb", *more
else
View
7 mspec/lib/mspec/helpers/const_lookup.rb
@@ -1,9 +1,14 @@
+require 'mspec/utils/version'
+
module Kernel
def const_lookup(c)
+ extra_arg = SpecVersion.new(RUBY_VERSION) >= "1.9"
+
names = c.split '::'
names.shift if names.first.empty?
+
names.inject(Object) do |m, n|
- defined = RUBY_VERSION =~ /^1.9/ ? m.const_defined?(n, false) : m.const_defined?(n)
+ defined = extra_arg ? m.const_defined?(n, false) : m.const_defined?(n)
defined ? m.const_get(n) : m.const_missing(n)
end
end
View
26 mspec/lib/mspec/helpers/datetime.rb
@@ -1,5 +1,3 @@
-require 'date'
-
class Object
# The new_datetime helper makes writing DateTime specs more simple by
# providing default constructor values and accepting a Hash of only the
@@ -10,19 +8,19 @@ class Object
# Possible keys are:
# :year, :month, :day, :hour, :minute, :second, :offset and :sg.
- MSPEC_DATETIME_OPTIONS = {
- :year => -4712,
- :month => 1,
- :day => 1,
- :hour => 0,
- :minute => 0,
- :second => 0,
- :offset => 0,
- :sg => Date::ITALY
- }
-
def new_datetime(opts={})
- value = MSPEC_DATETIME_OPTIONS.dup.merge opts
+ require 'date'
+
+ value = {
+ :year => -4712,
+ :month => 1,
+ :day => 1,
+ :hour => 0,
+ :minute => 0,
+ :second => 0,
+ :offset => 0,
+ :sg => Date::ITALY
+ }.merge opts
DateTime.new value[:year], value[:month], value[:day], value[:hour],
value[:minute], value[:second], value[:offset], value[:sg]
View
31 mspec/lib/mspec/helpers/ruby_exe.rb
@@ -22,15 +22,19 @@
#
# `#{RUBY_EXE} -e #{'puts "hello, world."'}`
#
-# The ruby_exe helper also accepts an options hash with two
-# keys: :options and :args. For example:
+# The ruby_exe helper also accepts an options hash with three
+# keys: :options, :args and :env. For example:
#
-# ruby_exe('file.rb', :options => "-w", :args => "> file.txt")
+# ruby_exe('file.rb', :options => "-w",
+# :args => "> file.txt",
+# :env => { :FOO => "bar" })
#
# will be executed as
#
# `#{RUBY_EXE} -w #{'file.rb'} > file.txt`
#
+# with access to ENV["FOO"] with value "bar".
+#
# If +nil+ is passed for the first argument, the command line
# will be built only from the options hash.
#
@@ -112,6 +116,7 @@ def resolve_ruby_exe
def ruby_exe(code, opts = {})
body = code
+ env = opts[:env] || {}
working_dir = opts[:dir] || "."
Dir.chdir(working_dir) do
if code and not File.exists?(code)
@@ -122,8 +127,24 @@ def ruby_exe(code, opts = {})
end
body = "-e #{code}"
end
- cmd = [RUBY_EXE, ENV['RUBY_FLAGS'], opts[:options], body, opts[:args]]
- `#{cmd.compact.join(' ')}`
+
+ saved_env = {}
+ env.each do |key, value|
+ key = key.to_s
+ saved_env[key] = ENV[key] if ENV.key? key
+ ENV[key] = value
+ end
+
+ begin
+ cmd = [RUBY_EXE, ENV['RUBY_FLAGS'], opts[:options], body, opts[:args]]
+ `#{cmd.compact.join(' ')}`
+ ensure
+ saved_env.each { |key, value| ENV[key] = value }
+ env.keys.each do |key|
+ key = key.to_s
+ ENV.delete key unless saved_env.key? key
+ end
+ end
end
end
View
3 mspec/lib/mspec/matchers.rb
@@ -7,6 +7,7 @@
require 'mspec/matchers/be_empty'
require 'mspec/matchers/be_false'
require 'mspec/matchers/be_kind_of'
+require 'mspec/matchers/be_nan'
require 'mspec/matchers/be_nil'
require 'mspec/matchers/be_true'
require 'mspec/matchers/be_valid_dns_name'
@@ -27,8 +28,10 @@
require 'mspec/matchers/have_public_instance_method'
require 'mspec/matchers/have_singleton_method'
require 'mspec/matchers/include'
+require 'mspec/matchers/infinity'
require 'mspec/matchers/match_yaml'
require 'mspec/matchers/raise_error'
require 'mspec/matchers/output'
require 'mspec/matchers/output_to_fd'
require 'mspec/matchers/respond_to'
+require 'mspec/matchers/signed_zero'
View
20 mspec/lib/mspec/matchers/be_nan.rb
@@ -0,0 +1,20 @@
+class BeNaNMatcher
+ def matches?(actual)
+ @actual = actual
+ @actual.kind_of?(Float) && @actual.nan?
+ end
+
+ def failure_message
+ ["Expected #{@actual}", "to be NaN"]
+ end
+
+ def negative_failure_message
+ ["Expected #{@actual}", "not to be NaN"]
+ end
+end
+
+class Object
+ def be_nan
+ BeNaNMatcher.new
+ end
+end
View
28 mspec/lib/mspec/matchers/infinity.rb
@@ -0,0 +1,28 @@
+class InfinityMatcher
+ def initialize(expected_sign)
+ @expected_sign = expected_sign
+ end
+
+ def matches?(actual)
+ @actual = actual
+ @actual.kind_of?(Float) && @actual.infinite? == @expected_sign
+ end
+
+ def failure_message
+ ["Expected #{@actual}", "to be #{"-" if @expected_sign == -1}Infinity"]
+ end
+
+ def negative_failure_message
+ ["Expected #{@actual}", "not to be #{"-" if @expected_sign == -1}Infinity"]
+ end
+end
+
+class Object
+ def be_positive_infinity
+ InfinityMatcher.new(1)
+ end
+
+ def be_negative_infinity
+ InfinityMatcher.new(-1)
+ end
+end
View
28 mspec/lib/mspec/matchers/signed_zero.rb
@@ -0,0 +1,28 @@
+class SignedZeroMatcher
+ def initialize(expected_sign)
+ @expected_sign = expected_sign
+ end
+
+ def matches?(actual)
+ @actual = actual
+ (1.0/actual).infinite? == @expected_sign
+ end
+
+ def failure_message
+ ["Expected #{@actual}", "to be #{"-" if @expected_sign == -1}0.0"]
+ end
+
+ def negative_failure_message
+ ["Expected #{@actual}", "not to be #{"-" if @expected_sign == -1}0.0"]
+ end
+end
+
+class Object
+ def be_positive_zero
+ SignedZeroMatcher.new(1)
+ end
+
+ def be_negative_zero
+ SignedZeroMatcher.new(-1)
+ end
+end
View
1 mspec/lib/mspec/runner/formatters.rb
@@ -9,4 +9,5 @@
require 'mspec/runner/formatters/method'
require 'mspec/runner/formatters/yaml'
require 'mspec/runner/formatters/profile'
+require 'mspec/runner/formatters/junit'
require 'mspec/runner/formatters/macruby'
View
96 mspec/lib/mspec/runner/formatters/junit.rb
@@ -0,0 +1,96 @@
+require 'mspec/expectations/expectations'
+require 'mspec/utils/ruby_name'
+require 'mspec/runner/formatters/yaml'
+
+class JUnitFormatter < YamlFormatter
+ def initialize(out=nil)
+ super
+ @tests = []
+ end
+
+ def after(state = nil)
+ super
+ @tests << {:test => state, :exception => false} unless exception?
+ end
+
+ def exception(exception)
+ super
+ @tests << {:test => exception, :exception => true}
+ end
+
+ def finish
+ switch
+
+ time = @timer.elapsed
+ tests = @tally.counter.examples
+ errors = @tally.counter.errors
+ failures = @tally.counter.failures
+
+ printf <<-XML
+
+<?xml version="1.0" encoding="UTF-8" ?>
+ <testsuites
+ testCount="#{tests}"
+ errorCount="#{errors}"
+ failureCount="#{failures}"
+ timeCount="#{time}" time="#{time}">
+ <testsuite
+ tests="#{tests}"
+ errors="#{errors}"
+ failures="#{failures}"
+ time="#{time}"
+ name="Spec Output For #{::RUBY_NAME} (#{::RUBY_VERSION})">
+ XML
+ @tests.each do |h|
+ description = encode_for_xml h[:test].description
+
+ printf <<-XML, "Spec", description, 0.0
+ <testcase classname="%s" name="%s" time="%f">
+ XML
+ if h[:exception]
+ outcome = h[:test].failure? ? "failure" : "error"
+ message = encode_for_xml h[:test].message
+ backtrace = encode_for_xml h[:test].backtrace
+ print <<-XML
+ <#{outcome} message="error in #{description}" type="#{outcome}">
+ #{message}
+ #{backtrace}
+ </#{outcome}>
+ XML
+ end
+ print <<-XML
+ </testcase>
+ XML
+ end
+
+ print <<-XML
+ </testsuite>
+ </testsuites>
+ XML
+ end
+
+ private
+ LT = "&lt;"
+ GT = "&gt;"
+ QU = "&quot;"
+ AP = "&apos;"
+ AM = "&amp;"
+ TARGET_ENCODING = "ISO-8859-1"
+
+ def encode_for_xml(str)
+ encode_as_latin1(str).gsub("<", LT).gsub(">", GT).
+ gsub('"', QU).gsub("'", AP).gsub("&", AM).
+ gsub(/[#{Regexp.escape("\0\1\2\3\4\5\6\7\8")}]/, "?")
+ end
+
+ if defined? Encoding
+ def encode_as_latin1(str)
+ str.encode(TARGET_ENCODING, :undef => :replace, :invalid => :replace)
+ end
+ else
+ require 'iconv'
+ def encode_as_latin1(str)
+ Iconv.conv("#{TARGET_ENCODING}//TRANSLIT//IGNORE", "UTF-8", str)
+ end
+ end
+end
View
3 mspec/lib/mspec/utils/options.rb
@@ -280,6 +280,8 @@ def formatters
config[:formatter] = YamlFormatter
when 'p', 'profile'
config[:formatter] = ProfileFormatter
+ when 'j', 'junit'
+ config[:formatter] = JUnitFormatter
when 'mr', 'macruby'
config[:formatter] = MacRubyFormatter
else
@@ -299,6 +301,7 @@ def formatters
doc " a, *, spin SpinnerFormatter"
doc " t, method MethodFormatter"
doc " y, yaml YamlFormatter"
+ doc " j, junit JUnitFormatter\n"
doc " mr, macruby MacRubyFormatter\n"
on("-o", "--output", "FILE",
View
2 mspec/lib/mspec/utils/script.rb
@@ -86,7 +86,7 @@ def load(target)
# first two numbers in RUBY_VERSION. For example, on MRI 1.8.6,
# the file name would be 'ruby.1.8.mspec'.
def load_default
- return if load 'default.mspec'
+ load 'default.mspec'
if Object.const_defined?(:RUBY_ENGINE)
engine = RUBY_ENGINE
View
38 mspec/mspec.gemspec
@@ -0,0 +1,38 @@
+# -*- encoding: utf-8 -*-
+$:.unshift File.expand_path('../lib', __FILE__)
+require 'mspec/version'
+
+Gem::Specification.new do |gem|
+ gem.name = "mspec"
+ gem.version = MSpec::VERSION.to_s
+ gem.authors = ["Brian Ford"]
+ gem.email = ["bford@engineyard.com"]
+ gem.homepage = "http://rubyspec.org"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) unless File.extname(f) == ".bat" }.compact
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.require_paths = ["lib"]
+ gem.summary = <<-EOS
+ MSpec is a specialized framework that is syntax-compatible
+ with RSpec for basic things like describe, it blocks and
+ before, after actions.
+
+ MSpec contains additional features that assist in writing
+ the RubySpecs used by multiple Ruby implementations. Also,
+ MSpec attempts to use the simplest Ruby language features
+ so that beginning Ruby implementations can run it.
+ EOS
+ gem.has_rdoc = true
+ gem.extra_rdoc_files = %w[ README LICENSE ]
+ gem.rubygems_version = %q{1.3.5}
+ gem.rubyforge_project = 'http://rubyforge.org/projects/mspec'
+
+ gem.rdoc_options << '--title' << 'MSpec Gem' <<
+ '--main' << 'README' <<
+ '--line-numbers'
+
+ gem.add_development_dependency "rake", "~> 0.9"
+ gem.add_development_dependency "rspec", "~> 2.8"
+ gem.add_development_dependency "ruby-debug", "~> 0.10"
+end
View
4 mspec/spec/commands/mkspec_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/commands/mkspec'
@@ -336,7 +336,7 @@
describe MkSpec, ".main" do
before :each do
- @script = mock("MkSpec", :null_object => true)
+ @script = mock("MkSpec").as_null_object
MkSpec.stub!(:new).and_return(@script)
end
View
2 mspec/spec/commands/mspec_ci_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/runner/mspec'
require 'mspec/runner/filters/tag'
require 'mspec/commands/mspec-ci'
View
2 mspec/spec/commands/mspec_run_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/runner/mspec'
require 'mspec/commands/mspec-run'
View
12 mspec/spec/commands/mspec_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'yaml'
require 'mspec/commands/mspec'
@@ -108,9 +108,9 @@
before :each do
@stdout, $stdout = $stdout, IOStub.new
- @timer = mock("timer", :null_object => true)
+ @timer = mock("timer").as_null_object
@timer.stub!(:format).and_return("Finished in 42 seconds")
- @file = mock("file", :null_object => true)
+ @file = mock("file").as_null_object
File.stub!(:delete)
YAML.stub!(:load)
@@ -301,11 +301,11 @@
@script.options
end
- it "sets flags to --valgrind" do
+ it "sets :use_valgrind config option to true" do
["-A", "--valgrind"].each do |opt|
- @config[:flags] = []
+ @config[:use_valgrind] = false
@script.options [opt]
- @config[:flags].should include("--valgrind")
+ @config[:use_valgrind].should be_true
end
end
end
View
50 mspec/spec/commands/mspec_tag_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/runner/mspec'
require 'mspec/commands/mspec-tag'
require 'mspec/runner/actions/tag'
@@ -264,7 +264,7 @@
before :each do
MSpec.stub!(:process)
- options = mock("MSpecOptions", :null_object => true)
+ options = mock("MSpecOptions").as_null_object
options.stub!(:parse).and_return(["one", "two"])
MSpecOptions.stub!(:new).and_return(options)
@@ -318,36 +318,42 @@
@tl.stub!(:register)
end
- it "creates a TagAction if config[:tagger] is :add" do
- TagAction.should_receive(:new).with(:add, :fail, "fake", nil, [], []).and_return(@t)
- @script.register
+ it "raises an ArgumentError if no recognized action is given" do
+ @config[:tagger] = :totally_whack
+ lambda { @script.register }.should raise_error(ArgumentError)
end
- it "creates a TagAction if config[:tagger] is :del" do
- @config[:tagger] = :del
- @config[:outcome] = :pass
- TagAction.should_receive(:new).with(:del, :pass, "fake", nil, [], []).and_return(@t)
- @script.register
- end
+ describe "when config[:tagger] is the default (:add)" do
+ before :each do
+ @config[:formatter] = false
+ end
- it "calls #register on the TagAction instance" do
- TagAction.should_receive(:new).and_return(@t)
- @t.should_receive(:register)
- @script.register
- end
+ it "creates a TagAction" do
+ TagAction.should_receive(:new).and_return(@t)
+ @script.register
+ end
- it "raises an ArgumentError if no recognized action is given" do
- @config[:tagger] = :totally_whack
- lambda { @script.register }.should raise_error(ArgumentError)
+ it "creates a TagAction if config[:tagger] is :del" do
+ @config[:tagger] = :del
+ @config[:outcome] = :pass
+ TagAction.should_receive(:new).with(:del, :pass, "fake", nil, [], []).and_return(@t)
+ @script.register
+ end
+
+ it "calls #register on the TagAction instance" do
+ TagAction.should_receive(:new).and_return(@t)
+ @t.should_receive(:register)
+ @script.register
+ end
end
describe "when config[:tagger] is :list" do
before :each do
+ TagListAction.should_receive(:new).with(@config[:ltags]).and_return(@tl)
@config[:tagger] = :list
end
it "creates a TagListAction" do
- TagListAction.should_receive(:new).with(@config[:ltags]).and_return(@tl)
@tl.should_receive(:register)
@script.register
end
@@ -365,11 +371,11 @@
describe "when config[:tagger] is :list_all" do
before :each do
+ TagListAction.should_receive(:new).with(nil).and_return(@tl)
@config[:tagger] = :list_all
end
it "creates a TagListAction" do
- TagListAction.should_receive(:new).with(nil).and_return(@tl)
@tl.should_receive(:register)
@script.register
end
@@ -387,12 +393,12 @@
describe "when config[:tagger] is :purge" do
before :each do
+ TagPurgeAction.should_receive(:new).and_return(@tl)
MSpec.stub!(:register_mode)
@config[:tagger] = :purge
end
it "creates a TagPurgeAction" do
- TagPurgeAction.should_receive(:new).and_return(@tl)
@tl.should_receive(:register)
@script.register
end
View
2 mspec/spec/expectations/expectations_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
describe SpecExpectationNotMetError do
View
4 mspec/spec/expectations/should_spec.rb
@@ -1,7 +1,7 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'rbconfig'
-describe MSpec do
+describe "MSpec" do
before :all do
path = RbConfig::CONFIG['bindir']
exe = RbConfig::CONFIG['ruby_install_name']
View
4 mspec/spec/guards/background_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/background'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#process_is_foreground" do
before :each do
View
5 mspec/spec/guards/bug_spec.rb
@@ -1,6 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/utils/ruby_name'
-require 'mspec/guards/bug'
+require 'spec_helper'
+require 'mspec/guards'
describe BugGuard, "#match? when #implementation? is 'ruby'" do
before :all do
View
4 mspec/spec/guards/compliance_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/compliance'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#compliant_on" do
before :all do
View
4 mspec/spec/guards/conflict_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/conflict'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#conflicts_with" do
before :each do
View
4 mspec/spec/guards/endian_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/endian'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#big_endian" do
before :each do
View
4 mspec/spec/guards/extensions_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/extensions'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#extended_on" do
before :all do
View
4 mspec/spec/guards/feature_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/feature'
+require 'spec_helper'
+require 'mspec/guards'
describe FeatureGuard, ".enabled?" do
it "returns true if the feature is enabled" do
View
9 mspec/spec/guards/guard_spec.rb
@@ -1,6 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/utils/ruby_name'
-require 'mspec/guards/guard'
+require 'spec_helper'
+require 'mspec/guards'
require 'rbconfig'
describe SpecGuard, "#ruby_version_override=" do
@@ -19,15 +18,15 @@
end
describe SpecGuard, ".ruby_version" do
- before :all do
+ before :each do
@ruby_version = Object.const_get :RUBY_VERSION
@ruby_patchlevel = Object.const_get :RUBY_PATCHLEVEL
Object.const_set :RUBY_VERSION, "8.2.3"
Object.const_set :RUBY_PATCHLEVEL, 71
end
- after :all do
+ after :each do
Object.const_set :RUBY_VERSION, @ruby_version
Object.const_set :RUBY_PATCHLEVEL, @ruby_patchlevel
end
View
4 mspec/spec/guards/noncompliance_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/noncompliance'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#deviates_on" do
before :all do
View
4 mspec/spec/guards/platform_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/platform'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#platform_is" do
before :each do
View
4 mspec/spec/guards/quarantine_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/quarantine'
+require 'spec_helper'
+require 'mspec/guards'
describe QuarantineGuard, "#match?" do
it "returns false" do
View
4 mspec/spec/guards/runner_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/runner'
+require 'spec_helper'
+require 'mspec/guards'
describe RunnerGuard, "#match?" do
before :all do
View
4 mspec/spec/guards/specified_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/specified'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#unspecified" do
before :each do
View
4 mspec/spec/guards/superuser_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/superuser'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#as_superuser" do
before :each do
View
4 mspec/spec/guards/support_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/support'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#not_supported_on" do
before :all do
View
4 mspec/spec/guards/tty_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/tty'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#with_tty" do
before :each do
View
4 mspec/spec/guards/user_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/user'
+require 'spec_helper'
+require 'mspec/guards'
describe Object, "#as_user" do
before :each do
View
4 mspec/spec/guards/version_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/version'
+require 'spec_helper'
+require 'mspec/guards'
# The VersionGuard specifies a version of Ruby with a String of
# the form: v = 'major.minor.tiny.patchlevel'.
View
5 mspec/spec/helpers/argv_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/argv'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#argv" do
before :each do
View
5 mspec/spec/helpers/const_lookup_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/const_lookup'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
CONST = 2
View
5 mspec/spec/helpers/datetime_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/datetime'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#new_datetime" do
it "returns a default DateTime instance" do
View
5 mspec/spec/helpers/ducktype_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/ducktype'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#responds_to" do
it "returns true for specified symbols" do
View
5 mspec/spec/helpers/encode_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/encode'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#encode" do
it "raises an ArgumentError if the str parameter is not a String" do
View
4 mspec/spec/helpers/enumerator_class_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/enumerator_class'
+require 'spec_helper'
require 'mspec/guards'
+require 'mspec/helpers'
describe "#enumerator_class" do
View
6 mspec/spec/helpers/environment_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/guards/platform'
-require 'mspec/helpers/environment'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe "#env" do
it "returns a hash of variables" do
View
5 mspec/spec/helpers/fixture_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/fixture'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#fixture" do
before :each do
View
7 mspec/spec/helpers/flunk_spec.rb
@@ -1,12 +1,13 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/helpers/flunk'
require 'mspec/runner/mspec'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#flunk" do
before :each do
MSpec.stub!(:actions)
- MSpec.stub!(:current).and_return(mock("spec state", :null_object => true))
+ MSpec.stub!(:current).and_return(mock("spec state").as_null_object)
end
it "raises an SpecExpectationNotMetError unconditionally" do
View
5 mspec/spec/helpers/fmode_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/fmode'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#fmode" do
it "returns the argument unmodified if :encoding feature is enabled" do
View
5 mspec/spec/helpers/fs_spec.rb
@@ -1,7 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/guards'
-require 'mspec/helpers/tmp'
-require 'mspec/helpers/fs'
+require 'mspec/helpers'
describe Object, "#cp" do
before :each do
View
5 mspec/spec/helpers/hash_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/hash'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#hash_class" do
it "returns the Hash class" do
View
8 mspec/spec/helpers/io_spec.rb
@@ -1,8 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/io'
-require 'mspec/helpers/fs'
-require 'mspec/helpers/fmode'
-require 'mspec/helpers/tmp'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe IOStub do
before :each do
View
5 mspec/spec/helpers/language_version_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/language_version'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#language_version" do
before :all do
View
5 mspec/spec/helpers/mock_to_path_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/mock_to_path'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#mock_to_path" do
it "returns an object that responds to #to_path" do
View
5 mspec/spec/helpers/numeric_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/numeric'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#bignum_value" do
it "returns a value that is an instance of Bignum on any platform" do
View
40 mspec/spec/helpers/ruby_exe_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/ruby_exe'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
require 'rbconfig'
class RubyExeSpecs
@@ -175,4 +176,39 @@ class RubyExeSpecs
@script.should_receive(:`).with("ruby_spec_exe -w -Q -c > file.txt")
@script.ruby_exe nil, :options => "-c", :args => "> file.txt"
end
+
+ describe "with :env option" do
+ before :each do
+ @script.stub!(:`)
+ end
+
+ it "preserves the values of existing ENV keys" do
+ ENV["ABC"] = "123"
+ ENV.should_receive(:[]).with("RUBY_FLAGS")
+ ENV.should_receive(:[]).with("ABC")
+ @script.ruby_exe nil, :env => { :ABC => "xyz" }
+ end
+
+ it "adds the :env entries to ENV" do
+ ENV.should_receive(:[]=).with("ABC", "xyz")
+ @script.ruby_exe nil, :env => { :ABC => "xyz" }
+ end
+
+ it "deletes the :env entries in ENV when an exception is raised" do
+ ENV.should_receive(:delete).with("XYZ")
+ @script.ruby_exe nil, :env => { :XYZ => "xyz" }
+ end
+
+ it "resets the values of existing ENV keys when an exception is raised" do
+ ENV["ABC"] = "123"
+ ENV.should_receive(:[]=).with("ABC", "xyz")
+ ENV.should_receive(:[]=).with("ABC", "123")
+
+ @script.should_receive(:`).and_raise(Exception)
+ lambda do
+ @script.ruby_exe nil, :env => { :ABC => "xyz" }
+ end.should raise_error(Exception)
+ end
+
+ end
end
View
4 mspec/spec/helpers/scratch_spec.rb
@@ -1,4 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe ScratchPad do
it "records an object and returns a previously recorded object" do
View
5 mspec/spec/helpers/stasy_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/stasy'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#stasy when RUBY_VERSION < 1.9" do
before :all do
View
5 mspec/spec/helpers/tmp_spec.rb
@@ -1,5 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/helpers/tmp'
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
describe Object, "#tmp" do
before :all do
View
4 mspec/spec/matchers/base_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/base'
+require 'mspec/matchers'
require 'time'
describe SpecPositiveOperatorMatcher, "== operator" do
View
4 mspec/spec/matchers/be_an_instance_of_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/be_an_instance_of'
+require 'mspec/matchers'
module BeAnInOfSpecs
class A
View
4 mspec/spec/matchers/be_ancestor_of_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/be_ancestor_of'
+require 'mspec/matchers'
class Parent; end
class Child < Parent; end
View
4 mspec/spec/matchers/be_close_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/be_close'
+require 'mspec/matchers'
# Adapted from RSpec 1.0.8
describe BeCloseMatcher do
View
4 mspec/spec/matchers/be_computed_by_function_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/matchers/be_computed_by_function'
+require 'spec_helper'
+require 'mspec/matchers'
describe BeComputedByFunctionMatcher do
it "matches when all entries in the Array compute" do
View
4 mspec/spec/matchers/be_computed_by_spec.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/matchers/be_computed_by'
+require 'spec_helper'
+require 'mspec/matchers'
describe BeComputedByMatcher do
it "matches when all entries in the Array compute" do
View
4 mspec/spec/matchers/be_empty_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/be_empty'
+require 'mspec/matchers'
describe BeEmptyMatcher do
it "matches when actual is empty" do
View
6 mspec/spec/matchers/be_false_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/be_false'
+require 'mspec/matchers'
describe BeFalseMatcher do
it "matches when actual is false" do
@@ -25,4 +25,4 @@
matcher.matches?(false)
matcher.negative_failure_message.should == ["Expected false", "not to be false"]
end
-end
+end
View
4 mspec/spec/matchers/be_kind_of_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/be_kind_of'
+require 'mspec/matchers'
describe BeKindOfMatcher do
it "matches when actual is a kind_of? expected" do
View
28 mspec/spec/matchers/be_nan_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+require 'mspec/expectations/expectations'
+require 'mspec/guards'
+require 'mspec/helpers'
+require 'mspec/matchers'
+
+describe BeNaNMatcher do
+ it "matches when actual is NaN" do
+ BeNaNMatcher.new.matches?(nan_value).should == true
+ end
+
+ it "does not match when actual is not NaN" do
+ BeNaNMatcher.new.matches?(1.0).should == false
+ BeNaNMatcher.new.matches?(0).should == false
+ end
+
+ it "provides a useful failure message" do
+ matcher = BeNaNMatcher.new
+ matcher.matches?(0)
+ matcher.failure_message.should == ["Expected 0", "to be NaN"]
+ end
+
+ it "provides a useful negative failure message" do
+ matcher = BeNaNMatcher.new
+ matcher.matches?(nan_value)
+ matcher.negative_failure_message.should == ["Expected NaN", "not to be NaN"]
+ end
+end
View
6 mspec/spec/matchers/be_nil_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/be_nil'
+require 'mspec/matchers'
describe BeNilMatcher do
it "matches when actual is nil" do
@@ -24,4 +24,4 @@
matcher.matches?(nil)
matcher.negative_failure_message.should == ["Expected nil", "not to be nil"]
end
-end
+end
View
6 mspec/spec/matchers/be_true_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/be_true'
+require 'mspec/matchers'
describe BeTrueMatcher do
it "matches when actual is true" do
@@ -25,4 +25,4 @@
matcher.matches?(true)
matcher.negative_failure_message.should == ["Expected true", "not to be true"]
end
-end
+end
View
4 mspec/spec/matchers/be_valid_dns_name_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/be_valid_dns_name'
+require 'mspec/matchers'
describe BeValidDNSName do
it "matches when actual is 'localhost'" do
View
4 mspec/spec/matchers/complain_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/complain'
+require 'mspec/matchers'
describe ComplainMatcher do
it "matches when executing the proc results in output to $stderr" do
View
4 mspec/spec/matchers/eql_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/eql'
+require 'mspec/matchers'
describe EqlMatcher do
it "matches when actual is eql? to expected" do
View
4 mspec/spec/matchers/equal_element_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/equal_element'
+require 'mspec/matchers'
describe EqualElementMatcher do
it "matches if it finds an element with the passed name, no matter what attributes/content" do
View
4 mspec/spec/matchers/equal_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/equal'
+require 'mspec/matchers'
describe EqualMatcher do
it "matches when actual is equal? to expected" do
View
4 mspec/spec/matchers/equal_utf16_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/equal_utf16'
+require 'mspec/matchers'
describe EqualUtf16Matcher do
before :all do
View
6 mspec/spec/matchers/have_class_variable_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/have_class_variable'
+require 'mspec/matchers'
class IVarModMock; end
@@ -72,4 +72,4 @@ def IVarModMock.class_variables
end
it_should_behave_like "have_class_variable, on all Ruby versions"
-end
+end
View
4 mspec/spec/matchers/have_constant_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/have_constant'
+require 'mspec/matchers'
class HCMSpecs
X = :x
View
8 mspec/spec/matchers/have_data_spec.rb
@@ -1,8 +1,8 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/have_data'
-require 'mspec/helpers/tmp'
-require 'mspec/helpers/fs'
+require 'mspec/guards'
+require 'mspec/helpers'
+require 'mspec/matchers'
describe HaveDataMatcher do
before :each do
View
4 mspec/spec/matchers/have_instance_method_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/have_instance_method'
+require 'mspec/matchers'
class HIMMSpecs
def instance_method
View
6 mspec/spec/matchers/have_instance_variable_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/have_instance_variable'
+require 'mspec/matchers'
shared_examples_for "have_instance_variable, on all Ruby versions" do
after :all do
@@ -72,4 +72,4 @@ def @object.instance_variables
end
it_should_behave_like "have_instance_variable, on all Ruby versions"
-end
+end
View
4 mspec/spec/matchers/have_method_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/have_method'
+require 'mspec/matchers'
class HMMSpecs
def instance_method
View
4 mspec/spec/matchers/have_private_instance_method_spec.rb
</
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
require 'mspec/expectations/expectations'
-require 'mspec/matchers/have_private_instance_method'
+require 'mspec/matchers'
class HPIMMSpecs