Revision: 5212 http://trac.macosforge.org/projects/ruby/changeset/5212 Author: eloy.de.enige@gmail.com Date: 2011-01-31 03:02:55 -0800 (Mon, 31 Jan 2011) Log Message: ----------- Update MSpec to 4c65ecbe81062f2ab01c26184745819bc0ab57c6 Modified Paths: -------------- MacRuby/trunk/mspec/lib/mspec/commands/mkspec.rb MacRuby/trunk/mspec/lib/mspec/commands/mspec.rb MacRuby/trunk/mspec/lib/mspec/guards/guard.rb MacRuby/trunk/mspec/lib/mspec/helpers/ruby_exe.rb MacRuby/trunk/mspec/lib/mspec/matchers.rb MacRuby/trunk/mspec/lib/mspec/runner/actions/debug.rb MacRuby/trunk/mspec/lib/mspec/utils/ruby_name.rb MacRuby/trunk/mspec/spec/commands/mspec_spec.rb MacRuby/trunk/mspec/spec/expectations/should_spec.rb MacRuby/trunk/mspec/spec/guards/guard_spec.rb MacRuby/trunk/mspec/spec/helpers/ruby_exe_spec.rb MacRuby/trunk/mspec/spec/spec_helper.rb MacRuby/trunk/mspec/upstream MacRuby/trunk/rakelib/upstream_git_repo_tasks.rb Added Paths: ----------- MacRuby/trunk/mspec/lib/mspec/matchers/be_computed_by_function.rb MacRuby/trunk/mspec/lib/mspec/matchers/be_valid_dns_name.rb MacRuby/trunk/mspec/spec/matchers/be_computed_by_function_spec.rb MacRuby/trunk/mspec/spec/matchers/be_valid_dns_name_spec.rb Modified: MacRuby/trunk/mspec/lib/mspec/commands/mkspec.rb =================================================================== --- MacRuby/trunk/mspec/lib/mspec/commands/mkspec.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/lib/mspec/commands/mkspec.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -138,8 +138,8 @@ # Determine and return the path of the ruby executable. def ruby - ruby = File.join(Config::CONFIG['bindir'], - Config::CONFIG['ruby_install_name']) + ruby = File.join(RbConfig::CONFIG['bindir'], + RbConfig::CONFIG['ruby_install_name']) ruby.gsub! File::SEPARATOR, File::ALT_SEPARATOR if File::ALT_SEPARATOR Modified: MacRuby/trunk/mspec/lib/mspec/commands/mspec.rb =================================================================== --- MacRuby/trunk/mspec/lib/mspec/commands/mspec.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/lib/mspec/commands/mspec.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -17,6 +17,7 @@ config[:flags] = [] config[:command] = nil config[:options] = [] + config[:launch] = [] end def options(argv=ARGV) @@ -38,17 +39,21 @@ options.on("-D", "--gdb", "Run under gdb") do config[:use_gdb] = true end + options.on("-A", "--valgrind", "Run under valgrind") do config[:flags] << '--valgrind' end + options.on("--warnings", "Don't supress warnings") do config[:flags] << '-w' ENV['OUTPUT_WARNINGS'] = '1' end + options.on("-j", "--multi", "Run multiple (possibly parallel) subprocesses") do config[:multi] = true config[:options] << "-fy" end + options.version MSpec::VERSION do if config[:command] config[:options] << "-v" @@ -57,6 +62,7 @@ exit end end + options.help do if config[:command] config[:options] << "-h" @@ -140,6 +146,8 @@ ENV['RUBY_FLAGS'] = config[:flags].join " " argv = [] + + argv.concat config[:launch] argv.concat config[:flags] argv.concat config[:includes] argv.concat config[:requires] Modified: MacRuby/trunk/mspec/lib/mspec/guards/guard.rb =================================================================== --- MacRuby/trunk/mspec/lib/mspec/guards/guard.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/lib/mspec/guards/guard.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -153,7 +153,7 @@ def os?(*oses) oses.any? do |os| - host_os = Config::CONFIG['host_os'] || RUBY_PLATFORM + host_os = RbConfig::CONFIG['host_os'] || RUBY_PLATFORM host_os.downcase! host_os.match(os.to_s) || windows?(os, host_os) end Modified: MacRuby/trunk/mspec/lib/mspec/helpers/ruby_exe.rb =================================================================== --- MacRuby/trunk/mspec/lib/mspec/helpers/ruby_exe.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/lib/mspec/helpers/ruby_exe.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -82,12 +82,12 @@ "ir" end when :name - bin = RUBY_NAME + (Config::CONFIG['EXEEXT'] || Config::CONFIG['exeext'] || '') + bin = RUBY_NAME + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '') File.join(".", bin) when :install_name - bin = Config::CONFIG["RUBY_INSTALL_NAME"] || Config::CONFIG["ruby_install_name"] - bin << (Config::CONFIG['EXEEXT'] || Config::CONFIG['exeext'] || '') - File.join(Config::CONFIG['bindir'], bin) + 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 @@ -110,7 +110,14 @@ body = code working_dir = opts[:dir] || "." Dir.chdir(working_dir) do - body = "-e #{code.inspect}" if code and not File.exists?(code) + if code and not File.exists?(code) + if opts[:escape] + code = "'#{code}'" + else + code = code.inspect + end + body = "-e #{code}" + end cmd = [RUBY_EXE, ENV['RUBY_FLAGS'], opts[:options], body, opts[:args]] `#{cmd.compact.join(' ')}` end Added: MacRuby/trunk/mspec/lib/mspec/matchers/be_computed_by_function.rb =================================================================== --- MacRuby/trunk/mspec/lib/mspec/matchers/be_computed_by_function.rb (rev 0) +++ MacRuby/trunk/mspec/lib/mspec/matchers/be_computed_by_function.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -0,0 +1,35 @@ +class BeComputedByFunctionMatcher + def initialize(sym, *args) + @function = sym + @args = args + end + + def matches?(array) + array.each do |line| + @value = line.pop + @arguments = line + @arguments += @args + return false unless send(@function, *@arguments) == @value + end + + return true + end + + def function_call + function_call = "#{@function}" + unless @arguments.empty? + function_call << "(#{@arguments.map { |x| x.inspect }.join(", ")})" + end + function_call + end + + def failure_message + ["Expected #{@value.inspect}", "to be computed by #{function_call}"] + end +end + +class Object + def be_computed_by_function(sym, *args) + BeComputedByFunctionMatcher.new(sym, *args) + end +end Added: MacRuby/trunk/mspec/lib/mspec/matchers/be_valid_dns_name.rb =================================================================== --- MacRuby/trunk/mspec/lib/mspec/matchers/be_valid_dns_name.rb (rev 0) +++ MacRuby/trunk/mspec/lib/mspec/matchers/be_valid_dns_name.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -0,0 +1,24 @@ +class BeValidDNSName + # http://stackoverflow.com/questions/106179/regular-expression-to-match-hostna... + # ftp://ftp.rfc-editor.org/in-notes/rfc3696.txt + VALID_DNS = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\.?$/ + + def matches?(actual) + @actual = actual + (VALID_DNS =~ @actual) == 0 + end + + def failure_message + ["Expected '#{@actual}'", "to be a valid DNS name"] + end + + def negative_failure_message + ["Expected '#{@actual}'", "not to be a valid DNS name"] + end +end + +class Object + def be_valid_DNS_name + BeValidDNSName.new + end +end Modified: MacRuby/trunk/mspec/lib/mspec/matchers.rb =================================================================== --- MacRuby/trunk/mspec/lib/mspec/matchers.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/lib/mspec/matchers.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -3,11 +3,13 @@ require 'mspec/matchers/be_ancestor_of' require 'mspec/matchers/be_close' require 'mspec/matchers/be_computed_by' +require 'mspec/matchers/be_computed_by_function' require 'mspec/matchers/be_empty' require 'mspec/matchers/be_false' require 'mspec/matchers/be_kind_of' require 'mspec/matchers/be_nil' require 'mspec/matchers/be_true' +require 'mspec/matchers/be_valid_dns_name' require 'mspec/matchers/complain' require 'mspec/matchers/eql' require 'mspec/matchers/equal' Modified: MacRuby/trunk/mspec/lib/mspec/runner/actions/debug.rb =================================================================== --- MacRuby/trunk/mspec/lib/mspec/runner/actions/debug.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/lib/mspec/runner/actions/debug.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -2,6 +2,8 @@ class DebugAction < ActionFilter def before(state) + require 'rubygems' + require 'ruby-debug' Kernel.debugger if self === state.description end Modified: MacRuby/trunk/mspec/lib/mspec/utils/ruby_name.rb =================================================================== --- MacRuby/trunk/mspec/lib/mspec/utils/ruby_name.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/lib/mspec/utils/ruby_name.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -3,6 +3,6 @@ RUBY_NAME = RUBY_ENGINE else require 'rbconfig' - RUBY_NAME = Config::CONFIG["RUBY_INSTALL_NAME"] || Config::CONFIG["ruby_install_name"] + RUBY_NAME = RbConfig::CONFIG["RUBY_INSTALL_NAME"] || RbConfig::CONFIG["ruby_install_name"] end end Modified: MacRuby/trunk/mspec/spec/commands/mspec_spec.rb =================================================================== --- MacRuby/trunk/mspec/spec/commands/mspec_spec.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/spec/commands/mspec_spec.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -244,6 +244,14 @@ @script.run end + it "adds config[:launch] to the exec options" do + @script.should_receive(:exec).with("ruby", + "-Xlaunch.option", "-v", %r"#{MSPEC_HOME}/bin/mspec-run$") + @config[:launch] << "-Xlaunch.option" + @script.options [] + @script.run + end + it "calls #multi_exec if the command is 'ci' and the multi option is passed" do @script.should_receive(:multi_exec).and_return do |arg| arg.length.should == 3 Modified: MacRuby/trunk/mspec/spec/expectations/should_spec.rb =================================================================== --- MacRuby/trunk/mspec/spec/expectations/should_spec.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/spec/expectations/should_spec.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -3,8 +3,8 @@ describe MSpec do before :all do - path = Config::CONFIG['bindir'] - exe = Config::CONFIG['ruby_install_name'] + path = RbConfig::CONFIG['bindir'] + exe = RbConfig::CONFIG['ruby_install_name'] file = File.dirname(__FILE__) + '/should.rb' @out = `#{path}/#{exe} #{file}` end Modified: MacRuby/trunk/mspec/spec/guards/guard_spec.rb =================================================================== --- MacRuby/trunk/mspec/spec/guards/guard_spec.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/spec/guards/guard_spec.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -237,12 +237,12 @@ @guard.platform?(:windows).should == true end - it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mswin'" do + it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do Object.const_set :RUBY_PLATFORM, 'i386-mswin32' @guard.platform?(:linux).should == false end - it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mingw'" do + it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do Object.const_set :RUBY_PLATFORM, 'i386-mingw32' @guard.platform?(:linux).should == false end @@ -273,12 +273,12 @@ end it "returns true when arg is :windows and RUBY_PLATFORM contains 'java' and os?(:windows) is true" do - Config::CONFIG.stub!(:[]).and_return('mswin32') + RbConfig::CONFIG.stub!(:[]).and_return('mswin32') @guard.platform?(:windows).should == true end it "returns true when RUBY_PLATFORM contains 'java' and os?(argument) is true" do - Config::CONFIG.stub!(:[]).and_return('amiga') + RbConfig::CONFIG.stub!(:[]).and_return('amiga') @guard.platform?(:amiga).should == true end end @@ -300,42 +300,42 @@ describe SpecGuard, "#os?" do before :each do @guard = SpecGuard.new - Config::CONFIG.stub!(:[]).and_return('unreal') + RbConfig::CONFIG.stub!(:[]).and_return('unreal') end - it "returns true if argument matches Config::CONFIG['host_os']" do + it "returns true if argument matches RbConfig::CONFIG['host_os']" do @guard.os?(:unreal).should == true end - it "returns true if any argument matches Config::CONFIG['host_os']" do + it "returns true if any argument matches RbConfig::CONFIG['host_os']" do @guard.os?(:bsd, :unreal, :amiga).should == true end - it "returns false if no argument matches Config::CONFIG['host_os']" do + it "returns false if no argument matches RbConfig::CONFIG['host_os']" do @guard.os?(:bsd, :netbsd, :amiga, :msdos).should == false end - it "returns false if argument does not match Config::CONFIG['host_os']" do + it "returns false if argument does not match RbConfig::CONFIG['host_os']" do @guard.os?(:amiga).should == false end - it "returns true when arg is :windows and Config::CONFIG['host_os'] contains 'mswin'" do - Config::CONFIG.stub!(:[]).and_return('i386-mswin32') + it "returns true when arg is :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do + RbConfig::CONFIG.stub!(:[]).and_return('i386-mswin32') @guard.os?(:windows).should == true end - it "returns true when arg is :windows and Config::CONFIG['host_os'] contains 'mingw'" do - Config::CONFIG.stub!(:[]).and_return('i386-mingw32') + it "returns true when arg is :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do + RbConfig::CONFIG.stub!(:[]).and_return('i386-mingw32') @guard.os?(:windows).should == true end - it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mswin'" do - Config::CONFIG.stub!(:[]).and_return('i386-mingw32') + it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do + RbConfig::CONFIG.stub!(:[]).and_return('i386-mingw32') @guard.os?(:linux).should == false end - it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mingw'" do - Config::CONFIG.stub!(:[]).and_return('i386-mingw32') + it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do + RbConfig::CONFIG.stub!(:[]).and_return('i386-mingw32') @guard.os?(:linux).should == false end end Modified: MacRuby/trunk/mspec/spec/helpers/ruby_exe_spec.rb =================================================================== --- MacRuby/trunk/mspec/spec/helpers/ruby_exe_spec.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/spec/helpers/ruby_exe_spec.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -52,14 +52,14 @@ end it "returns RUBY_NAME + $(EXEEXT) when passed :name" do - bin = RUBY_NAME + (Config::CONFIG['EXEEXT'] || Config::CONFIG['exeext'] || '') + bin = RUBY_NAME + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '') name = File.join ".", bin @script.ruby_exe_options(:name).should == name end it "returns $(bindir)/$(RUBY_INSTALL_NAME) + $(EXEEXT) when passed :install_name" do - bin = Config::CONFIG['RUBY_INSTALL_NAME'] + (Config::CONFIG['EXEEXT'] || Config::CONFIG['exeext'] || '') - name = File.join Config::CONFIG['bindir'], bin + bin = RbConfig::CONFIG['RUBY_INSTALL_NAME'] + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '') + name = File.join RbConfig::CONFIG['bindir'], bin @script.ruby_exe_options(:install_name).should == name end end Added: MacRuby/trunk/mspec/spec/matchers/be_computed_by_function_spec.rb =================================================================== --- MacRuby/trunk/mspec/spec/matchers/be_computed_by_function_spec.rb (rev 0) +++ MacRuby/trunk/mspec/spec/matchers/be_computed_by_function_spec.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -0,0 +1,36 @@ +require File.dirname(__FILE__) + '/../spec_helper' +require 'mspec/matchers/be_computed_by_function' + +describe BeComputedByFunctionMatcher do + it "matches when all entries in the Array compute" do + array = [ ["%2d", 65, "65"], + ["%04d", 90, "0090"] ] + BeComputedByFunctionMatcher.new(:sprintf).matches?(array).should be_true + end + + it "matches when all entries in the Array with arguments compute" do + array = [ ["%2d", "65"], + ["%04d", "0065"] ] + BeComputedByFunctionMatcher.new(:sprintf, 65).matches?(array).should be_true + end + + it "does not match when any entry in the Array does not compute" do + array = [ ["%2d", 65, "65"], + ["%04d", 90, "00090"] ] + BeComputedByFunctionMatcher.new(:sprintf).matches?(array).should be_false + end + + it "does not match when any entry in the Array with arguments does not compute" do + array = [ ["%2d", "65"], + ["%04d", "0065"] ] + BeComputedByFunctionMatcher.new(:sprintf, 91).matches?(array).should be_false + end + + it "provides a useful failure message" do + array = [ ["%2d", 90, "65"], + ["%04d", 90, "00090"] ] + matcher = BeComputedByFunctionMatcher.new(:sprintf) + matcher.matches?(array) + matcher.failure_message.should == ["Expected \"65\"", "to be computed by sprintf(\"%2d\", 90)"] + end +end Added: MacRuby/trunk/mspec/spec/matchers/be_valid_dns_name_spec.rb =================================================================== --- MacRuby/trunk/mspec/spec/matchers/be_valid_dns_name_spec.rb (rev 0) +++ MacRuby/trunk/mspec/spec/matchers/be_valid_dns_name_spec.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -0,0 +1,50 @@ +require File.dirname(__FILE__) + '/../spec_helper' +require 'mspec/expectations/expectations' +require 'mspec/matchers/be_valid_dns_name' + +describe BeValidDNSName do + it "matches when actual is 'localhost'" do + BeValidDNSName.new.matches?("localhost").should be_true + end + + it "matches when actual is 'localhost.localdomain'" do + BeValidDNSName.new.matches?("localhost.localdomain").should be_true + end + + it "matches when actual is hyphenated" do + BeValidDNSName.new.matches?("local-host").should be_true + end + + it "matches when actual is 'a.b.c'" do + BeValidDNSName.new.matches?("a.b.c").should be_true + end + + it "matches when actual has a trailing '.'" do + BeValidDNSName.new.matches?("a.com.").should be_true + end + + it "does not match when actual is not a valid dns name" do + BeValidDNSName.new.matches?(".").should be_false + end + + it "does not match when actual contains a hyphen at the beginning" do + BeValidDNSName.new.matches?("-localhost").should be_false + end + + it "does not match when actual contains a hyphen at the end" do + BeValidDNSName.new.matches?("localhost-").should be_false + end + + it "provides a failure message" do + matcher = BeValidDNSName.new + matcher.matches?(".") + matcher.failure_message.should == ["Expected '.'", "to be a valid DNS name"] + end + + it "provides a negative failure message" do + matcher = BeValidDNSName.new + matcher.matches?("localhost") + matcher.negative_failure_message.should == + ["Expected 'localhost'", "not to be a valid DNS name"] + end +end Modified: MacRuby/trunk/mspec/spec/spec_helper.rb =================================================================== --- MacRuby/trunk/mspec/spec/spec_helper.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/spec/spec_helper.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -29,6 +29,7 @@ self[:command] = nil self[:ltags] = [] self[:files] = [] + self[:launch] = [] end end Modified: MacRuby/trunk/mspec/upstream =================================================================== --- MacRuby/trunk/mspec/upstream 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/mspec/upstream 2011-01-31 11:02:55 UTC (rev 5212) @@ -1 +1 @@ -66c9eb68ccdc473025d2f6fb34019fc3a977c252 +4c65ecbe81062f2ab01c26184745819bc0ab57c6 \ No newline at end of file Modified: MacRuby/trunk/rakelib/upstream_git_repo_tasks.rb =================================================================== --- MacRuby/trunk/rakelib/upstream_git_repo_tasks.rb 2011-01-31 06:19:30 UTC (rev 5211) +++ MacRuby/trunk/rakelib/upstream_git_repo_tasks.rb 2011-01-31 11:02:55 UTC (rev 5212) @@ -18,7 +18,7 @@ end def upstream_rev - @upstream_rev ||= ENV['REV'] || File.read(upstream_rev_file) + @upstream_rev ||= (ENV['REV'] || File.read(upstream_rev_file)).strip end def define
participants (1)
-
source_changes@macosforge.org