summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rwxr-xr-xspec/mspec/lib/mspec/commands/mspec.rb26
-rw-r--r--spec/mspec/lib/mspec/helpers/ruby_exe.rb14
-rw-r--r--spec/mspec/lib/mspec/matchers/base.rb12
-rw-r--r--spec/mspec/lib/mspec/matchers/be_an_instance_of.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/be_ancestor_of.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/be_close.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/be_computed_by.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/be_empty.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/be_false.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/be_kind_of.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/be_nan.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/be_nil.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/be_true.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/be_true_or_false.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/block_caller.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/complain.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/eql.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/equal.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/equal_element.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/have_class_variable.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/have_constant.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/have_instance_method.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/have_instance_variable.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/have_method.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/have_private_instance_method.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/have_private_method.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/have_protected_instance_method.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/have_public_instance_method.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/have_singleton_method.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/include.rb5
-rw-r--r--spec/mspec/lib/mspec/matchers/infinity.rb6
-rw-r--r--spec/mspec/lib/mspec/matchers/match_yaml.rb5
-rw-r--r--spec/mspec/lib/mspec/matchers/output.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/output_to_fd.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/raise_error.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/respond_to.rb4
-rw-r--r--spec/mspec/lib/mspec/matchers/signed_zero.rb6
-rw-r--r--spec/mspec/lib/mspec/mocks/mock.rb6
-rw-r--r--spec/mspec/lib/mspec/mocks/object.rb24
-rw-r--r--spec/mspec/lib/mspec/runner/evaluate.rb8
-rw-r--r--spec/mspec/lib/mspec/runner/mspec.rb21
-rw-r--r--spec/mspec/lib/mspec/runner/object.rb16
-rw-r--r--spec/mspec/lib/mspec/runner/shared.rb14
-rw-r--r--spec/mspec/lib/mspec/utils/options.rb4
-rw-r--r--spec/mspec/spec/commands/mspec_spec.rb6
-rw-r--r--spec/mspec/spec/expectations/should.rb1
-rw-r--r--spec/mspec/spec/fixtures/object_methods_spec.rb8
-rw-r--r--spec/mspec/spec/helpers/ruby_exe_spec.rb59
-rw-r--r--spec/mspec/spec/integration/object_methods_spec.rb18
-rw-r--r--spec/mspec/spec/matchers/output_to_fd_spec.rb24
-rw-r--r--spec/mspec/spec/mocks/mock_spec.rb6
-rw-r--r--spec/mspec/spec/runner/shared_spec.rb2
-rw-r--r--spec/mspec/tool/sync/sync-rubyspec.rb54
53 files changed, 259 insertions, 206 deletions
diff --git a/spec/mspec/lib/mspec/commands/mspec.rb b/spec/mspec/lib/mspec/commands/mspec.rb
index d3edb4d51e..cb1c0fbacb 100755
--- a/spec/mspec/lib/mspec/commands/mspec.rb
+++ b/spec/mspec/lib/mspec/commands/mspec.rb
@@ -114,6 +114,7 @@ class MSpecMain < MSpecScript
puts children.map { |child| child.gets }.uniq
formatter.start
+ last_files = {}
until @files.empty?
IO.select(children)[0].each { |io|
@@ -127,22 +128,33 @@ class MSpecMain < MSpecScript
while chunk = (io.read_nonblock(4096) rescue nil)
reply += chunk
end
- raise reply
+ reply.chomp!('.')
+ msg = "A child mspec-run process printed unexpected output on STDOUT"
+ if last_file = last_files[io]
+ msg += " while running #{last_file}"
+ end
+ abort "\n#{msg}: #{reply.inspect}"
+ end
+
+ unless @files.empty?
+ file = @files.shift
+ last_files[io] = file
+ io.puts file
end
- io.puts @files.shift unless @files.empty?
}
end
- ok = true
+ success = true
children.each { |child|
child.puts "QUIT"
- Process.wait(child.pid)
- ok &&= $?.success?
+ _pid, status = Process.wait2(child.pid)
+ success &&= status.success?
+ child.close
}
formatter.aggregate_results(output_files)
formatter.finish
- ok
+ success
end
def run
@@ -152,7 +164,7 @@ class MSpecMain < MSpecScript
argv.concat config[:flags]
argv.concat config[:loadpath]
argv.concat config[:requires]
- argv << "#{MSPEC_HOME}/bin/mspec-#{ config[:command] || "run" }"
+ argv << "#{MSPEC_HOME}/bin/mspec-#{config[:command] || 'run'}"
argv.concat config[:options]
if config[:multi]
diff --git a/spec/mspec/lib/mspec/helpers/ruby_exe.rb b/spec/mspec/lib/mspec/helpers/ruby_exe.rb
index 7c3d6a36cf..f74ed014ce 100644
--- a/spec/mspec/lib/mspec/helpers/ruby_exe.rb
+++ b/spec/mspec/lib/mspec/helpers/ruby_exe.rb
@@ -38,6 +38,14 @@ require 'mspec/helpers/tmp'
# If +nil+ is passed for the first argument, the command line
# will be built only from the options hash.
#
+# If no arguments are passed to ruby_exe, it returns an Array
+# containing the interpreter executable and the flags:
+#
+# spawn(*ruby_exe, "-e", "puts :hello")
+#
+# This avoids spawning an extra shell, and ensure the pid returned by spawn
+# corresponds to the ruby process and not the shell.
+#
# The RUBY_EXE constant is setup by mspec automatically
# and is used by ruby_exe and ruby_cmd. The mspec runner script
# will set ENV['RUBY_EXE'] to the name of the executable used
@@ -121,11 +129,15 @@ def resolve_ruby_exe
raise Exception, "Unable to find a suitable ruby executable."
end
-def ruby_exe(code, opts = {})
+def ruby_exe(code = :not_given, opts = {})
if opts[:dir]
raise "ruby_exe(..., dir: dir) is no longer supported, use Dir.chdir"
end
+ if code == :not_given
+ return RUBY_EXE.split(' ')
+ end
+
env = opts[:env] || {}
saved_env = {}
env.each do |key, value|
diff --git a/spec/mspec/lib/mspec/matchers/base.rb b/spec/mspec/lib/mspec/matchers/base.rb
index 30fb1f93dc..86b2fb4cec 100644
--- a/spec/mspec/lib/mspec/matchers/base.rb
+++ b/spec/mspec/lib/mspec/matchers/base.rb
@@ -1,3 +1,15 @@
+module MSpecMatchers
+end
+
+class MSpecEnv
+ include MSpecMatchers
+end
+
+# Expactations are sometimes used in a module body
+class Module
+ include MSpecMatchers
+end
+
class SpecPositiveOperatorMatcher
def initialize(actual)
@actual = actual
diff --git a/spec/mspec/lib/mspec/matchers/be_an_instance_of.rb b/spec/mspec/lib/mspec/matchers/be_an_instance_of.rb
index 6e31afcddd..fdf3736ac2 100644
--- a/spec/mspec/lib/mspec/matchers/be_an_instance_of.rb
+++ b/spec/mspec/lib/mspec/matchers/be_an_instance_of.rb
@@ -19,8 +19,8 @@ class BeAnInstanceOfMatcher
end
end
-class Object
- def be_an_instance_of(expected)
+module MSpecMatchers
+ private def be_an_instance_of(expected)
BeAnInstanceOfMatcher.new(expected)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/be_ancestor_of.rb b/spec/mspec/lib/mspec/matchers/be_ancestor_of.rb
index 792c64089a..05f72099e4 100644
--- a/spec/mspec/lib/mspec/matchers/be_ancestor_of.rb
+++ b/spec/mspec/lib/mspec/matchers/be_ancestor_of.rb
@@ -17,8 +17,8 @@ class BeAncestorOfMatcher
end
end
-class Object
- def be_ancestor_of(expected)
+module MSpecMatchers
+ private def be_ancestor_of(expected)
BeAncestorOfMatcher.new(expected)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/be_close.rb b/spec/mspec/lib/mspec/matchers/be_close.rb
index 5d79654099..2cf0fba41f 100644
--- a/spec/mspec/lib/mspec/matchers/be_close.rb
+++ b/spec/mspec/lib/mspec/matchers/be_close.rb
@@ -20,8 +20,8 @@ class BeCloseMatcher
end
end
-class Object
- def be_close(expected, tolerance)
+module MSpecMatchers
+ private def be_close(expected, tolerance)
BeCloseMatcher.new(expected, tolerance)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/be_computed_by.rb b/spec/mspec/lib/mspec/matchers/be_computed_by.rb
index c927eb7697..2e31bc93af 100644
--- a/spec/mspec/lib/mspec/matchers/be_computed_by.rb
+++ b/spec/mspec/lib/mspec/matchers/be_computed_by.rb
@@ -30,8 +30,8 @@ class BeComputedByMatcher
end
end
-class Object
- def be_computed_by(sym, *args)
+module MSpecMatchers
+ private def be_computed_by(sym, *args)
BeComputedByMatcher.new(sym, *args)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/be_empty.rb b/spec/mspec/lib/mspec/matchers/be_empty.rb
index 8a401b63fd..5abd5c9485 100644
--- a/spec/mspec/lib/mspec/matchers/be_empty.rb
+++ b/spec/mspec/lib/mspec/matchers/be_empty.rb
@@ -13,8 +13,8 @@ class BeEmptyMatcher
end
end
-class Object
- def be_empty
+module MSpecMatchers
+ private def be_empty
BeEmptyMatcher.new
end
end
diff --git a/spec/mspec/lib/mspec/matchers/be_false.rb b/spec/mspec/lib/mspec/matchers/be_false.rb
index 33e371dad0..9e9a2608e1 100644
--- a/spec/mspec/lib/mspec/matchers/be_false.rb
+++ b/spec/mspec/lib/mspec/matchers/be_false.rb
@@ -13,8 +13,8 @@ class BeFalseMatcher
end
end
-class Object
- def be_false
+module MSpecMatchers
+ private def be_false
BeFalseMatcher.new
end
end
diff --git a/spec/mspec/lib/mspec/matchers/be_kind_of.rb b/spec/mspec/lib/mspec/matchers/be_kind_of.rb
index a734f6159c..a69906f210 100644
--- a/spec/mspec/lib/mspec/matchers/be_kind_of.rb
+++ b/spec/mspec/lib/mspec/matchers/be_kind_of.rb
@@ -17,8 +17,8 @@ class BeKindOfMatcher
end
end
-class Object
- def be_kind_of(expected)
+module MSpecMatchers
+ private def be_kind_of(expected)
BeKindOfMatcher.new(expected)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/be_nan.rb b/spec/mspec/lib/mspec/matchers/be_nan.rb
index aa19391211..b279d8f1cf 100644
--- a/spec/mspec/lib/mspec/matchers/be_nan.rb
+++ b/spec/mspec/lib/mspec/matchers/be_nan.rb
@@ -13,8 +13,8 @@ class BeNaNMatcher
end
end
-class Object
- def be_nan
+module MSpecMatchers
+ private def be_nan
BeNaNMatcher.new
end
end
diff --git a/spec/mspec/lib/mspec/matchers/be_nil.rb b/spec/mspec/lib/mspec/matchers/be_nil.rb
index c107ae109c..049b1e3a53 100644
--- a/spec/mspec/lib/mspec/matchers/be_nil.rb
+++ b/spec/mspec/lib/mspec/matchers/be_nil.rb
@@ -13,8 +13,8 @@ class BeNilMatcher
end
end
-class Object
- def be_nil
+module MSpecMatchers
+ private def be_nil
BeNilMatcher.new
end
end
diff --git a/spec/mspec/lib/mspec/matchers/be_true.rb b/spec/mspec/lib/mspec/matchers/be_true.rb
index be107f45be..52f5013752 100644
--- a/spec/mspec/lib/mspec/matchers/be_true.rb
+++ b/spec/mspec/lib/mspec/matchers/be_true.rb
@@ -13,8 +13,8 @@ class BeTrueMatcher
end
end
-class Object
- def be_true
+module MSpecMatchers
+ private def be_true
BeTrueMatcher.new
end
end
diff --git a/spec/mspec/lib/mspec/matchers/be_true_or_false.rb b/spec/mspec/lib/mspec/matchers/be_true_or_false.rb
index b2262779ed..4294b08d1b 100644
--- a/spec/mspec/lib/mspec/matchers/be_true_or_false.rb
+++ b/spec/mspec/lib/mspec/matchers/be_true_or_false.rb
@@ -13,8 +13,8 @@ class BeTrueOrFalseMatcher
end
end
-class Object
- def be_true_or_false
+module MSpecMatchers
+ private def be_true_or_false
BeTrueOrFalseMatcher.new
end
end
diff --git a/spec/mspec/lib/mspec/matchers/block_caller.rb b/spec/mspec/lib/mspec/matchers/block_caller.rb
index 5451950712..017bce3cb7 100644
--- a/spec/mspec/lib/mspec/matchers/block_caller.rb
+++ b/spec/mspec/lib/mspec/matchers/block_caller.rb
@@ -28,8 +28,8 @@ class BlockingMatcher
end
end
-class Object
- def block_caller(timeout = 0.1)
+module MSpecMatchers
+ private def block_caller(timeout = 0.1)
BlockingMatcher.new
end
end
diff --git a/spec/mspec/lib/mspec/matchers/complain.rb b/spec/mspec/lib/mspec/matchers/complain.rb
index 1313215156..71b6a77680 100644
--- a/spec/mspec/lib/mspec/matchers/complain.rb
+++ b/spec/mspec/lib/mspec/matchers/complain.rb
@@ -49,8 +49,8 @@ class ComplainMatcher
end
end
-class Object
- def complain(complaint=nil)
+module MSpecMatchers
+ private def complain(complaint=nil)
ComplainMatcher.new(complaint)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/eql.rb b/spec/mspec/lib/mspec/matchers/eql.rb
index 82117d862c..a855789550 100644
--- a/spec/mspec/lib/mspec/matchers/eql.rb
+++ b/spec/mspec/lib/mspec/matchers/eql.rb
@@ -19,8 +19,8 @@ class EqlMatcher
end
end
-class Object
- def eql(expected)
+module MSpecMatchers
+ private def eql(expected)
EqlMatcher.new(expected)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/equal.rb b/spec/mspec/lib/mspec/matchers/equal.rb
index ee6431fd4f..5dc77d27ea 100644
--- a/spec/mspec/lib/mspec/matchers/equal.rb
+++ b/spec/mspec/lib/mspec/matchers/equal.rb
@@ -19,8 +19,8 @@ class EqualMatcher
end
end
-class Object
- def equal(expected)
+module MSpecMatchers
+ private def equal(expected)
EqualMatcher.new(expected)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/equal_element.rb b/spec/mspec/lib/mspec/matchers/equal_element.rb
index 428bbfc8b6..1e9dfbcca1 100644
--- a/spec/mspec/lib/mspec/matchers/equal_element.rb
+++ b/spec/mspec/lib/mspec/matchers/equal_element.rb
@@ -71,8 +71,8 @@ class EqualElementMatcher
end
end
-class Object
- def equal_element(*args)
+module MSpecMatchers
+ private def equal_element(*args)
EqualElementMatcher.new(*args)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/have_class_variable.rb b/spec/mspec/lib/mspec/matchers/have_class_variable.rb
index 2d1903e1a8..dd43ced621 100644
--- a/spec/mspec/lib/mspec/matchers/have_class_variable.rb
+++ b/spec/mspec/lib/mspec/matchers/have_class_variable.rb
@@ -5,8 +5,8 @@ class HaveClassVariableMatcher < VariableMatcher
self.description = 'class variable'
end
-class Object
- def have_class_variable(variable)
+module MSpecMatchers
+ private def have_class_variable(variable)
HaveClassVariableMatcher.new(variable)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/have_constant.rb b/spec/mspec/lib/mspec/matchers/have_constant.rb
index df95219e53..6ec7c75b85 100644
--- a/spec/mspec/lib/mspec/matchers/have_constant.rb
+++ b/spec/mspec/lib/mspec/matchers/have_constant.rb
@@ -5,8 +5,8 @@ class HaveConstantMatcher < VariableMatcher
self.description = 'constant'
end
-class Object
- def have_constant(variable)
+module MSpecMatchers
+ private def have_constant(variable)
HaveConstantMatcher.new(variable)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/have_instance_method.rb b/spec/mspec/lib/mspec/matchers/have_instance_method.rb
index 00dcbd39eb..636aaf3e47 100644
--- a/spec/mspec/lib/mspec/matchers/have_instance_method.rb
+++ b/spec/mspec/lib/mspec/matchers/have_instance_method.rb
@@ -17,8 +17,8 @@ class HaveInstanceMethodMatcher < MethodMatcher
end
end
-class Object
- def have_instance_method(method, include_super=true)
+module MSpecMatchers
+ private def have_instance_method(method, include_super=true)
HaveInstanceMethodMatcher.new method, include_super
end
end
diff --git a/spec/mspec/lib/mspec/matchers/have_instance_variable.rb b/spec/mspec/lib/mspec/matchers/have_instance_variable.rb
index f83c803a26..de51b3209d 100644
--- a/spec/mspec/lib/mspec/matchers/have_instance_variable.rb
+++ b/spec/mspec/lib/mspec/matchers/have_instance_variable.rb
@@ -5,8 +5,8 @@ class HaveInstanceVariableMatcher < VariableMatcher
self.description = 'instance variable'
end
-class Object
- def have_instance_variable(variable)
+module MSpecMatchers
+ private def have_instance_variable(variable)
HaveInstanceVariableMatcher.new(variable)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/have_method.rb b/spec/mspec/lib/mspec/matchers/have_method.rb
index 2fc3e66f69..35dae03af0 100644
--- a/spec/mspec/lib/mspec/matchers/have_method.rb
+++ b/spec/mspec/lib/mspec/matchers/have_method.rb
@@ -17,8 +17,8 @@ class HaveMethodMatcher < MethodMatcher
end
end
-class Object
- def have_method(method, include_super=true)
+module MSpecMatchers
+ private def have_method(method, include_super=true)
HaveMethodMatcher.new method, include_super
end
end
diff --git a/spec/mspec/lib/mspec/matchers/have_private_instance_method.rb b/spec/mspec/lib/mspec/matchers/have_private_instance_method.rb
index 87d9767a69..4eb7133055 100644
--- a/spec/mspec/lib/mspec/matchers/have_private_instance_method.rb
+++ b/spec/mspec/lib/mspec/matchers/have_private_instance_method.rb
@@ -17,8 +17,8 @@ class HavePrivateInstanceMethodMatcher < MethodMatcher
end
end
-class Object
- def have_private_instance_method(method, include_super=true)
+module MSpecMatchers
+ private def have_private_instance_method(method, include_super=true)
HavePrivateInstanceMethodMatcher.new method, include_super
end
end
diff --git a/spec/mspec/lib/mspec/matchers/have_private_method.rb b/spec/mspec/lib/mspec/matchers/have_private_method.rb
index d99d4ccb7f..3433d982cc 100644
--- a/spec/mspec/lib/mspec/matchers/have_private_method.rb
+++ b/spec/mspec/lib/mspec/matchers/have_private_method.rb
@@ -17,8 +17,8 @@ class HavePrivateMethodMatcher < MethodMatcher
end
end
-class Object
- def have_private_method(method, include_super=true)
+module MSpecMatchers
+ private def have_private_method(method, include_super=true)
HavePrivateMethodMatcher.new method, include_super
end
end
diff --git a/spec/mspec/lib/mspec/matchers/have_protected_instance_method.rb b/spec/mspec/lib/mspec/matchers/have_protected_instance_method.rb
index 92f38e9acb..641d4d0dc2 100644
--- a/spec/mspec/lib/mspec/matchers/have_protected_instance_method.rb
+++ b/spec/mspec/lib/mspec/matchers/have_protected_instance_method.rb
@@ -17,8 +17,8 @@ class HaveProtectedInstanceMethodMatcher < MethodMatcher
end
end
-class Object
- def have_protected_instance_method(method, include_super=true)
+module MSpecMatchers
+ private def have_protected_instance_method(method, include_super=true)
HaveProtectedInstanceMethodMatcher.new method, include_super
end
end
diff --git a/spec/mspec/lib/mspec/matchers/have_public_instance_method.rb b/spec/mspec/lib/mspec/matchers/have_public_instance_method.rb
index 035547d28f..501c0a418e 100644
--- a/spec/mspec/lib/mspec/matchers/have_public_instance_method.rb
+++ b/spec/mspec/lib/mspec/matchers/have_public_instance_method.rb
@@ -17,8 +17,8 @@ class HavePublicInstanceMethodMatcher < MethodMatcher
end
end
-class Object
- def have_public_instance_method(method, include_super=true)
+module MSpecMatchers
+ private def have_public_instance_method(method, include_super=true)
HavePublicInstanceMethodMatcher.new method, include_super
end
end
diff --git a/spec/mspec/lib/mspec/matchers/have_singleton_method.rb b/spec/mspec/lib/mspec/matchers/have_singleton_method.rb
index 5f3acb84e2..95d78709ff 100644
--- a/spec/mspec/lib/mspec/matchers/have_singleton_method.rb
+++ b/spec/mspec/lib/mspec/matchers/have_singleton_method.rb
@@ -17,8 +17,8 @@ class HaveSingletonMethodMatcher < MethodMatcher
end
end
-class Object
- def have_singleton_method(method, include_super=true)
+module MSpecMatchers
+ private def have_singleton_method(method, include_super=true)
HaveSingletonMethodMatcher.new method, include_super
end
end
diff --git a/spec/mspec/lib/mspec/matchers/include.rb b/spec/mspec/lib/mspec/matchers/include.rb
index b4e54158d1..0b7eaf3ce2 100644
--- a/spec/mspec/lib/mspec/matchers/include.rb
+++ b/spec/mspec/lib/mspec/matchers/include.rb
@@ -24,9 +24,8 @@ class IncludeMatcher
end
# Cannot override #include at the toplevel in MRI
-module MSpec
- def include(*expected)
+module MSpecMatchers
+ private def include(*expected)
IncludeMatcher.new(*expected)
end
- module_function :include
end
diff --git a/spec/mspec/lib/mspec/matchers/infinity.rb b/spec/mspec/lib/mspec/matchers/infinity.rb
index 0949fd47eb..8bfa6dbd10 100644
--- a/spec/mspec/lib/mspec/matchers/infinity.rb
+++ b/spec/mspec/lib/mspec/matchers/infinity.rb
@@ -17,12 +17,12 @@ class InfinityMatcher
end
end
-class Object
- def be_positive_infinity
+module MSpecMatchers
+ private def be_positive_infinity
InfinityMatcher.new(1)
end
- def be_negative_infinity
+ private def be_negative_infinity
InfinityMatcher.new(-1)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/match_yaml.rb b/spec/mspec/lib/mspec/matchers/match_yaml.rb
index 542dece2b4..920d85a14f 100644
--- a/spec/mspec/lib/mspec/matchers/match_yaml.rb
+++ b/spec/mspec/lib/mspec/matchers/match_yaml.rb
@@ -39,9 +39,8 @@ class MatchYAMLMatcher
end
end
-class Object
- def match_yaml(expected)
+module MSpecMatchers
+ private def match_yaml(expected)
MatchYAMLMatcher.new(expected)
end
end
-
diff --git a/spec/mspec/lib/mspec/matchers/output.rb b/spec/mspec/lib/mspec/matchers/output.rb
index 551e7506cf..b89b6ca0f6 100644
--- a/spec/mspec/lib/mspec/matchers/output.rb
+++ b/spec/mspec/lib/mspec/matchers/output.rb
@@ -60,8 +60,8 @@ class OutputMatcher
end
end
-class Object
- def output(stdout=nil, stderr=nil)
+module MSpecMatchers
+ private def output(stdout=nil, stderr=nil)
OutputMatcher.new(stdout, stderr)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/output_to_fd.rb b/spec/mspec/lib/mspec/matchers/output_to_fd.rb
index 5daaf5545c..f4d7b4ea1f 100644
--- a/spec/mspec/lib/mspec/matchers/output_to_fd.rb
+++ b/spec/mspec/lib/mspec/matchers/output_to_fd.rb
@@ -64,8 +64,8 @@ class OutputToFDMatcher
end
end
-class Object
- def output_to_fd(what, where = STDOUT)
+module MSpecMatchers
+ private def output_to_fd(what, where = STDOUT)
OutputToFDMatcher.new what, where
end
end
diff --git a/spec/mspec/lib/mspec/matchers/raise_error.rb b/spec/mspec/lib/mspec/matchers/raise_error.rb
index a5d6e01ec9..d128ca03ea 100644
--- a/spec/mspec/lib/mspec/matchers/raise_error.rb
+++ b/spec/mspec/lib/mspec/matchers/raise_error.rb
@@ -72,8 +72,8 @@ class RaiseErrorMatcher
end
end
-class Object
- def raise_error(exception=Exception, message=nil, &block)
+module MSpecMatchers
+ private def raise_error(exception=Exception, message=nil, &block)
RaiseErrorMatcher.new(exception, message, &block)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/respond_to.rb b/spec/mspec/lib/mspec/matchers/respond_to.rb
index 2aa3ab14d1..6b35ae2d3c 100644
--- a/spec/mspec/lib/mspec/matchers/respond_to.rb
+++ b/spec/mspec/lib/mspec/matchers/respond_to.rb
@@ -17,8 +17,8 @@ class RespondToMatcher
end
end
-class Object
- def respond_to(expected)
+module MSpecMatchers
+ private def respond_to(expected)
RespondToMatcher.new(expected)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/signed_zero.rb b/spec/mspec/lib/mspec/matchers/signed_zero.rb
index 3fd1472fc8..2ff90f4994 100644
--- a/spec/mspec/lib/mspec/matchers/signed_zero.rb
+++ b/spec/mspec/lib/mspec/matchers/signed_zero.rb
@@ -17,12 +17,12 @@ class SignedZeroMatcher
end
end
-class Object
- def be_positive_zero
+module MSpecMatchers
+ private def be_positive_zero
SignedZeroMatcher.new(1)
end
- def be_negative_zero
+ private def be_negative_zero
SignedZeroMatcher.new(-1)
end
end
diff --git a/spec/mspec/lib/mspec/mocks/mock.rb b/spec/mspec/lib/mspec/mocks/mock.rb
index 1557f2008e..9fc72b5631 100644
--- a/spec/mspec/lib/mspec/mocks/mock.rb
+++ b/spec/mspec/lib/mspec/mocks/mock.rb
@@ -1,9 +1,5 @@
require 'mspec/expectations/expectations'
-class Object
- alias_method :__mspec_object_id__, :object_id
-end
-
module Mock
def self.reset
@mocks = @stubs = @objects = nil
@@ -22,7 +18,7 @@ module Mock
end
def self.replaced_name(obj, sym)
- :"__mspec_#{obj.__mspec_object_id__}_#{sym}__"
+ :"__mspec_#{obj.__id__}_#{sym}__"
end
def self.replaced_key(obj, sym)
diff --git a/spec/mspec/lib/mspec/mocks/object.rb b/spec/mspec/lib/mspec/mocks/object.rb
index f4652a4671..19a50ac4e1 100644
--- a/spec/mspec/lib/mspec/mocks/object.rb
+++ b/spec/mspec/lib/mspec/mocks/object.rb
@@ -1,10 +1,6 @@
require 'mspec/mocks/proxy'
class Object
- def stub!(sym)
- Mock.install_method self, sym, :stub
- end
-
def should_receive(sym)
Mock.install_method self, sym
end
@@ -14,15 +10,19 @@ class Object
proxy.exactly(0).times
end
- def mock(name, options={})
- MockObject.new name, options
+ def stub!(sym)
+ Mock.install_method self, sym, :stub
end
+end
- def mock_int(val)
- MockIntObject.new(val)
- end
+def mock(name, options={})
+ MockObject.new name, options
+end
- def mock_numeric(name, options={})
- NumericMockObject.new name, options
- end
+def mock_int(val)
+ MockIntObject.new(val)
+end
+
+def mock_numeric(name, options={})
+ NumericMockObject.new name, options
end
diff --git a/spec/mspec/lib/mspec/runner/evaluate.rb b/spec/mspec/lib/mspec/runner/evaluate.rb
index fded84421f..ecf7460a90 100644
--- a/spec/mspec/lib/mspec/runner/evaluate.rb
+++ b/spec/mspec/lib/mspec/runner/evaluate.rb
@@ -1,4 +1,6 @@
class SpecEvaluate
+ include MSpecMatchers
+
def self.desc=(desc)
@desc = desc
end
@@ -47,8 +49,6 @@ class SpecEvaluate
end
end
-class Object
- def evaluate(str, desc=nil, &block)
- SpecEvaluate.new(str, desc).define(&block)
- end
+def evaluate(str, desc=nil, &block)
+ SpecEvaluate.new(str, desc).define(&block)
end
diff --git a/spec/mspec/lib/mspec/runner/mspec.rb b/spec/mspec/lib/mspec/runner/mspec.rb
index 0ff0de36ca..8f9c7a602f 100644
--- a/spec/mspec/lib/mspec/runner/mspec.rb
+++ b/spec/mspec/lib/mspec/runner/mspec.rb
@@ -2,6 +2,10 @@ require 'mspec/runner/context'
require 'mspec/runner/exception'
require 'mspec/runner/tag'
+class MSpecEnv
+ include MSpec
+end
+
module MSpec
@exit = nil
@@ -53,11 +57,19 @@ module MSpec
if ENV["MSPEC_MULTI"]
STDOUT.print "."
STDOUT.flush
- while (file = STDIN.gets.chomp) != "QUIT"
+ while file = STDIN.gets and file = file.chomp
+ return if file == "QUIT"
yield file
- STDOUT.print "."
- STDOUT.flush
+ begin
+ STDOUT.print "."
+ STDOUT.flush
+ rescue Errno::EPIPE
+ # The parent died
+ exit 1
+ end
end
+ # The parent closed the connection without QUIT
+ abort "the parent did not send QUIT"
else
return unless files = retrieve(:files)
shuffle files if randomize?
@@ -76,8 +88,7 @@ module MSpec
end
def self.setup_env
- @env = Object.new
- @env.extend MSpec
+ @env = MSpecEnv.new
end
def self.actions(action, *args)
diff --git a/spec/mspec/lib/mspec/runner/object.rb b/spec/mspec/lib/mspec/runner/object.rb
index 018e356149..2ea8197165 100644
--- a/spec/mspec/lib/mspec/runner/object.rb
+++ b/spec/mspec/lib/mspec/runner/object.rb
@@ -1,28 +1,26 @@
class Object
- def before(at=:each, &block)
+ private def before(at=:each, &block)
MSpec.current.before at, &block
end
- def after(at=:each, &block)
+ private def after(at=:each, &block)
MSpec.current.after at, &block
end
- def describe(mod, msg=nil, options=nil, &block)
+ private def describe(mod, msg=nil, options=nil, &block)
MSpec.describe mod, msg, &block
end
- def it(msg, &block)
+ private def it(msg, &block)
MSpec.current.it msg, &block
end
- def it_should_behave_like(desc)
+ private def it_should_behave_like(desc)
MSpec.current.it_should_behave_like desc
end
- # For ReadRuby compatiability
- def doc(*a)
- end
-
alias_method :context, :describe
+ private :context
alias_method :specify, :it
+ private :specify
end
diff --git a/spec/mspec/lib/mspec/runner/shared.rb b/spec/mspec/lib/mspec/runner/shared.rb
index 336e35f6ac..b606de473b 100644
--- a/spec/mspec/lib/mspec/runner/shared.rb
+++ b/spec/mspec/lib/mspec/runner/shared.rb
@@ -1,12 +1,10 @@
require 'mspec/runner/mspec'
-class Object
- def it_behaves_like(desc, meth, obj=nil)
- send :before, :all do
- @method = meth
- @object = obj
- end
-
- send :it_should_behave_like, desc.to_s
+def it_behaves_like(desc, meth, obj=nil)
+ send :before, :all do
+ @method = meth
+ @object = obj
end
+
+ send :it_should_behave_like, desc.to_s
end
diff --git a/spec/mspec/lib/mspec/utils/options.rb b/spec/mspec/lib/mspec/utils/options.rb
index f6e5304062..9f8dd01dbf 100644
--- a/spec/mspec/lib/mspec/utils/options.rb
+++ b/spec/mspec/lib/mspec/utils/options.rb
@@ -396,7 +396,7 @@ class MSpecOptions
end
def obj.load
file = MSpec.retrieve :file
- print "\n#{file.ljust(@width)}"
+ STDERR.print "\n#{file.ljust(@width)}"
end
MSpec.register :start, obj
MSpec.register :load, obj
@@ -407,7 +407,7 @@ class MSpecOptions
obj = Object.new
obj.instance_variable_set :@marker, o
def obj.load
- print @marker
+ STDERR.print @marker
end
MSpec.register :load, obj
end
diff --git a/spec/mspec/spec/commands/mspec_spec.rb b/spec/mspec/spec/commands/mspec_spec.rb
index 5d2134a054..b01af6b41b 100644
--- a/spec/mspec/spec/commands/mspec_spec.rb
+++ b/spec/mspec/spec/commands/mspec_spec.rb
@@ -60,13 +60,13 @@ describe MSpecMain, "#run" do
end
it "uses exec to invoke the runner script" do
- @script.should_receive(:exec).with("ruby", "#{MSPEC_HOME}/bin/mspec-run")
+ @script.should_receive(:exec).with("ruby", "#{MSPEC_HOME}/bin/mspec-run", close_others: false)
@script.options []
@script.run
end
it "shows the command line on stderr" do
- @script.should_receive(:exec).with("ruby", "#{MSPEC_HOME}/bin/mspec-run")
+ @script.should_receive(:exec).with("ruby", "#{MSPEC_HOME}/bin/mspec-run", close_others: false)
@script.options []
@script.run
$stderr.to_s.should == "$ ruby #{Dir.pwd}/bin/mspec-run\n"
@@ -74,7 +74,7 @@ describe MSpecMain, "#run" do
it "adds config[:launch] to the exec options" do
@script.should_receive(:exec).with("ruby",
- "-Xlaunch.option", "#{MSPEC_HOME}/bin/mspec-run")
+ "-Xlaunch.option", "#{MSPEC_HOME}/bin/mspec-run", close_others: false)
@config[:launch] << "-Xlaunch.option"
@script.options []
@script.run
diff --git a/spec/mspec/spec/expectations/should.rb b/spec/mspec/spec/expectations/should.rb
index 8404ff044e..24b1cf2bf8 100644
--- a/spec/mspec/spec/expectations/should.rb
+++ b/spec/mspec/spec/expectations/should.rb
@@ -33,6 +33,7 @@ MSpec.register :finish, monitor
at_exit { MSpec.actions :finish }
MSpec.actions :start
+MSpec.setup_env
# Specs
describe "MSpec expectation method #should" do
diff --git a/spec/mspec/spec/fixtures/object_methods_spec.rb b/spec/mspec/spec/fixtures/object_methods_spec.rb
new file mode 100644
index 0000000000..9b7c1523e5
--- /dev/null
+++ b/spec/mspec/spec/fixtures/object_methods_spec.rb
@@ -0,0 +1,8 @@
+unless defined?(RSpec)
+ describe "Object" do
+ it ".public_instance_methods(false) is empty" do
+ Object.public_instance_methods(false).sort.should ==
+ [:should, :should_not, :should_not_receive, :should_receive, :stub!]
+ end
+ end
+end
diff --git a/spec/mspec/spec/helpers/ruby_exe_spec.rb b/spec/mspec/spec/helpers/ruby_exe_spec.rb
index 474ad7b51a..8036043578 100644
--- a/spec/mspec/spec/helpers/ruby_exe_spec.rb
+++ b/spec/mspec/spec/helpers/ruby_exe_spec.rb
@@ -11,24 +11,13 @@ class RubyExeSpecs
end
describe "#ruby_exe_options" do
- before :all do
- @verbose = $VERBOSE
- $VERBOSE = nil
-
- @ruby_engine = Object.const_get :RUBY_ENGINE
+ before :each do
@ruby_exe_env = ENV['RUBY_EXE']
-
@script = RubyExeSpecs.new
end
- after :all do
- Object.const_set :RUBY_ENGINE, @ruby_engine
+ after :each do
ENV['RUBY_EXE'] = @ruby_exe_env
- $VERBOSE = @verbose
- end
-
- before :each do
- @script = RubyExeSpecs.new
end
it "returns ENV['RUBY_EXE'] when passed :env" do
@@ -37,27 +26,27 @@ describe "#ruby_exe_options" do
end
it "returns 'bin/jruby' when passed :engine and RUBY_ENGINE is 'jruby'" do
- Object.const_set :RUBY_ENGINE, 'jruby'
+ stub_const "RUBY_ENGINE", 'jruby'
@script.ruby_exe_options(:engine).should == 'bin/jruby'
end
it "returns 'bin/rbx' when passed :engine, RUBY_ENGINE is 'rbx'" do
- Object.const_set :RUBY_ENGINE, 'rbx'
+ stub_const "RUBY_ENGINE", 'rbx'
@script.ruby_exe_options(:engine).should == 'bin/rbx'
end
it "returns 'ir' when passed :engine and RUBY_ENGINE is 'ironruby'" do
- Object.const_set :RUBY_ENGINE, 'ironruby'
+ stub_const "RUBY_ENGINE", 'ironruby'
@script.ruby_exe_options(:engine).should == 'ir'
end
it "returns 'maglev-ruby' when passed :engine and RUBY_ENGINE is 'maglev'" do
- Object.const_set :RUBY_ENGINE, 'maglev'
+ stub_const "RUBY_ENGINE", 'maglev'
@script.ruby_exe_options(:engine).should == 'maglev-ruby'
end
it "returns 'topaz' when passed :engine and RUBY_ENGINE is 'topaz'" do
- Object.const_set :RUBY_ENGINE, 'topaz'
+ stub_const "RUBY_ENGINE", 'topaz'
@script.ruby_exe_options(:engine).should == 'topaz'
end
@@ -75,21 +64,11 @@ describe "#ruby_exe_options" do
end
describe "#resolve_ruby_exe" do
- before :all do
- @verbose = $VERBOSE
- $VERBOSE = nil
-
- @name = "ruby_spec_exe"
- end
-
before :each do
+ @name = "ruby_spec_exe"
@script = RubyExeSpecs.new
end
- after :all do
- $VERBOSE = @verbose
- end
-
it "returns the value returned by #ruby_exe_options if it exists and is executable" do
@script.should_receive(:ruby_exe_options).and_return(@name)
File.should_receive(:file?).with(@name).and_return(true)
@@ -126,12 +105,8 @@ describe "#resolve_ruby_exe" do
end
describe Object, "#ruby_cmd" do
- before :all do
- @verbose = $VERBOSE
- $VERBOSE = nil
-
- @ruby_exe = Object.const_get :RUBY_EXE
- Object.const_set :RUBY_EXE, 'ruby_spec_exe -w -Q'
+ before :each do
+ stub_const 'RUBY_EXE', 'ruby_spec_exe -w -Q'
@file = "some/ruby/file.rb"
@code = %(some "real" 'ruby' code)
@@ -139,11 +114,6 @@ describe Object, "#ruby_cmd" do
@script = RubyExeSpecs.new
end
- after :all do
- Object.const_set :RUBY_EXE, @ruby_exe
- $VERBOSE = @verbose
- end
-
it "returns a command that runs the given file if it is a file that exists" do
File.should_receive(:exist?).with(@file).and_return(true)
@script.ruby_cmd(@file).should == "ruby_spec_exe -w -Q some/ruby/file.rb"
@@ -168,12 +138,15 @@ describe Object, "#ruby_cmd" do
end
describe Object, "#ruby_exe" do
- before :all do
+ before :each do
+ stub_const 'RUBY_EXE', 'ruby_spec_exe -w -Q'
+
@script = RubyExeSpecs.new
+ @script.stub(:`)
end
- before :each do
- @script.stub(:`)
+ it "returns an Array containing the interpreter executable and flags when given no arguments" do
+ @script.ruby_exe.should == ['ruby_spec_exe', '-w', '-Q']
end
it "executes (using `) the result of calling #ruby_cmd with the given arguments" do
diff --git a/spec/mspec/spec/integration/object_methods_spec.rb b/spec/mspec/spec/integration/object_methods_spec.rb
new file mode 100644
index 0000000000..3be704beb6
--- /dev/null
+++ b/spec/mspec/spec/integration/object_methods_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+expected_output = <<EOS
+RUBY_DESCRIPTION
+.
+
+Finished in D.DDDDDD seconds
+
+1 file, 1 example, 1 expectation, 0 failures, 0 errors, 0 tagged
+EOS
+
+describe "MSpec" do
+ it "does not define public methods on Object" do
+ out, ret = run_mspec("run", "spec/fixtures/object_methods_spec.rb")
+ out.should == expected_output
+ ret.success?.should == true
+ end
+end
diff --git a/spec/mspec/spec/matchers/output_to_fd_spec.rb b/spec/mspec/spec/matchers/output_to_fd_spec.rb
index d35da58829..e584c4e003 100644
--- a/spec/mspec/spec/matchers/output_to_fd_spec.rb
+++ b/spec/mspec/spec/matchers/output_to_fd_spec.rb
@@ -5,38 +5,40 @@ require 'mspec/matchers'
describe OutputToFDMatcher do
# Figure out how in the hell to achieve this
it "matches when running the block produces the expected output to the given FD" do
- output_to_fd("Hi\n", STDERR).matches?(lambda { $stderr.print "Hi\n" }).should == true
+ OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda { $stderr.print "Hi\n" }).should == true
end
it "does not match if running the block does not produce the expected output to the FD" do
- output_to_fd("Hi\n", STDERR).matches?(lambda { $stderr.puts("Hello\n") }).should == false
+ OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda { $stderr.puts("Hello\n") }).should == false
end
it "propagate the exception if one is thrown while matching" do
exc = RuntimeError.new("propagates")
lambda {
- output_to_fd("Hi\n", STDERR).matches?(lambda {
+ OutputToFDMatcher.new("Hi\n", STDERR).matches?(lambda {
raise exc
}).should == false
}.should raise_error(exc)
end
it "defaults to matching against STDOUT" do
- output_to_fd("Hi\n").matches?(lambda { $stdout.print "Hi\n" }).should == true
+ object = Object.new
+ object.extend MSpecMatchers
+ object.send(:output_to_fd, "Hi\n").matches?(lambda { $stdout.print "Hi\n" }).should == true
end
it "accepts any IO instance" do
io = IO.new STDOUT.fileno
- output_to_fd("Hi\n", io).matches?(lambda { io.print "Hi\n" }).should == true
+ OutputToFDMatcher.new("Hi\n", io).matches?(lambda { io.print "Hi\n" }).should == true
end
it "allows matching with a Regexp" do
s = "Hi there\n"
- output_to_fd(/Hi/, STDERR).matches?(lambda { $stderr.print s }).should == true
- output_to_fd(/Hi?/, STDERR).matches?(lambda { $stderr.print s }).should == true
- output_to_fd(/[hH]i?/, STDERR).matches?(lambda { $stderr.print s }).should == true
- output_to_fd(/.*/, STDERR).matches?(lambda { $stderr.print s }).should == true
- output_to_fd(/H.*?here/, STDERR).matches?(lambda { $stderr.print s }).should == true
- output_to_fd(/Ahoy/, STDERR).matches?(lambda { $stderr.print s }).should == false
+ OutputToFDMatcher.new(/Hi/, STDERR).matches?(lambda { $stderr.print s }).should == true
+ OutputToFDMatcher.new(/Hi?/, STDERR).matches?(lambda { $stderr.print s }).should == true
+ OutputToFDMatcher.new(/[hH]i?/, STDERR).matches?(lambda { $stderr.print s }).should == true
+ OutputToFDMatcher.new(/.*/, STDERR).matches?(lambda { $stderr.print s }).should == true
+ OutputToFDMatcher.new(/H.*?here/, STDERR).matches?(lambda { $stderr.print s }).should == true
+ OutputToFDMatcher.new(/Ahoy/, STDERR).matches?(lambda { $stderr.print s }).should == false
end
end
diff --git a/spec/mspec/spec/mocks/mock_spec.rb b/spec/mspec/spec/mocks/mock_spec.rb
index 1a7fb2d567..d996b5285c 100644
--- a/spec/mspec/spec/mocks/mock_spec.rb
+++ b/spec/mspec/spec/mocks/mock_spec.rb
@@ -22,16 +22,14 @@ end
describe Mock, ".replaced_name" do
it "returns the name for a method that is being replaced by a mock method" do
m = double('a fake id')
- m.stub(:__mspec_object_id__).and_return(42)
- Mock.replaced_name(m, :method_call).should == :__mspec_42_method_call__
+ Mock.replaced_name(m, :method_call).should == :"__mspec_#{m.object_id}_method_call__"
end
end
describe Mock, ".replaced_key" do
it "returns a key used internally by Mock" do
m = double('a fake id')
- m.stub(:__mspec_object_id__).and_return(42)
- Mock.replaced_key(m, :method_call).should == [:__mspec_42_method_call__, :method_call]
+ Mock.replaced_key(m, :method_call).should == [:"__mspec_#{m.object_id}_method_call__", :method_call]
end
end
diff --git a/spec/mspec/spec/runner/shared_spec.rb b/spec/mspec/spec/runner/shared_spec.rb
index 791588fdca..b91800b7db 100644
--- a/spec/mspec/spec/runner/shared_spec.rb
+++ b/spec/mspec/spec/runner/shared_spec.rb
@@ -11,6 +11,7 @@ describe Object, "#it_behaves_like" do
@state = ContextState.new "Top level"
@state.instance_variable_set :@parsed, true
+ @state.singleton_class.send(:public, :it_behaves_like)
@shared = ContextState.new :shared_spec, :shared => true
MSpec.stub(:retrieve_shared).and_return(@shared)
@@ -51,6 +52,7 @@ describe Object, "#it_behaves_like" do
@state2 = ContextState.new "Second top level"
@state2.instance_variable_set :@parsed, true
+ @state2.singleton_class.send(:public, :it_behaves_like)
end
it "ensures the shared spec state is distinct" do
diff --git a/spec/mspec/tool/sync/sync-rubyspec.rb b/spec/mspec/tool/sync/sync-rubyspec.rb
index be5082e240..4073608ce3 100644
--- a/spec/mspec/tool/sync/sync-rubyspec.rb
+++ b/spec/mspec/tool/sync/sync-rubyspec.rb
@@ -18,10 +18,17 @@ IMPLS = {
},
}
+MSPEC = ARGV.delete('--mspec')
+
# Assuming the rubyspec repo is a sibling of the mspec repo
RUBYSPEC_REPO = File.expand_path("../../../../rubyspec", __FILE__)
raise RUBYSPEC_REPO unless Dir.exist?(RUBYSPEC_REPO)
+MSPEC_REPO = File.expand_path("../../../../mspec", __FILE__)
+raise MSPEC_REPO if MSPEC && !Dir.exist?(MSPEC_REPO)
+
+SOURCE_REPO = MSPEC ? MSPEC_REPO : RUBYSPEC_REPO
+
NOW = Time.now
BRIGHT_YELLOW = "\e[33;1m"
@@ -57,10 +64,13 @@ class RubyImplementation
end
def last_merge_message
- @data[:merge_message] || "Merge ruby/spec commit"
+ message = @data[:merge_message] || "Merge ruby/spec commit"
+ message.gsub!("ruby/spec", "ruby/mspec") if MSPEC
+ message
end
def prefix
+ return "spec/mspec" if MSPEC
@data[:prefix] || "spec/ruby"
end
@@ -96,18 +106,18 @@ end
def filter_commits(impl)
Dir.chdir(impl.repo_name) do
date = NOW.strftime("%F")
- branch = "specs-#{date}"
+ branch = "#{MSPEC ? :mspec : :specs}-#{date}"
unless branch?(branch)
sh "git", "checkout", "-b", branch
sh "git", "filter-branch", "-f", "--subdirectory-filter", impl.prefix, *impl.from_commit
- sh "git", "push", "-f", RUBYSPEC_REPO, "#{branch}:#{impl.name}"
+ sh "git", "push", "-f", SOURCE_REPO, "#{branch}:#{impl.name}"
end
end
end
def rebase_commits(impl)
- Dir.chdir(RUBYSPEC_REPO) do
+ Dir.chdir(SOURCE_REPO) do
sh "git", "checkout", "master"
sh "git", "pull"
@@ -144,25 +154,29 @@ end
def test_new_specs
require "yaml"
- Dir.chdir(RUBYSPEC_REPO) do
- versions = YAML.load_file(".travis.yml")
- versions = versions["matrix"]["include"].map { |job| job["rvm"] }
- versions.delete "ruby-head"
- min_version, max_version = versions.minmax
-
- run_rubyspec = -> version {
- command = "chruby #{version} && ../mspec/bin/mspec -j"
- sh ENV["SHELL"], "-c", command
- }
- run_rubyspec[min_version]
- run_rubyspec[max_version]
- run_rubyspec["trunk"]
+ Dir.chdir(SOURCE_REPO) do
+ if MSPEC
+ sh "bundle", "exec", "rspec"
+ else
+ versions = YAML.load_file(".travis.yml")
+ versions = versions["matrix"]["include"].map { |job| job["rvm"] }
+ versions.delete "ruby-head"
+ min_version, max_version = versions.minmax
+
+ run_rubyspec = -> version {
+ command = "chruby #{version} && ../mspec/bin/mspec -j"
+ sh ENV["SHELL"], "-c", command
+ }
+ run_rubyspec[min_version]
+ run_rubyspec[max_version]
+ run_rubyspec["trunk"]
+ end
end
end
def verify_commits(impl)
puts
- Dir.chdir(RUBYSPEC_REPO) do
+ Dir.chdir(SOURCE_REPO) do
history = `git log master...`
history.lines.slice_before(/^commit \h{40}$/).each do |commit, *message|
commit = commit.chomp.split.last
@@ -182,7 +196,7 @@ def verify_commits(impl)
end
def fast_forward_master(impl)
- Dir.chdir(RUBYSPEC_REPO) do
+ Dir.chdir(SOURCE_REPO) do
sh "git", "checkout", "master"
sh "git", "merge", "--ff-only", "#{impl.name}-rebased"
end
@@ -192,7 +206,7 @@ def check_ci
puts
puts <<-EOS
Push to master, and check that the CI passes:
- https://github.com/ruby/spec/commits/master
+ https://github.com/ruby/#{:m if MSPEC}spec/commits/master
EOS
end