[macruby-changes] [3230] MacRuby/trunk/mspec
source_changes at macosforge.org
source_changes at macosforge.org
Sun Jan 10 12:53:11 PST 2010
Revision: 3230
http://trac.macosforge.org/projects/ruby/changeset/3230
Author: eloy.de.enige at gmail.com
Date: 2010-01-10 12:53:10 -0800 (Sun, 10 Jan 2010)
Log Message:
-----------
Updated MSpec to ddf4bd5a4c29e36caad2504749a7bfb5dc8eadf5
Modified Paths:
--------------
MacRuby/trunk/mspec/Rakefile
MacRuby/trunk/mspec/lib/mspec/expectations/should.rb
MacRuby/trunk/mspec/lib/mspec/helpers/language_version.rb
MacRuby/trunk/mspec/lib/mspec/helpers/tmp.rb
MacRuby/trunk/mspec/lib/mspec/helpers.rb
MacRuby/trunk/mspec/lib/mspec/runner/context.rb
MacRuby/trunk/mspec/lib/mspec/runner/mspec.rb
MacRuby/trunk/mspec/lib/mspec/version.rb
MacRuby/trunk/mspec/spec/helpers/language_version_spec.rb
MacRuby/trunk/mspec/spec/helpers/tmp_spec.rb
MacRuby/trunk/mspec/spec/runner/context_spec.rb
MacRuby/trunk/mspec/upstream
Added Paths:
-----------
MacRuby/trunk/mspec/lib/mspec/helpers/fs.rb
MacRuby/trunk/mspec/spec/helpers/fs_spec.rb
Removed Paths:
-------------
MacRuby/trunk/mspec/mspec.gemspec
Modified: MacRuby/trunk/mspec/Rakefile
===================================================================
--- MacRuby/trunk/mspec/Rakefile 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/Rakefile 2010-01-10 20:53:10 UTC (rev 3230)
@@ -18,7 +18,7 @@
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Brian Ford"]
- s.date = %q{2009-6-8}
+ s.date = %q{2010-01-05}
s.email = %q{bford at engineyard.com}
s.has_rdoc = true
s.extra_rdoc_files = %w[ README LICENSE ]
@@ -27,7 +27,7 @@
s.homepage = %q{http://rubyspec.org}
s.rubyforge_project = 'http://rubyforge.org/projects/mspec'
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.1.1}
+ s.rubygems_version = %q{1.3.5}
s.summary = <<EOS
MSpec is a specialized framework that is syntax-compatible
with RSpec for basic things like describe, it blocks and
Modified: MacRuby/trunk/mspec/lib/mspec/expectations/should.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/expectations/should.rb 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/lib/mspec/expectations/should.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -1,8 +1,9 @@
class Object
- def should(matcher=nil)
+ NO_MATCHER_GIVEN = Object.new
+ def should(matcher=NO_MATCHER_GIVEN)
MSpec.expectation
MSpec.actions :expectation, MSpec.current.state
- if matcher
+ unless matcher.equal?(NO_MATCHER_GIVEN)
unless matcher.matches?(self)
SpecExpectation.fail_with(*matcher.failure_message)
end
@@ -11,10 +12,10 @@
end
end
- def should_not(matcher=nil)
+ def should_not(matcher=NO_MATCHER_GIVEN)
MSpec.expectation
MSpec.actions :expectation, MSpec.current.state
- if matcher
+ unless matcher.equal?(NO_MATCHER_GIVEN)
if matcher.matches?(self)
SpecExpectation.fail_with(*matcher.negative_failure_message)
end
Added: MacRuby/trunk/mspec/lib/mspec/helpers/fs.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/helpers/fs.rb (rev 0)
+++ MacRuby/trunk/mspec/lib/mspec/helpers/fs.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -0,0 +1,58 @@
+class Object
+ # Copies a file
+ def cp(source, dest)
+ File.open(dest, "w") do |d|
+ File.open(source, "r") 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
+
+ if File.file? name
+ raise ArgumentError, "path component of #{path} is a file"
+ end
+
+ Dir.mkdir name unless File.directory? name
+ 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
+
+ prefix = SPEC_TEMP_DIR
+ unless path[0, prefix.size] == prefix
+ raise ArgumentError, "#{path} is not prefixed by #{prefix}"
+ end
+
+ if File.directory? path
+ Dir.entries(path).each { |x| rm_r "#{path}/#{x}" unless x =~ /^\.\.?$/ }
+ Dir.rmdir path
+ elsif File.exists? 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)
+
+ File.open(name, mode) do |f|
+ yield f if block_given?
+ end
+ end
+end
Modified: MacRuby/trunk/mspec/lib/mspec/helpers/language_version.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/helpers/language_version.rb 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/lib/mspec/helpers/language_version.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -10,11 +10,21 @@
#
# Then add a file "language/versions/method_1.8.rb" for the specs that are
# syntax-compatible with Ruby 1.8.x.
+ #
+ # The most version-specific file will be loaded. If the version is 1.8.6,
+ # "method_1.8.6.rb" will be loaded if it exists, otherwise "method_1.8.rb"
+ # will be loaded if it exists.
def language_version(dir, name)
path = File.dirname(File.expand_path(dir))
- name = "#{name}_#{SpecGuard.ruby_version}.rb"
- file = File.join path, "versions", name
- require file if File.exists? file
+ [SpecGuard.ruby_version(:tiny), SpecGuard.ruby_version].each do |version|
+ file = File.join path, "versions", "#{name}_#{version}.rb"
+ if File.exists? file
+ require file
+ break
+ end
+ end
+
+ nil
end
end
Modified: MacRuby/trunk/mspec/lib/mspec/helpers/tmp.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/helpers/tmp.rb 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/lib/mspec/helpers/tmp.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -1,37 +1,32 @@
-# The #tmp method provides a similar functionality
-# to that of Dir.tmpdir. This helper can be overridden
-# by different implementations to provide a more useful
-# behavior if needed.
-#
-# Usage in a spec:
-#
-# File.open(tmp("tags.txt"), "w") { |f| f.puts "" }
-#
-# The order of directories below with "/private/tmp"
-# preceding "/tmp" is significant. On OS X, the directory
-# "/tmp" is a symlink to "private/tmp" with no leading
-# "/". Rather than futzing with what constitutes an
-# absolute path, we just look for "/private/tmp" first.
+# Creates a temporary directory in the current working directory
+# for temporary files created while running the specs. All specs
+# should clean up any temporary files created so that the temp
+# directory is empty when the process exits.
+SPEC_TEMP_DIR = "#{File.expand_path(Dir.pwd)}/rubyspec_temp"
+
+at_exit do
+ begin
+ Dir.delete SPEC_TEMP_DIR if File.directory? SPEC_TEMP_DIR
+ rescue SystemCallError
+ STDERR.puts <<-EOM
+
+-----------------------------------------------------
+The rubyspec temp directory is not empty. Ensure that
+all specs are cleaning up temporary files.
+-----------------------------------------------------
+
+ EOM
+ rescue Object => e
+ STDERR.puts "failed to remove spec temp directory"
+ STDERR.puts e.message
+ end
+end
+
class Object
def tmp(name)
- unless @spec_temp_directory
- # MacRuby TODO: Discuss with Brian
- if RUBY_NAME =~ /^macruby/
- @spec_temp_directory = "/private/tmp"
- else
- [ ENV["TMPDIR"], "/private/tmp", "/tmp", "/var/tmp", ENV["TMP"],
- ENV["TEMP"], ENV["USERPROFILE"] ].each do |dir|
- if dir and File.directory?(dir) and File.writable?(dir)
- temp = File.expand_path dir
- temp = File.readlink temp if File.symlink? temp
- @spec_temp_directory = temp
- break
- end
- end
- end
- end
+ Dir.mkdir SPEC_TEMP_DIR unless File.exists? SPEC_TEMP_DIR
- File.join @spec_temp_directory, name
+ File.join SPEC_TEMP_DIR, name
end
end
Modified: MacRuby/trunk/mspec/lib/mspec/helpers.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/helpers.rb 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/lib/mspec/helpers.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -6,6 +6,7 @@
require 'mspec/helpers/environment'
require 'mspec/helpers/fixture'
require 'mspec/helpers/flunk'
+require 'mspec/helpers/fs'
require 'mspec/helpers/hash'
require 'mspec/helpers/infinity'
require 'mspec/helpers/io'
Modified: MacRuby/trunk/mspec/lib/mspec/runner/context.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/runner/context.rb 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/lib/mspec/runner/context.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -32,9 +32,9 @@
@parents = [self]
@children = []
- @mock_verify = lambda { Mock.verify_count }
- @mock_cleanup = lambda { Mock.cleanup }
- @expectation_missing = lambda { raise SpecExpectationNotFoundError }
+ @mock_verify = Proc.new { Mock.verify_count }
+ @mock_cleanup = Proc.new { Mock.cleanup }
+ @expectation_missing = Proc.new { raise SpecExpectationNotFoundError }
end
# Returns true if this is a shared +ContextState+. Essentially, when
@@ -57,6 +57,12 @@
end
end
+ def replace_parent(parent)
+ @parents[0] = parent
+
+ children.each { |child| child.replace_parent parent }
+ end
+
# Add the ContextState instance +child+ to the list of nested
# describe blocks.
def child(child)
@@ -124,6 +130,14 @@
state.before(:each).each { |b| before :each, &b }
state.after(:each).each { |b| after :each, &b }
state.after(:all).each { |b| after :all, &b }
+
+ # There is a potential race here if mspec ever implements concurrency
+ # in process. Right now, the only way to run specs concurrently is
+ # with multiple processes, so we ignore this for the sake of simplicity.
+ state.children.each do |child|
+ child.replace_parent self
+ @children << child
+ end
end
# Evaluates each block in +blocks+ using the +MSpec.protect+ method
Modified: MacRuby/trunk/mspec/lib/mspec/runner/mspec.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/runner/mspec.rb 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/lib/mspec/runner/mspec.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -266,7 +266,7 @@
file = tags_file
if File.exist? file
# TODO: roxor workaround, or should mspec just use File.read anyways?
- # File.open(file, "r") do |f|
+ # File.open(file, "rb") do |f|
# f.each_line do |line|
# line.chomp!
# next if line.empty?
@@ -290,7 +290,7 @@
file = tags_file
path = File.dirname file
FileUtils.mkdir_p path unless File.exist? path
- File.open(file, "w") do |f|
+ File.open(file, "wb") do |f|
tags.each { |t| f.puts t }
end
end
@@ -303,11 +303,11 @@
path = File.dirname file
FileUtils.mkdir_p path unless File.exist? path
if File.exist? file
- File.open(file, "r") do |f|
+ File.open(file, "rb") do |f|
f.each_line { |line| return false if line.chomp == string }
end
end
- File.open(file, "a") { |f| f.puts string }
+ File.open(file, "ab") { |f| f.puts string }
return true
end
@@ -320,7 +320,7 @@
file = tags_file
if File.exist? file
lines = IO.readlines(file)
- File.open(file, "w") do |f|
+ File.open(file, "wb") do |f|
lines.each do |line|
# unless pattern =~ line.chomp
# FIXME: This is temporary until the regexp specs are passing
Modified: MacRuby/trunk/mspec/lib/mspec/version.rb
===================================================================
--- MacRuby/trunk/mspec/lib/mspec/version.rb 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/lib/mspec/version.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -1,5 +1,5 @@
require 'mspec/utils/version'
module MSpec
- VERSION = SpecVersion.new "1.5.12"
+ VERSION = SpecVersion.new "1.5.14"
end
Deleted: MacRuby/trunk/mspec/mspec.gemspec
===================================================================
--- MacRuby/trunk/mspec/mspec.gemspec 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/mspec.gemspec 2010-01-10 20:53:10 UTC (rev 3230)
@@ -1,33 +0,0 @@
-Gem::Specification.new do |s|
- s.name = %q{mspec}
- s.version = "1.5.12"
-
- s.specification_version = 2 if s.respond_to? :specification_version=
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Brian Ford"]
- s.date = %q{2009-6-8}
- s.email = %q{bford at engineyard.com}
- s.has_rdoc = true
- s.extra_rdoc_files = %w[ README LICENSE ]
- s.executables = ["mkspec", "mspec", "mspec-ci", "mspec-run", "mspec-tag"]
- s.files = FileList[ '{bin,lib,spec}/**/*.{yaml,txt,rb}', 'Rakefile', *s.extra_rdoc_files ]
- s.homepage = %q{http://rubyspec.org}
- s.rubyforge_project = 'http://rubyforge.org/projects/mspec'
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.1.1}
- s.summary = <<EOS
-MSpec is a specialized framework that is syntax-compatible
-with RSpec for basic things like describe, it blocks and
-before, after actions.
-
-MSpec contains additional features that assist in writing
-the RubySpecs used by multiple Ruby implementations. Also,
-MSpec attempts to use the simplest Ruby language features
-so that beginning Ruby implementations can run it.
-EOS
-
- s.rdoc_options << '--title' << 'MSpec Gem' <<
- '--main' << 'README' <<
- '--line-numbers'
-end
Added: MacRuby/trunk/mspec/spec/helpers/fs_spec.rb
===================================================================
--- MacRuby/trunk/mspec/spec/helpers/fs_spec.rb (rev 0)
+++ MacRuby/trunk/mspec/spec/helpers/fs_spec.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -0,0 +1,165 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+require 'mspec/helpers/tmp'
+require 'mspec/helpers/fs'
+
+describe Object, "#cp" do
+ before :each do
+ @source = tmp("source.txt")
+ @copy = tmp("copied.txt")
+
+ @contents = "This is a copy."
+ File.open(@source, "w") { |f| f.write @contents }
+ end
+
+ after :each do
+ File.delete @source if File.exists? @source
+ File.delete @copy if File.exists? @copy
+ end
+
+ it "copies a file" do
+ cp @source, @copy
+ data = IO.read(@copy)
+ data.should == @contents
+ data.should == IO.read(@source)
+ end
+end
+
+describe Object, "#touch" do
+ before :all do
+ @name = tmp("touched.txt")
+ end
+
+ after :each do
+ File.delete @name if File.exists? @name
+ end
+
+ it "creates a file" do
+ touch @name
+ File.exists?(@name).should be_true
+ end
+
+ it "accepts an optional mode argument" do
+ touch @name, "wb"
+ File.exists?(@name).should be_true
+ end
+
+ it "overwrites an existing file" do
+ File.open(@name, "w") { |f| f.puts "used" }
+ File.size(@name).should > 0
+
+ touch @name
+ File.size(@name).should == 0
+ end
+
+ it "yields the open file if passed a block" do
+ touch(@name) { |f| f.write "touching" }
+ IO.read(@name).should == "touching"
+ end
+end
+
+describe Object, "#touch" do
+ before :all do
+ @dir = tmp("subdir")
+ @name = tmp("subdir/touched.txt")
+ end
+
+ after :each do
+ File.delete @name if File.exists? @name
+ Dir.rmdir @dir if File.directory? @dir
+ end
+
+ it "creates all the directories in the path to the file" do
+ touch @name
+ File.exists?(@name).should be_true
+ end
+end
+
+describe Object, "#mkdir_p" do
+ before :all do
+ @dir1 = tmp("/nested")
+ @dir2 = @dir1 + "/directory"
+ @paths = [ @dir2, @dir1 ]
+ end
+
+ after :each do
+ File.delete @dir1 if File.file? @dir1
+ @paths.each { |path| Dir.rmdir path if File.directory? path }
+ end
+
+ it "creates all the directories in a path" do
+ mkdir_p @dir2
+ File.directory?(@dir2).should be_true
+ end
+
+ it "raises an ArgumentError if a path component is a file" do
+ File.open(@dir1, "w") { |f| }
+ lambda { mkdir_p @dir2 }.should raise_error(ArgumentError)
+ end
+end
+
+describe Object, "#rm_r" do
+ before :all do
+ @topdir = tmp("rm_r_tree")
+ @topfile = @topdir + "/file.txt"
+ @link = @topdir + "/file.lnk"
+ @socket = @topdir + "/socket.sck"
+ @subdir1 = @topdir + "/subdir1"
+ @subdir2 = @subdir1 + "/subdir2"
+ @subfile = @subdir1 + "/subfile.txt"
+ end
+
+ before :each do
+ mkdir_p @subdir2
+ touch @topfile
+ touch @subfile
+ end
+
+ after :each do
+ File.delete @link if File.exists? @link
+ File.delete @socket if File.exists? @socket
+ File.delete @subfile if File.exists? @subfile
+ File.delete @topfile if File.exists? @topfile
+
+ Dir.rmdir @subdir2 if File.directory? @subdir2
+ Dir.rmdir @subdir1 if File.directory? @subdir1
+ Dir.rmdir @topdir if File.directory? @topdir
+ end
+
+ it "raises an ArgumentError if the path is not prefixed by MSPEC_RM_PREFIX" do
+ lambda { rm_r "some_file.txt" }.should raise_error(ArgumentError)
+ end
+
+ it "removes a single file" do
+ rm_r @subfile
+ File.exists?(@subfile).should be_false
+ end
+
+ it "removes multiple files" do
+ rm_r @topfile, @subfile
+ File.exists?(@topfile).should be_false
+ File.exists?(@subfile).should be_false
+ end
+
+ it "removes a symlink" do
+ File.symlink @topfile, @link
+ rm_r @link
+ File.exists?(@link).should be_false
+ end
+
+ it "removes a socket" do
+ require 'socket'
+ UNIXServer.new(@socket).close
+ rm_r @socket
+ File.exists?(@socket).should be_false
+ end
+
+ it "removes a single directory" do
+ rm_r @subdir2
+ File.directory?(@subdir2).should be_false
+ end
+
+ it "recursively removes a directory tree" do
+ rm_r @topdir
+ File.directory?(@topdir).should be_false
+ end
+end
Modified: MacRuby/trunk/mspec/spec/helpers/language_version_spec.rb
===================================================================
--- MacRuby/trunk/mspec/spec/helpers/language_version_spec.rb 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/spec/helpers/language_version_spec.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -7,23 +7,33 @@
Object.const_set :RUBY_VERSION, "8.2.3"
- dir = File.dirname(File.expand_path(__FILE__))
- @name = "#{dir}/versions/method_8.2.rb"
+ dir = "#{File.expand_path('../', __FILE__)}/versions"
+ @method82 = "#{dir}/method_8.2.rb"
+ @method823 = "#{dir}/method_8.2.3.rb"
end
after :all do
Object.const_set :RUBY_VERSION, @ruby_version
end
- it "loads files conditionally based on name and RUBY_VERSION if it exists" do
- File.should_receive(:exists?).with(@name).and_return(true)
- should_receive(:require).with(@name)
+ it "loads the most version-specific file if it exists" do
+ File.should_receive(:exists?).with(@method823).and_return(true)
+ should_receive(:require).with(@method823)
language_version __FILE__, "method"
end
+ it "loads a less version-specific file if it exists" do
+ File.should_receive(:exists?).with(@method823).and_return(false)
+ File.should_receive(:exists?).with(@method82).and_return(true)
+ should_receive(:require).with(@method82)
+ language_version __FILE__, "method"
+ end
+
it "does not load the file if it does not exist" do
- File.should_receive(:exists?).with(@name).and_return(false)
- should_not_receive(:require).with(@name)
+ File.should_receive(:exists?).with(@method82).and_return(false)
+ File.should_receive(:exists?).with(@method823).and_return(false)
+ should_not_receive(:require).with(@method82)
+ should_not_receive(:require).with(@method823)
language_version __FILE__, "method"
end
end
Modified: MacRuby/trunk/mspec/spec/helpers/tmp_spec.rb
===================================================================
--- MacRuby/trunk/mspec/spec/helpers/tmp_spec.rb 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/spec/helpers/tmp_spec.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -2,71 +2,9 @@
require 'mspec/helpers/tmp'
describe Object, "#tmp" do
- before :each do
- File.stub!(:directory?).and_return(false)
- File.stub!(:symlink?).and_return(false)
- ENV.stub!(:[]).and_return(nil)
- end
+ it "returns a name relative to the current working directory" do
+ dir = "#{File.expand_path(Dir.pwd)}/rubyspec_temp"
- it "returns /tmp/<name> if /tmp is a writable directory" do
- dir = "/tmp"
- File.should_receive(:directory?).with(dir).and_return(true)
- File.should_receive(:writable?).with(dir).and_return(true)
- File.should_receive(:expand_path).with(dir).and_return(dir)
tmp("test.txt").should == dir + "/test.txt"
end
-
- it "returns /var/tmp/<name> if /var/tmp is a writable directory" do
- dir = "/var/tmp"
- File.should_receive(:directory?).with(dir).and_return(true)
- File.should_receive(:writable?).with(dir).and_return(true)
- File.should_receive(:expand_path).with(dir).and_return(dir)
- tmp("test.txt").should == dir + "/test.txt"
- end
-
- it "returns ENV['TMPDIR']/<name> if ENV['TMPDIR'] is a writable directory" do
- dir = "/tmpdir"
- ENV.should_receive(:[]).with("TMPDIR").and_return(dir)
- File.should_receive(:directory?).with(dir).and_return(true)
- File.should_receive(:writable?).with(dir).and_return(true)
- File.should_receive(:expand_path).with(dir).and_return(dir)
- tmp("test.txt").should == dir + "/test.txt"
- end
-
- it "returns ENV['TMP']/<name> if ENV['TMP'] is a writable directory" do
- dir = "/tmp/tmp"
- ENV.should_receive(:[]).with("TMP").and_return(dir)
- File.should_receive(:directory?).with(dir).and_return(true)
- File.should_receive(:writable?).with(dir).and_return(true)
- File.should_receive(:expand_path).with(dir).and_return(dir)
- tmp("test.txt").should == dir + "/test.txt"
- end
-
- it "returns ENV['TEMP']/<name> if ENV['TEMP'] is a writable directory" do
- dir = "/tmp/temp"
- ENV.should_receive(:[]).with("TEMP").and_return(dir)
- File.should_receive(:directory?).with(dir).and_return(true)
- File.should_receive(:writable?).with(dir).and_return(true)
- File.should_receive(:expand_path).with(dir).and_return(dir)
- tmp("test.txt").should == dir + "/test.txt"
- end
-
- it "returns ENV['USERPROFILE']/<name> if ENV['USERPROFILE'] is a writable directory" do
- dir = "/tmp/temp"
- ENV.should_receive(:[]).with("TEMP").and_return(dir)
- File.should_receive(:directory?).with(dir).and_return(true)
- File.should_receive(:writable?).with(dir).and_return(true)
- File.should_receive(:expand_path).with(dir).and_return(dir)
- tmp("test.txt").should == dir + "/test.txt"
- end
-
- it "returns the actual file name if the file is a symlink" do
- dir = "/tmp"
- File.should_receive(:directory?).with(dir).and_return(true)
- File.should_receive(:writable?).with(dir).and_return(true)
- File.should_receive(:expand_path).with(dir).and_return(dir)
- File.should_receive(:symlink?).with(dir).and_return(true)
- File.should_receive(:readlink).with(dir).and_return("/ponies"+dir)
- tmp("test.txt").should == "/ponies" + dir + "/test.txt"
- end
end
Modified: MacRuby/trunk/mspec/spec/runner/context_spec.rb
===================================================================
--- MacRuby/trunk/mspec/spec/runner/context_spec.rb 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/spec/runner/context_spec.rb 2010-01-10 20:53:10 UTC (rev 3230)
@@ -910,7 +910,8 @@
describe ContextState, "#it_should_behave_like" do
before :each do
- @shared = ContextState.new("", :shared => true)
+ @shared_desc = "shared context"
+ @shared = ContextState.new(@shared_desc, :shared => true)
MSpec.stub!(:retrieve_shared).and_return(@shared)
@state = ContextState.new ""
@@ -923,10 +924,30 @@
lambda { @state.it_should_behave_like "this" }.should raise_error(Exception)
end
+ describe "for nested ContextState instances" do
+ before :each do
+ @nested = ContextState.new ""
+ @nested.parents.unshift @shared
+ @shared.children << @nested
+ end
+
+ it "adds nested describe blocks to the invoking ContextState" do
+ @state.it_should_behave_like @shared_desc
+ @shared.children.should_not be_empty
+ @state.children.should include(*@shared.children)
+ end
+
+ it "changes the parent ContextState" do
+ @shared.children.first.parents.first.should equal(@shared)
+ @state.it_should_behave_like @shared_desc
+ @shared.children.first.parents.first.should equal(@state)
+ end
+ end
+
it "adds examples from the shared ContextState" do
@shared.it "some", &@a
@shared.it "thing", &@b
- @state.it_should_behave_like ""
+ @state.it_should_behave_like @shared_desc
@state.examples.should include(*@shared.examples)
end
@@ -934,34 +955,34 @@
@shared.it "some", &@a
@shared.it "thing", &@b
@shared.examples.each { |ex| ex.should_receive(:context=).with(@state) }
- @state.it_should_behave_like ""
+ @state.it_should_behave_like @shared_desc
end
it "adds before(:all) blocks from the shared ContextState" do
@shared.before :all, &@a
@shared.before :all, &@b
- @state.it_should_behave_like ""
+ @state.it_should_behave_like @shared_desc
@state.before(:all).should include(*@shared.before(:all))
end
it "adds before(:each) blocks from the shared ContextState" do
@shared.before :each, &@a
@shared.before :each, &@b
- @state.it_should_behave_like ""
+ @state.it_should_behave_like @shared_desc
@state.before(:each).should include(*@shared.before(:each))
end
it "adds after(:each) blocks from the shared ContextState" do
@shared.after :each, &@a
@shared.after :each, &@b
- @state.it_should_behave_like ""
+ @state.it_should_behave_like @shared_desc
@state.after(:each).should include(*@shared.after(:each))
end
it "adds after(:all) blocks from the shared ContextState" do
@shared.after :all, &@a
@shared.after :all, &@b
- @state.it_should_behave_like ""
+ @state.it_should_behave_like @shared_desc
@state.after(:all).should include(*@shared.after(:all))
end
end
Modified: MacRuby/trunk/mspec/upstream
===================================================================
--- MacRuby/trunk/mspec/upstream 2010-01-10 20:52:37 UTC (rev 3229)
+++ MacRuby/trunk/mspec/upstream 2010-01-10 20:53:10 UTC (rev 3230)
@@ -1 +1 @@
-bcec47c70e0678a29fd0c1345358c4daf7b971a3
\ No newline at end of file
+ddf4bd5a4c29e36caad2504749a7bfb5dc8eadf5
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100110/112eda0c/attachment-0001.html>
More information about the macruby-changes
mailing list