From 9f19436f1612b0453b8569ad819874449e86b6bd Mon Sep 17 00:00:00 2001 From: eregon Date: Thu, 15 Jun 2017 12:48:26 +0000 Subject: Update to ruby/mspec@d900a49 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/mspec/lib/mspec/commands/mspec-ci.rb | 1 - spec/mspec/lib/mspec/commands/mspec-run.rb | 1 - spec/mspec/lib/mspec/commands/mspec-tag.rb | 1 - spec/mspec/lib/mspec/guards.rb | 1 - spec/mspec/lib/mspec/guards/block_device.rb | 6 +- spec/mspec/lib/mspec/guards/bug.rb | 6 +- spec/mspec/lib/mspec/guards/conflict.rb | 14 +- spec/mspec/lib/mspec/guards/endian.rb | 12 +- spec/mspec/lib/mspec/guards/feature.rb | 58 ++++---- spec/mspec/lib/mspec/guards/guard.rb | 1 - spec/mspec/lib/mspec/guards/platform.rb | 16 +-- spec/mspec/lib/mspec/guards/quarantine.rb | 6 +- spec/mspec/lib/mspec/guards/superuser.rb | 12 +- spec/mspec/lib/mspec/guards/support.rb | 6 +- spec/mspec/lib/mspec/guards/version.rb | 6 +- spec/mspec/lib/mspec/helpers/argf.rb | 66 +++++----- spec/mspec/lib/mspec/helpers/argv.rb | 82 ++++++------ spec/mspec/lib/mspec/helpers/datetime.rb | 82 ++++++------ spec/mspec/lib/mspec/helpers/fixture.rb | 46 ++++--- spec/mspec/lib/mspec/helpers/flunk.rb | 6 +- spec/mspec/lib/mspec/helpers/fs.rb | 104 +++++++-------- spec/mspec/lib/mspec/helpers/io.rb | 82 ++++++------ spec/mspec/lib/mspec/helpers/mock_to_path.rb | 12 +- spec/mspec/lib/mspec/helpers/numeric.rb | 104 +++++++-------- spec/mspec/lib/mspec/helpers/ruby_exe.rb | 168 ++++++++++++------------ spec/mspec/lib/mspec/helpers/tmp.rb | 18 ++- spec/mspec/lib/mspec/helpers/warning.rb | 14 +- spec/mspec/lib/mspec/runner/formatters/html.rb | 2 +- spec/mspec/lib/mspec/runner/formatters/junit.rb | 3 +- spec/mspec/lib/mspec/utils/options.rb | 8 -- spec/mspec/lib/mspec/utils/ruby_name.rb | 8 -- spec/mspec/spec/commands/mspec_ci_spec.rb | 5 - spec/mspec/spec/commands/mspec_run_spec.rb | 5 - spec/mspec/spec/commands/mspec_tag_spec.rb | 5 - spec/mspec/spec/guards/bug_spec.rb | 12 +- spec/mspec/spec/guards/platform_spec.rb | 38 +++--- spec/mspec/spec/guards/support_spec.rb | 16 +-- spec/mspec/spec/helpers/ruby_exe_spec.rb | 32 +++-- spec/mspec/spec/runner/formatters/html_spec.rb | 7 +- spec/mspec/spec/utils/options_spec.rb | 24 ---- spec/mspec/tool/sync/sync-rubyspec.rb | 7 +- 41 files changed, 500 insertions(+), 603 deletions(-) delete mode 100644 spec/mspec/lib/mspec/utils/ruby_name.rb (limited to 'spec') diff --git a/spec/mspec/lib/mspec/commands/mspec-ci.rb b/spec/mspec/lib/mspec/commands/mspec-ci.rb index 225d2bb96d..cb0193f42d 100644 --- a/spec/mspec/lib/mspec/commands/mspec-ci.rb +++ b/spec/mspec/lib/mspec/commands/mspec-ci.rb @@ -22,7 +22,6 @@ class MSpecCI < MSpecScript options.chdir options.prefix options.configure { |f| load f } - options.name options.pretend options.interrupt diff --git a/spec/mspec/lib/mspec/commands/mspec-run.rb b/spec/mspec/lib/mspec/commands/mspec-run.rb index 45b26e88ad..249f9f5771 100644 --- a/spec/mspec/lib/mspec/commands/mspec-run.rb +++ b/spec/mspec/lib/mspec/commands/mspec-run.rb @@ -32,7 +32,6 @@ class MSpecRun < MSpecScript options.chdir options.prefix options.configure { |f| load f } - options.name options.randomize options.repeat options.pretend diff --git a/spec/mspec/lib/mspec/commands/mspec-tag.rb b/spec/mspec/lib/mspec/commands/mspec-tag.rb index 7582015916..8bc3382e91 100644 --- a/spec/mspec/lib/mspec/commands/mspec-tag.rb +++ b/spec/mspec/lib/mspec/commands/mspec-tag.rb @@ -30,7 +30,6 @@ class MSpecTag < MSpecScript options.doc "\n How to modify the execution" options.configure { |f| load f } - options.name options.pretend options.unguarded options.interrupt diff --git a/spec/mspec/lib/mspec/guards.rb b/spec/mspec/lib/mspec/guards.rb index 0d7d300c64..454ac0c776 100644 --- a/spec/mspec/lib/mspec/guards.rb +++ b/spec/mspec/lib/mspec/guards.rb @@ -1,4 +1,3 @@ -require 'mspec/utils/ruby_name' require 'mspec/guards/block_device' require 'mspec/guards/bug' require 'mspec/guards/conflict' diff --git a/spec/mspec/lib/mspec/guards/block_device.rb b/spec/mspec/lib/mspec/guards/block_device.rb index 327f6e564e..ae736a2d4e 100644 --- a/spec/mspec/lib/mspec/guards/block_device.rb +++ b/spec/mspec/lib/mspec/guards/block_device.rb @@ -11,8 +11,6 @@ class BlockDeviceGuard < SpecGuard end end -class Object - def with_block_device(&block) - BlockDeviceGuard.new.run_if(:with_block_device, &block) - end +def with_block_device(&block) + BlockDeviceGuard.new.run_if(:with_block_device, &block) end diff --git a/spec/mspec/lib/mspec/guards/bug.rb b/spec/mspec/lib/mspec/guards/bug.rb index 31de6e080d..b1bfc6413e 100644 --- a/spec/mspec/lib/mspec/guards/bug.rb +++ b/spec/mspec/lib/mspec/guards/bug.rb @@ -23,8 +23,6 @@ class BugGuard < VersionGuard end end -class Object - def ruby_bug(bug, version, &block) - BugGuard.new(bug, version).run_unless(:ruby_bug, &block) - end +def ruby_bug(bug, version, &block) + BugGuard.new(bug, version).run_unless(:ruby_bug, &block) end diff --git a/spec/mspec/lib/mspec/guards/conflict.rb b/spec/mspec/lib/mspec/guards/conflict.rb index c1d33e3512..7a27671c1e 100644 --- a/spec/mspec/lib/mspec/guards/conflict.rb +++ b/spec/mspec/lib/mspec/guards/conflict.rb @@ -8,12 +8,10 @@ class ConflictsGuard < SpecGuard end end -class Object - # In some cases, libraries will modify another Ruby method's - # behavior. The specs for the method's behavior will then fail - # if that library is loaded. This guard will not run if any of - # the specified constants exist in Object.constants. - def conflicts_with(*modules, &block) - ConflictsGuard.new(*modules).run_unless(:conflicts_with, &block) - end +# In some cases, libraries will modify another Ruby method's +# behavior. The specs for the method's behavior will then fail +# if that library is loaded. This guard will not run if any of +# the specified constants exist in Object.constants. +def conflicts_with(*modules, &block) + ConflictsGuard.new(*modules).run_unless(:conflicts_with, &block) end diff --git a/spec/mspec/lib/mspec/guards/endian.rb b/spec/mspec/lib/mspec/guards/endian.rb index 6bb01263c7..79335a8933 100644 --- a/spec/mspec/lib/mspec/guards/endian.rb +++ b/spec/mspec/lib/mspec/guards/endian.rb @@ -16,12 +16,10 @@ class BigEndianGuard < EndianGuard end end -class Object - def big_endian(&block) - BigEndianGuard.new.run_if(:big_endian, &block) - end +def big_endian(&block) + BigEndianGuard.new.run_if(:big_endian, &block) +end - def little_endian(&block) - BigEndianGuard.new.run_unless(:little_endian, &block) - end +def little_endian(&block) + BigEndianGuard.new.run_unless(:little_endian, &block) end diff --git a/spec/mspec/lib/mspec/guards/feature.rb b/spec/mspec/lib/mspec/guards/feature.rb index 346212bda0..30984e0cc5 100644 --- a/spec/mspec/lib/mspec/guards/feature.rb +++ b/spec/mspec/lib/mspec/guards/feature.rb @@ -10,34 +10,32 @@ class FeatureGuard < SpecGuard end end -class Object - # Provides better documentation in the specs by - # naming sets of features that work together as - # a whole. Examples include :encoding, :fiber, - # :continuation, :fork. - # - # Usage example: - # - # with_feature :encoding do - # # specs for a method that provides aspects - # # of the encoding feature - # end - # - # Multiple features must all be enabled for the - # guard to run: - # - # with_feature :one, :two do - # # these specs will run if features :one AND - # # :two are enabled. - # end - # - # The implementation must explicitly enable a feature - # by adding code like the following to the .mspec - # configuration file: - # - # MSpec.enable_feature :encoding - # - def with_feature(*features, &block) - FeatureGuard.new(*features).run_if(:with_feature, &block) - end +# Provides better documentation in the specs by +# naming sets of features that work together as +# a whole. Examples include :encoding, :fiber, +# :continuation, :fork. +# +# Usage example: +# +# with_feature :encoding do +# # specs for a method that provides aspects +# # of the encoding feature +# end +# +# Multiple features must all be enabled for the +# guard to run: +# +# with_feature :one, :two do +# # these specs will run if features :one AND +# # :two are enabled. +# end +# +# The implementation must explicitly enable a feature +# by adding code like the following to the .mspec +# configuration file: +# +# MSpec.enable_feature :encoding +# +def with_feature(*features, &block) + FeatureGuard.new(*features).run_if(:with_feature, &block) end diff --git a/spec/mspec/lib/mspec/guards/guard.rb b/spec/mspec/lib/mspec/guards/guard.rb index c95d8f7923..88adbba260 100644 --- a/spec/mspec/lib/mspec/guards/guard.rb +++ b/spec/mspec/lib/mspec/guards/guard.rb @@ -1,6 +1,5 @@ require 'mspec/runner/mspec' require 'mspec/runner/actions/tally' -require 'mspec/utils/ruby_name' class SpecGuard def self.report diff --git a/spec/mspec/lib/mspec/guards/platform.rb b/spec/mspec/lib/mspec/guards/platform.rb index 875aef6c9c..96176b8753 100644 --- a/spec/mspec/lib/mspec/guards/platform.rb +++ b/spec/mspec/lib/mspec/guards/platform.rb @@ -5,9 +5,9 @@ class PlatformGuard < SpecGuard args.any? do |name| case name when :rubinius - RUBY_NAME.start_with?('rbx') + RUBY_ENGINE.start_with?('rbx') when :ruby, :jruby, :truffleruby, :ironruby, :macruby, :maglev, :topaz, :opal - RUBY_NAME.start_with?(name.to_s) + RUBY_ENGINE.start_with?(name.to_s) else raise "unknown implementation #{name}" end @@ -67,12 +67,10 @@ class PlatformGuard < SpecGuard end end -class Object - def platform_is(*args, &block) - PlatformGuard.new(*args).run_if(:platform_is, &block) - end +def platform_is(*args, &block) + PlatformGuard.new(*args).run_if(:platform_is, &block) +end - def platform_is_not(*args, &block) - PlatformGuard.new(*args).run_unless(:platform_is_not, &block) - end +def platform_is_not(*args, &block) + PlatformGuard.new(*args).run_unless(:platform_is_not, &block) end diff --git a/spec/mspec/lib/mspec/guards/quarantine.rb b/spec/mspec/lib/mspec/guards/quarantine.rb index 4724613a0f..ec4d01f9ea 100644 --- a/spec/mspec/lib/mspec/guards/quarantine.rb +++ b/spec/mspec/lib/mspec/guards/quarantine.rb @@ -6,8 +6,6 @@ class QuarantineGuard < SpecGuard end end -class Object - def quarantine!(&block) - QuarantineGuard.new.run_unless(:quarantine!, &block) - end +def quarantine!(&block) + QuarantineGuard.new.run_unless(:quarantine!, &block) end diff --git a/spec/mspec/lib/mspec/guards/superuser.rb b/spec/mspec/lib/mspec/guards/superuser.rb index 6e447198a7..e92ea7e862 100644 --- a/spec/mspec/lib/mspec/guards/superuser.rb +++ b/spec/mspec/lib/mspec/guards/superuser.rb @@ -6,12 +6,10 @@ class SuperUserGuard < SpecGuard end end -class Object - def as_superuser(&block) - SuperUserGuard.new.run_if(:as_superuser, &block) - end +def as_superuser(&block) + SuperUserGuard.new.run_if(:as_superuser, &block) +end - def as_user(&block) - SuperUserGuard.new.run_unless(:as_user, &block) - end +def as_user(&block) + SuperUserGuard.new.run_unless(:as_user, &block) end diff --git a/spec/mspec/lib/mspec/guards/support.rb b/spec/mspec/lib/mspec/guards/support.rb index f1760ece2e..790bea1077 100644 --- a/spec/mspec/lib/mspec/guards/support.rb +++ b/spec/mspec/lib/mspec/guards/support.rb @@ -9,8 +9,6 @@ class SupportedGuard < SpecGuard end end -class Object - def not_supported_on(*args, &block) - SupportedGuard.new(*args).run_unless(:not_supported_on, &block) - end +def not_supported_on(*args, &block) + SupportedGuard.new(*args).run_unless(:not_supported_on, &block) end diff --git a/spec/mspec/lib/mspec/guards/version.rb b/spec/mspec/lib/mspec/guards/version.rb index 110853e082..cb08fdac73 100644 --- a/spec/mspec/lib/mspec/guards/version.rb +++ b/spec/mspec/lib/mspec/guards/version.rb @@ -32,8 +32,6 @@ class VersionGuard < SpecGuard end end -class Object - def ruby_version_is(*args, &block) - VersionGuard.new(*args).run_if(:ruby_version_is, &block) - end +def ruby_version_is(*args, &block) + VersionGuard.new(*args).run_if(:ruby_version_is, &block) end diff --git a/spec/mspec/lib/mspec/helpers/argf.rb b/spec/mspec/lib/mspec/helpers/argf.rb index 1ba48b9378..4d3e0f46b3 100644 --- a/spec/mspec/lib/mspec/helpers/argf.rb +++ b/spec/mspec/lib/mspec/helpers/argf.rb @@ -1,37 +1,35 @@ -class Object - # Convenience helper for specs using ARGF. - # Set @argf to an instance of ARGF.class with the given +argv+. - # That instance must be used instead of ARGF as ARGF is global - # and it is not always possible to reset its state correctly. - # - # The helper yields to the block and then close - # the files open by the instance. Example: - # - # describe "That" do - # it "does something" do - # argf ['a', 'b'] do - # # do something - # end - # end - # end - def argf(argv) - if argv.empty? or argv.length > 2 - raise "Only 1 or 2 filenames are allowed for the argf helper so files can be properly closed: #{argv.inspect}" - end - @argf ||= nil - raise "Cannot nest calls to the argf helper" if @argf +# Convenience helper for specs using ARGF. +# Set @argf to an instance of ARGF.class with the given +argv+. +# That instance must be used instead of ARGF as ARGF is global +# and it is not always possible to reset its state correctly. +# +# The helper yields to the block and then close +# the files open by the instance. Example: +# +# describe "That" do +# it "does something" do +# argf ['a', 'b'] do +# # do something +# end +# end +# end +def argf(argv) + if argv.empty? or argv.length > 2 + raise "Only 1 or 2 filenames are allowed for the argf helper so files can be properly closed: #{argv.inspect}" + end + @argf ||= nil + raise "Cannot nest calls to the argf helper" if @argf - @argf = ARGF.class.new(*argv) - @__mspec_saved_argf_file__ = @argf.file - begin - yield - ensure - file1 = @__mspec_saved_argf_file__ - file2 = @argf.file # Either the first file or the second - file1.close if !file1.closed? and file1 != STDIN - file2.close if !file2.closed? and file2 != STDIN - @argf = nil - @__mspec_saved_argf_file__ = nil - end + @argf = ARGF.class.new(*argv) + @__mspec_saved_argf_file__ = @argf.file + begin + yield + ensure + file1 = @__mspec_saved_argf_file__ + file2 = @argf.file # Either the first file or the second + file1.close if !file1.closed? and file1 != STDIN + file2.close if !file2.closed? and file2 != STDIN + @argf = nil + @__mspec_saved_argf_file__ = nil end end diff --git a/spec/mspec/lib/mspec/helpers/argv.rb b/spec/mspec/lib/mspec/helpers/argv.rb index c8cbbf2ac3..9dac384dbd 100644 --- a/spec/mspec/lib/mspec/helpers/argv.rb +++ b/spec/mspec/lib/mspec/helpers/argv.rb @@ -1,45 +1,43 @@ -class Object - # Convenience helper for altering ARGV. Saves the - # value of ARGV and sets it to +args+. If a block - # is given, yields to the block and then restores - # the value of ARGV. The previously saved value of - # ARGV can be restored by passing +:restore+. The - # former is useful in a single spec. The latter is - # useful in before/after actions. For example: - # - # describe "This" do - # before do - # argv ['a', 'b'] - # end - # - # after do - # argv :restore - # end - # - # it "does something" do - # # do something - # end - # end - # - # describe "That" do - # it "does something" do - # argv ['a', 'b'] do - # # do something - # end - # end - # end - def argv(args) - if args == :restore - ARGV.replace(@__mspec_saved_argv__ || []) - else - @__mspec_saved_argv__ = ARGV.dup - ARGV.replace args - if block_given? - begin - yield - ensure - argv :restore - end +# Convenience helper for altering ARGV. Saves the +# value of ARGV and sets it to +args+. If a block +# is given, yields to the block and then restores +# the value of ARGV. The previously saved value of +# ARGV can be restored by passing +:restore+. The +# former is useful in a single spec. The latter is +# useful in before/after actions. For example: +# +# describe "This" do +# before do +# argv ['a', 'b'] +# end +# +# after do +# argv :restore +# end +# +# it "does something" do +# # do something +# end +# end +# +# describe "That" do +# it "does something" do +# argv ['a', 'b'] do +# # do something +# end +# end +# end +def argv(args) + if args == :restore + ARGV.replace(@__mspec_saved_argv__ || []) + else + @__mspec_saved_argv__ = ARGV.dup + ARGV.replace args + if block_given? + begin + yield + ensure + argv :restore end end end diff --git a/spec/mspec/lib/mspec/helpers/datetime.rb b/spec/mspec/lib/mspec/helpers/datetime.rb index 4cb57bdaa1..1520b971ea 100644 --- a/spec/mspec/lib/mspec/helpers/datetime.rb +++ b/spec/mspec/lib/mspec/helpers/datetime.rb @@ -1,51 +1,47 @@ -class Object - # The new_datetime helper makes writing DateTime specs more simple by - # providing default constructor values and accepting a Hash of only the - # constructor values needed for the particular spec. For example: - # - # new_datetime :hour => 1, :minute => 20 - # - # Possible keys are: - # :year, :month, :day, :hour, :minute, :second, :offset and :sg. +# The new_datetime helper makes writing DateTime specs more simple by +# providing default constructor values and accepting a Hash of only the +# constructor values needed for the particular spec. For example: +# +# new_datetime :hour => 1, :minute => 20 +# +# Possible keys are: +# :year, :month, :day, :hour, :minute, :second, :offset and :sg. +def new_datetime(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] +end - def new_datetime(opts={}) - require 'date' +def with_timezone(name, offset = nil, daylight_saving_zone = "") + zone = name.dup - value = { - :year => -4712, - :month => 1, - :day => 1, - :hour => 0, - :minute => 0, - :second => 0, - :offset => 0, - :sg => Date::ITALY - }.merge opts + if offset + # TZ convention is backwards + offset = -offset - DateTime.new value[:year], value[:month], value[:day], value[:hour], - value[:minute], value[:second], value[:offset], value[:sg] + zone += offset.to_s + zone += ":00:00" end + zone += daylight_saving_zone - def with_timezone(name, offset = nil, daylight_saving_zone = "") - zone = name.dup - - if offset - # TZ convention is backwards - offset = -offset - - zone += offset.to_s - zone += ":00:00" - end - zone += daylight_saving_zone + old = ENV["TZ"] + ENV["TZ"] = zone - old = ENV["TZ"] - ENV["TZ"] = zone - - begin - yield - ensure - ENV["TZ"] = old - end + begin + yield + ensure + ENV["TZ"] = old end - end diff --git a/spec/mspec/lib/mspec/helpers/fixture.rb b/spec/mspec/lib/mspec/helpers/fixture.rb index 718c1b7a94..f3bbe423bd 100644 --- a/spec/mspec/lib/mspec/helpers/fixture.rb +++ b/spec/mspec/lib/mspec/helpers/fixture.rb @@ -1,26 +1,24 @@ -class Object - # Returns the name of a fixture file by adjoining the directory - # of the +file+ argument with "fixtures" and the contents of the - # +args+ array. For example, - # - # +file+ == "some/example_spec.rb" - # - # and - # - # +args+ == ["subdir", "file.txt"] - # - # then the result is the expanded path of - # - # "some/fixtures/subdir/file.txt". - def fixture(file, *args) - path = File.dirname(file) - path = path[0..-7] if path[-7..-1] == "/shared" - fixtures = path[-9..-1] == "/fixtures" ? "" : "fixtures" - if File.respond_to?(:realpath) - path = File.realpath(path) - else - path = File.expand_path(path) - end - File.join(path, fixtures, args) +# Returns the name of a fixture file by adjoining the directory +# of the +file+ argument with "fixtures" and the contents of the +# +args+ array. For example, +# +# +file+ == "some/example_spec.rb" +# +# and +# +# +args+ == ["subdir", "file.txt"] +# +# then the result is the expanded path of +# +# "some/fixtures/subdir/file.txt". +def fixture(file, *args) + path = File.dirname(file) + path = path[0..-7] if path[-7..-1] == "/shared" + fixtures = path[-9..-1] == "/fixtures" ? "" : "fixtures" + if File.respond_to?(:realpath) + path = File.realpath(path) + else + path = File.expand_path(path) end + File.join(path, fixtures, args) end diff --git a/spec/mspec/lib/mspec/helpers/flunk.rb b/spec/mspec/lib/mspec/helpers/flunk.rb index 35bd939b85..68fb3cadac 100644 --- a/spec/mspec/lib/mspec/helpers/flunk.rb +++ b/spec/mspec/lib/mspec/helpers/flunk.rb @@ -1,5 +1,3 @@ -class Object - def flunk(msg="This example is a failure") - SpecExpectation.fail_with "Failed:", msg - end +def flunk(msg="This example is a failure") + SpecExpectation.fail_with "Failed:", msg end diff --git a/spec/mspec/lib/mspec/helpers/fs.rb b/spec/mspec/lib/mspec/helpers/fs.rb index c41389e755..fb2c0f702c 100644 --- a/spec/mspec/lib/mspec/helpers/fs.rb +++ b/spec/mspec/lib/mspec/helpers/fs.rb @@ -1,72 +1,70 @@ -class Object - # Copies a file - def cp(source, dest) - File.open(dest, "wb") do |d| - File.open(source, "rb") do |s| - while data = s.read(1024) - d.write data - end +# Copies a file +def cp(source, dest) + File.open(dest, "wb") do |d| + File.open(source, "rb") do |s| + while data = s.read(1024) + d.write data end end end +end - # Creates each directory in path that does not exist. - def mkdir_p(path) - parts = File.expand_path(path).split %r[/|\\] - name = parts.shift - parts.each do |part| - name = File.join name, part +# Creates each directory in path that does not exist. +def mkdir_p(path) + parts = File.expand_path(path).split %r[/|\\] + name = parts.shift + parts.each do |part| + name = File.join name, part - if File.file? name - raise ArgumentError, "path component of #{path} is a file" - end + if File.file? name + raise ArgumentError, "path component of #{path} is a file" + end - unless File.directory? name - begin - Dir.mkdir name - rescue Errno::EEXIST => e - if File.directory? name - # OK, another process/thread created the same directory - else - raise e - end + unless File.directory? name + begin + Dir.mkdir name + rescue Errno::EEXIST => e + if File.directory? name + # OK, another process/thread created the same directory + else + raise e end end end end +end - # Recursively removes all files and directories in +path+ - # if +path+ is a directory. Removes the file if +path+ is - # a file. - def rm_r(*paths) - paths.each do |path| - path = File.expand_path path +# Recursively removes all files and directories in +path+ +# if +path+ is a directory. Removes the file if +path+ is +# a file. +def rm_r(*paths) + paths.each do |path| + path = File.expand_path path - prefix = SPEC_TEMP_DIR - unless path[0, prefix.size] == prefix - raise ArgumentError, "#{path} is not prefixed by #{prefix}" - end + prefix = SPEC_TEMP_DIR + unless path[0, prefix.size] == prefix + raise ArgumentError, "#{path} is not prefixed by #{prefix}" + end - # File.symlink? needs to be checked first as - # File.exist? returns false for dangling symlinks - if File.symlink? path - File.unlink path - elsif File.directory? path - Dir.entries(path).each { |x| rm_r "#{path}/#{x}" unless x =~ /^\.\.?$/ } - Dir.rmdir path - elsif File.exist? path - File.delete path - end + # File.symlink? needs to be checked first as + # File.exist? returns false for dangling symlinks + if File.symlink? path + File.unlink path + elsif File.directory? path + Dir.entries(path).each { |x| rm_r "#{path}/#{x}" unless x =~ /^\.\.?$/ } + Dir.rmdir path + elsif File.exist? path + File.delete path end end +end - # Creates a file +name+. Creates the directory for +name+ - # if it does not exist. - def touch(name, mode="w") - mkdir_p File.dirname(name) +# Creates a file +name+. Creates the directory for +name+ +# if it does not exist. +def touch(name, mode="w") + mkdir_p File.dirname(name) - File.open(name, mode) do |f| - yield f if block_given? - end + File.open(name, mode) do |f| + yield f if block_given? end end diff --git a/spec/mspec/lib/mspec/helpers/io.rb b/spec/mspec/lib/mspec/helpers/io.rb index 83d14441a7..57dc0d53a4 100644 --- a/spec/mspec/lib/mspec/helpers/io.rb +++ b/spec/mspec/lib/mspec/helpers/io.rb @@ -61,53 +61,51 @@ class IOStub end end -class Object - # Creates a "bare" file descriptor (i.e. one that is not associated - # with any Ruby object). The file descriptor can safely be passed - # to IO.new without creating a Ruby object alias to the fd. - def new_fd(name, mode="w:utf-8") - mode = options_or_mode(mode) - - if mode.kind_of? Hash - if mode.key? :mode - mode = mode[:mode] - else - raise ArgumentError, "new_fd options Hash must include :mode" - end +# Creates a "bare" file descriptor (i.e. one that is not associated +# with any Ruby object). The file descriptor can safely be passed +# to IO.new without creating a Ruby object alias to the fd. +def new_fd(name, mode="w:utf-8") + mode = options_or_mode(mode) + + if mode.kind_of? Hash + if mode.key? :mode + mode = mode[:mode] + else + raise ArgumentError, "new_fd options Hash must include :mode" end - - IO.sysopen name, fmode(mode) end - # Creates an IO instance for a temporary file name. The file - # must be deleted. - def new_io(name, mode="w:utf-8") - IO.new new_fd(name, options_or_mode(mode)), options_or_mode(mode) - end + IO.sysopen name, fmode(mode) +end - # This helper simplifies passing file access modes regardless of - # whether the :encoding feature is enabled. Only the access specifier - # itself will be returned if :encoding is not enabled. Otherwise, - # the full mode string will be returned (i.e. the helper is a no-op). - def fmode(mode) - if FeatureGuard.enabled? :encoding - mode - else - mode.split(':').first - end - end +# Creates an IO instance for a temporary file name. The file +# must be deleted. +def new_io(name, mode="w:utf-8") + IO.new new_fd(name, options_or_mode(mode)), options_or_mode(mode) +end - # This helper simplifies passing file access modes or options regardless of - # whether the :encoding feature is enabled. Only the access specifier itself - # will be returned if :encoding is not enabled. Otherwise, the full mode - # string or option will be returned (i.e. the helper is a no-op). - def options_or_mode(oom) - return fmode(oom) if oom.kind_of? String +# This helper simplifies passing file access modes regardless of +# whether the :encoding feature is enabled. Only the access specifier +# itself will be returned if :encoding is not enabled. Otherwise, +# the full mode string will be returned (i.e. the helper is a no-op). +def fmode(mode) + if FeatureGuard.enabled? :encoding + mode + else + mode.split(':').first + end +end - if FeatureGuard.enabled? :encoding - oom - else - fmode(oom[:mode] || "r:utf-8") - end +# This helper simplifies passing file access modes or options regardless of +# whether the :encoding feature is enabled. Only the access specifier itself +# will be returned if :encoding is not enabled. Otherwise, the full mode +# string or option will be returned (i.e. the helper is a no-op). +def options_or_mode(oom) + return fmode(oom) if oom.kind_of? String + + if FeatureGuard.enabled? :encoding + oom + else + fmode(oom[:mode] || "r:utf-8") end end diff --git a/spec/mspec/lib/mspec/helpers/mock_to_path.rb b/spec/mspec/lib/mspec/helpers/mock_to_path.rb index 683bb1d9d6..2780afc54a 100644 --- a/spec/mspec/lib/mspec/helpers/mock_to_path.rb +++ b/spec/mspec/lib/mspec/helpers/mock_to_path.rb @@ -1,8 +1,6 @@ -class Object - def mock_to_path(path) - # Cannot use our Object#mock here since it conflicts with RSpec - obj = MockObject.new('path') - obj.should_receive(:to_path).and_return(path) - obj - end +def mock_to_path(path) + # Cannot use our Object#mock here since it conflicts with RSpec + obj = MockObject.new('path') + obj.should_receive(:to_path).and_return(path) + obj end diff --git a/spec/mspec/lib/mspec/helpers/numeric.rb b/spec/mspec/lib/mspec/helpers/numeric.rb index ff30cf2b83..312aafae35 100644 --- a/spec/mspec/lib/mspec/helpers/numeric.rb +++ b/spec/mspec/lib/mspec/helpers/numeric.rb @@ -1,72 +1,70 @@ require 'mspec/guards/platform' -class Object - def nan_value - 0/0.0 - end - - def infinity_value - 1/0.0 - end - - def bignum_value(plus=0) - 0x8000_0000_0000_0000 + plus - end +def nan_value + 0/0.0 +end - # This is a bit hairy, but we need to be able to write specs that cover the - # boundary between Fixnum and Bignum for operations like Fixnum#<<. Since - # this boundary is implementation-dependent, we use these helpers to write - # specs based on the relationship between values rather than specific - # values. - if PlatformGuard.standard? or PlatformGuard.implementation? :topaz - if PlatformGuard.wordsize? 32 - def fixnum_max - (2**30) - 1 - end +def infinity_value + 1/0.0 +end - def fixnum_min - -(2**30) - end - elsif PlatformGuard.wordsize? 64 - def fixnum_max - (2**62) - 1 - end +def bignum_value(plus=0) + 0x8000_0000_0000_0000 + plus +end - def fixnum_min - -(2**62) - end - end - elsif PlatformGuard.implementation? :opal +# This is a bit hairy, but we need to be able to write specs that cover the +# boundary between Fixnum and Bignum for operations like Fixnum#<<. Since +# this boundary is implementation-dependent, we use these helpers to write +# specs based on the relationship between values rather than specific +# values. +if PlatformGuard.standard? or PlatformGuard.implementation? :topaz + if PlatformGuard.wordsize? 32 def fixnum_max - Integer::MAX + (2**30) - 1 end def fixnum_min - Integer::MIN + -(2**30) end - elsif PlatformGuard.implementation? :rubinius + elsif PlatformGuard.wordsize? 64 def fixnum_max - Fixnum::MAX + (2**62) - 1 end def fixnum_min - Fixnum::MIN - end - elsif PlatformGuard.implementation?(:jruby) || PlatformGuard.implementation?(:truffleruby) - def fixnum_max - 9223372036854775807 + -(2**62) end + end +elsif PlatformGuard.implementation? :opal + def fixnum_max + Integer::MAX + end - def fixnum_min - -9223372036854775808 - end - else - def fixnum_max - raise "unknown implementation for fixnum_max() helper" - end + def fixnum_min + Integer::MIN + end +elsif PlatformGuard.implementation? :rubinius + def fixnum_max + Fixnum::MAX + end - def fixnum_min - raise "unknown implementation for fixnum_min() helper" - end + def fixnum_min + Fixnum::MIN + end +elsif PlatformGuard.implementation?(:jruby) || PlatformGuard.implementation?(:truffleruby) + def fixnum_max + 9223372036854775807 + end + + def fixnum_min + -9223372036854775808 + end +else + def fixnum_max + raise "unknown implementation for fixnum_max() helper" + end + + def fixnum_min + raise "unknown implementation for fixnum_min() helper" end end diff --git a/spec/mspec/lib/mspec/helpers/ruby_exe.rb b/spec/mspec/lib/mspec/helpers/ruby_exe.rb index a025be6c81..7c3d6a36cf 100644 --- a/spec/mspec/lib/mspec/helpers/ruby_exe.rb +++ b/spec/mspec/lib/mspec/helpers/ruby_exe.rb @@ -1,4 +1,3 @@ -require 'mspec/utils/ruby_name' require 'mspec/guards/platform' require 'mspec/helpers/tmp' @@ -46,8 +45,8 @@ require 'mspec/helpers/tmp' # constructed as follows: # # 1. the value of ENV['RUBY_EXE'] -# 2. an explicit value based on RUBY_NAME -# 3. cwd/(RUBY_NAME + $(EXEEXT) || $(exeext) || '') +# 2. an explicit value based on RUBY_ENGINE +# 3. cwd/(RUBY_ENGINE + $(EXEEXT) || $(exeext) || '') # 4. $(bindir)/$(RUBY_INSTALL_NAME) # # The value will only be used if the file exists and is executable. @@ -64,8 +63,7 @@ require 'mspec/helpers/tmp' # 2. Running the specs while developing an alternative # Ruby implementation. This explicitly names the # executable in the development directory based on -# the value of RUBY_NAME, which is probably initialized -# from the value of RUBY_ENGINE. +# the value of RUBY_ENGINE. # 3. Running the specs within the source directory for # some implementation. (E.g. a local build directory.) # 4. Running the specs against some installed Ruby @@ -76,103 +74,101 @@ require 'mspec/helpers/tmp' # will be appended to RUBY_EXE so that the interpreter # is always called with those flags. -class Object - def ruby_exe_options(option) - case option - when :env - ENV['RUBY_EXE'] - when :engine - case RUBY_NAME - when 'rbx' - "bin/rbx" - when 'jruby' - "bin/jruby" - when 'maglev' - "maglev-ruby" - when 'topaz' - "topaz" - when 'ironruby' - "ir" - end - when :name - require 'rbconfig' - bin = RUBY_NAME + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '') - File.join(".", bin) - when :install_name - require 'rbconfig' - bin = RbConfig::CONFIG["RUBY_INSTALL_NAME"] || RbConfig::CONFIG["ruby_install_name"] - bin << (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '') - File.join(RbConfig::CONFIG['bindir'], bin) +def ruby_exe_options(option) + case option + when :env + ENV['RUBY_EXE'] + when :engine + case RUBY_ENGINE + when 'rbx' + "bin/rbx" + when 'jruby' + "bin/jruby" + when 'maglev' + "maglev-ruby" + when 'topaz' + "topaz" + when 'ironruby' + "ir" end + when :name + require 'rbconfig' + bin = RUBY_ENGINE + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '') + File.join(".", bin) + when :install_name + require 'rbconfig' + bin = RbConfig::CONFIG["RUBY_INSTALL_NAME"] || RbConfig::CONFIG["ruby_install_name"] + bin << (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '') + File.join(RbConfig::CONFIG['bindir'], bin) end +end - def resolve_ruby_exe - [:env, :engine, :name, :install_name].each do |option| - next unless exe = ruby_exe_options(option) +def resolve_ruby_exe + [:env, :engine, :name, :install_name].each do |option| + next unless exe = ruby_exe_options(option) - if File.file?(exe) and File.executable?(exe) - exe = File.expand_path(exe) - exe = exe.tr('/', '\\') if PlatformGuard.windows? - flags = ENV['RUBY_FLAGS'] - if flags and !flags.empty? - return exe + ' ' + flags - else - return exe - end + if File.file?(exe) and File.executable?(exe) + exe = File.expand_path(exe) + exe = exe.tr('/', '\\') if PlatformGuard.windows? + flags = ENV['RUBY_FLAGS'] + if flags and !flags.empty? + return exe + ' ' + flags + else + return exe end end - raise Exception, "Unable to find a suitable ruby executable." end + raise Exception, "Unable to find a suitable ruby executable." +end - def ruby_exe(code, opts = {}) - if opts[:dir] - raise "ruby_exe(..., dir: dir) is no longer supported, use Dir.chdir" - end - - env = opts[:env] || {} - saved_env = {} - env.each do |key, value| - key = key.to_s - saved_env[key] = ENV[key] if ENV.key? key - ENV[key] = value - end - - escape = opts.delete(:escape) - if code and !File.exist?(code) and escape != false - tmpfile = tmp("rubyexe.rb") - File.open(tmpfile, "w") { |f| f.write(code) } - code = tmpfile - end +def ruby_exe(code, opts = {}) + if opts[:dir] + raise "ruby_exe(..., dir: dir) is no longer supported, use Dir.chdir" + end - begin - platform_is_not :opal do - `#{ruby_cmd(code, opts)}` - end - 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 - File.delete tmpfile if tmpfile - end + env = opts[:env] || {} + saved_env = {} + env.each do |key, value| + key = key.to_s + saved_env[key] = ENV[key] if ENV.key? key + ENV[key] = value end - def ruby_cmd(code, opts = {}) - body = code + escape = opts.delete(:escape) + if code and !File.exist?(code) and escape != false + tmpfile = tmp("rubyexe.rb") + File.open(tmpfile, "w") { |f| f.write(code) } + code = tmpfile + end - if opts[:escape] - raise "escape: true is no longer supported in ruby_cmd, use ruby_exe or a fixture" + begin + platform_is_not :opal do + `#{ruby_cmd(code, opts)}` end - - if code and !File.exist?(code) - body = "-e #{code.inspect}" + 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 + File.delete tmpfile if tmpfile + end +end + +def ruby_cmd(code, opts = {}) + body = code - [RUBY_EXE, opts[:options], body, opts[:args]].compact.join(' ') + if opts[:escape] + raise "escape: true is no longer supported in ruby_cmd, use ruby_exe or a fixture" end - unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE - RUBY_EXE = resolve_ruby_exe + if code and !File.exist?(code) + body = "-e #{code.inspect}" end + + [RUBY_EXE, opts[:options], body, opts[:args]].compact.join(' ') +end + +unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE + RUBY_EXE = resolve_ruby_exe end diff --git a/spec/mspec/lib/mspec/helpers/tmp.rb b/spec/mspec/lib/mspec/helpers/tmp.rb index 742eb57fdc..4e1273dcfe 100644 --- a/spec/mspec/lib/mspec/helpers/tmp.rb +++ b/spec/mspec/lib/mspec/helpers/tmp.rb @@ -30,16 +30,14 @@ all specs are cleaning up temporary files: end end -class Object - def tmp(name, uniquify=true) - Dir.mkdir SPEC_TEMP_DIR unless Dir.exist? SPEC_TEMP_DIR - - if uniquify and !name.empty? - slash = name.rindex "/" - index = slash ? slash + 1 : 0 - name.insert index, "#{SPEC_TEMP_UNIQUIFIER.succ!}-" - end +def tmp(name, uniquify=true) + Dir.mkdir SPEC_TEMP_DIR unless Dir.exist? SPEC_TEMP_DIR - File.join SPEC_TEMP_DIR, name + if uniquify and !name.empty? + slash = name.rindex "/" + index = slash ? slash + 1 : 0 + name.insert index, "#{SPEC_TEMP_UNIQUIFIER.succ!}-" end + + File.join SPEC_TEMP_DIR, name end diff --git a/spec/mspec/lib/mspec/helpers/warning.rb b/spec/mspec/lib/mspec/helpers/warning.rb index 44d0e35dc5..9e093074e5 100644 --- a/spec/mspec/lib/mspec/helpers/warning.rb +++ b/spec/mspec/lib/mspec/helpers/warning.rb @@ -1,9 +1,7 @@ -class Object - def suppress_warning - verbose = $VERBOSE - $VERBOSE = nil - yield - ensure - $VERBOSE = verbose - end +def suppress_warning + verbose = $VERBOSE + $VERBOSE = nil + yield +ensure + $VERBOSE = verbose end diff --git a/spec/mspec/lib/mspec/runner/formatters/html.rb b/spec/mspec/lib/mspec/runner/formatters/html.rb index 060d2732f0..fd64cd0d20 100644 --- a/spec/mspec/lib/mspec/runner/formatters/html.rb +++ b/spec/mspec/lib/mspec/runner/formatters/html.rb @@ -15,7 +15,7 @@ class HtmlFormatter < DottedFormatter "http://www.w3.org/TR/html4/strict.dtd"> -Spec Output For #{RUBY_NAME} (#{RUBY_VERSION}) +Spec Output For #{RUBY_ENGINE} (#{RUBY_VERSION})