mspec 1.5.12 → 1.5.13

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ spec = Gem::Specification.new do |s|
18
18
 
19
19
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
20
20
  s.authors = ["Brian Ford"]
21
- s.date = %q{2009-6-8}
21
+ s.date = %q{2009-12-25}
22
22
  s.email = %q{bford@engineyard.com}
23
23
  s.has_rdoc = true
24
24
  s.extra_rdoc_files = %w[ README LICENSE ]
@@ -27,7 +27,7 @@ spec = Gem::Specification.new do |s|
27
27
  s.homepage = %q{http://rubyspec.org}
28
28
  s.rubyforge_project = 'http://rubyforge.org/projects/mspec'
29
29
  s.require_paths = ["lib"]
30
- s.rubygems_version = %q{1.1.1}
30
+ s.rubygems_version = %q{1.3.5}
31
31
  s.summary = <<EOS
32
32
  MSpec is a specialized framework that is syntax-compatible
33
33
  with RSpec for basic things like describe, it blocks and
@@ -36,7 +36,7 @@ class MSpecMain < MSpecScript
36
36
  options.targets
37
37
 
38
38
  options.on("-D", "--gdb", "Run under gdb") do
39
- config[:flags] << '--gdb'
39
+ config[:use_gdb] = true
40
40
  end
41
41
  options.on("-A", "--valgrind", "Run under valgrind") do
42
42
  config[:flags] << '--valgrind'
@@ -150,7 +150,12 @@ class MSpecMain < MSpecScript
150
150
  if config[:multi] and config[:command] == "ci"
151
151
  multi_exec argv
152
152
  else
153
- exec config[:target], *argv
153
+ if config[:use_gdb]
154
+ more = ["--args", config[:target]] + argv
155
+ exec "gdb", *more
156
+ else
157
+ exec config[:target], *argv
158
+ end
154
159
  end
155
160
  end
156
161
  end
@@ -1,8 +1,9 @@
1
1
  class Object
2
- def should(matcher=nil)
2
+ NO_MATCHER_GIVEN = Object.new
3
+ def should(matcher=NO_MATCHER_GIVEN)
3
4
  MSpec.expectation
4
5
  MSpec.actions :expectation, MSpec.current.state
5
- if matcher
6
+ unless matcher.equal?(NO_MATCHER_GIVEN)
6
7
  unless matcher.matches?(self)
7
8
  SpecExpectation.fail_with(*matcher.failure_message)
8
9
  end
@@ -11,10 +12,10 @@ class Object
11
12
  end
12
13
  end
13
14
 
14
- def should_not(matcher=nil)
15
+ def should_not(matcher=NO_MATCHER_GIVEN)
15
16
  MSpec.expectation
16
17
  MSpec.actions :expectation, MSpec.current.state
17
- if matcher
18
+ unless matcher.equal?(NO_MATCHER_GIVEN)
18
19
  if matcher.matches?(self)
19
20
  SpecExpectation.fail_with(*matcher.negative_failure_message)
20
21
  end
data/lib/mspec/guards.rb CHANGED
@@ -13,4 +13,5 @@ require 'mspec/guards/runner'
13
13
  require 'mspec/guards/support'
14
14
  require 'mspec/guards/superuser'
15
15
  require 'mspec/guards/tty'
16
+ require 'mspec/guards/user'
16
17
  require 'mspec/guards/version'
@@ -123,6 +123,8 @@ class SpecGuard
123
123
  RUBY_NAME =~ /^ironruby/
124
124
  when :macruby
125
125
  RUBY_NAME =~ /^macruby/
126
+ when :maglev
127
+ RUBY_NAME =~ /^maglev/
126
128
  else
127
129
  false
128
130
  end
@@ -0,0 +1,17 @@
1
+ require 'mspec/guards/guard'
2
+
3
+ class UserGuard < SpecGuard
4
+ def match?
5
+ Process.euid != 0
6
+ end
7
+ end
8
+
9
+ class Object
10
+ def as_user
11
+ g = UserGuard.new
12
+ g.name = :as_user
13
+ yield if g.yield?
14
+ ensure
15
+ g.unregister
16
+ end
17
+ end
data/lib/mspec/helpers.rb CHANGED
@@ -6,10 +6,14 @@ require 'mspec/helpers/enumerator_class'
6
6
  require 'mspec/helpers/environment'
7
7
  require 'mspec/helpers/fixture'
8
8
  require 'mspec/helpers/flunk'
9
+ require 'mspec/helpers/fs'
9
10
  require 'mspec/helpers/hash'
11
+ require 'mspec/helpers/infinity'
10
12
  require 'mspec/helpers/io'
11
13
  require 'mspec/helpers/language_version'
12
14
  require 'mspec/helpers/metaclass'
15
+ require 'mspec/helpers/mock_to_path'
16
+ require 'mspec/helpers/nan'
13
17
  require 'mspec/helpers/ruby_exe'
14
18
  require 'mspec/helpers/scratch'
15
19
  require 'mspec/helpers/tmp'
@@ -0,0 +1,58 @@
1
+ class Object
2
+ # Copies a file
3
+ def cp(source, dest)
4
+ File.open(dest, "w") do |d|
5
+ File.open(source, "r") do |s|
6
+ while data = s.read(1024)
7
+ d.write data
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ # Creates each directory in path that does not exist.
14
+ def mkdir_p(path)
15
+ parts = File.expand_path(path).split %r[/|\\]
16
+ name = parts.shift
17
+ parts.each do |part|
18
+ name = File.join name, part
19
+
20
+ if File.file? name
21
+ raise ArgumentError, "path component of #{path} is a file"
22
+ end
23
+
24
+ Dir.mkdir name unless File.directory? name
25
+ end
26
+ end
27
+
28
+ # Recursively removes all files and directories in +path+
29
+ # if +path+ is a directory. Removes the file if +path+ is
30
+ # a file.
31
+ def rm_r(*paths)
32
+ paths.each do |path|
33
+ path = File.expand_path path
34
+
35
+ prefix = SPEC_TEMP_DIR
36
+ unless path[0, prefix.size] == prefix
37
+ raise ArgumentError, "#{path} is not prefixed by #{prefix}"
38
+ end
39
+
40
+ if File.directory? path
41
+ Dir.entries(path).each { |x| rm_r "#{path}/#{x}" unless x =~ /^\.\.?$/ }
42
+ Dir.rmdir path
43
+ elsif File.exists? path
44
+ File.delete path
45
+ end
46
+ end
47
+ end
48
+
49
+ # Creates a file +name+. Creates the directory for +name+
50
+ # if it does not exist.
51
+ def touch(name)
52
+ mkdir_p File.dirname(name)
53
+
54
+ File.open(name, "w") do |f|
55
+ yield f if block_given?
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ class Object
2
+ def infinity_value
3
+ 1/0.0
4
+ end
5
+ end
@@ -10,11 +10,21 @@ class Object
10
10
  #
11
11
  # Then add a file "language/versions/method_1.8.rb" for the specs that are
12
12
  # syntax-compatible with Ruby 1.8.x.
13
+ #
14
+ # The most version-specific file will be loaded. If the version is 1.8.6,
15
+ # "method_1.8.6.rb" will be loaded if it exists, otherwise "method_1.8.rb"
16
+ # will be loaded if it exists.
13
17
  def language_version(dir, name)
14
18
  path = File.dirname(File.expand_path(dir))
15
- name = "#{name}_#{SpecGuard.ruby_version}.rb"
16
- file = File.join path, "versions", name
17
19
 
18
- require file if File.exists? file
20
+ [SpecGuard.ruby_version(:tiny), SpecGuard.ruby_version].each do |version|
21
+ file = File.join path, "versions", "#{name}_#{version}.rb"
22
+ if File.exists? file
23
+ require file
24
+ break
25
+ end
26
+ end
27
+
28
+ nil
19
29
  end
20
30
  end
@@ -0,0 +1,7 @@
1
+ class Object
2
+ def mock_to_path(path)
3
+ obj = mock('path')
4
+ obj.should_receive(:to_path).and_return(path)
5
+ obj
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class Object
2
+ def nan_value
3
+ 0/0.0
4
+ end
5
+ end
@@ -76,6 +76,8 @@ class Object
76
76
  "bin/rbx"
77
77
  when 'jruby'
78
78
  "bin/jruby"
79
+ when 'maglev'
80
+ "maglev-ruby"
79
81
  when 'ironruby'
80
82
  "ir"
81
83
  end
@@ -1,32 +1,32 @@
1
- # The #tmp method provides a similar functionality
2
- # to that of Dir.tmpdir. This helper can be overridden
3
- # by different implementations to provide a more useful
4
- # behavior if needed.
5
- #
6
- # Usage in a spec:
7
- #
8
- # File.open(tmp("tags.txt"), "w") { |f| f.puts "" }
9
- #
10
- # The order of directories below with "/private/tmp"
11
- # preceding "/tmp" is significant. On OS X, the directory
12
- # "/tmp" is a symlink to "private/tmp" with no leading
13
- # "/". Rather than futzing with what constitutes an
14
- # absolute path, we just look for "/private/tmp" first.
1
+ # Creates a temporary directory in the current working directory
2
+ # for temporary files created while running the specs. All specs
3
+ # should clean up any temporary files created so that the temp
4
+ # directory is empty when the process exits.
5
+
6
+ SPEC_TEMP_DIR = "#{File.expand_path(Dir.pwd)}/rubyspec_temp"
7
+
8
+ at_exit do
9
+ begin
10
+ Dir.delete SPEC_TEMP_DIR if File.directory? SPEC_TEMP_DIR
11
+ rescue SystemCallError
12
+ STDERR.puts <<-EOM
13
+
14
+ -----------------------------------------------------
15
+ The rubyspec temp directory is not empty. Ensure that
16
+ all specs are cleaning up temporary files.
17
+ -----------------------------------------------------
18
+
19
+ EOM
20
+ rescue Object => e
21
+ STDERR.puts "failed to remove spec temp directory"
22
+ STDERR.puts e.message
23
+ end
24
+ end
15
25
 
16
26
  class Object
17
27
  def tmp(name)
18
- unless @spec_temp_directory
19
- [ "/private/tmp", "/tmp", "/var/tmp", ENV["TMPDIR"], ENV["TMP"],
20
- ENV["TEMP"], ENV["USERPROFILE"] ].each do |dir|
21
- if dir and File.directory?(dir) and File.writable?(dir)
22
- temp = File.expand_path dir
23
- temp = File.readlink temp if File.symlink? temp
24
- @spec_temp_directory = temp
25
- break
26
- end
27
- end
28
- end
28
+ Dir.mkdir SPEC_TEMP_DIR unless File.exists? SPEC_TEMP_DIR
29
29
 
30
- File.join @spec_temp_directory, name
30
+ File.join SPEC_TEMP_DIR, name
31
31
  end
32
32
  end
@@ -1,6 +1,10 @@
1
1
  require 'mspec/expectations/expectations'
2
2
  require 'mspec/helpers/metaclass'
3
3
 
4
+ class Object
5
+ alias_method :__mspec_object_id__, :object_id
6
+ end
7
+
4
8
  module Mock
5
9
  def self.reset
6
10
  @mocks = @stubs = @objects = nil
@@ -19,7 +23,7 @@ module Mock
19
23
  end
20
24
 
21
25
  def self.replaced_name(obj, sym)
22
- :"__mspec_#{obj.__id__}_#{sym}__"
26
+ :"__mspec_#{obj.__mspec_object_id__}_#{sym}__"
23
27
  end
24
28
 
25
29
  def self.replaced_key(obj, sym)
@@ -166,7 +170,7 @@ module Mock
166
170
  sym = key.last
167
171
  meta = obj.metaclass
168
172
 
169
- if meta.instance_methods.map { |x| x.to_sym }.include?(replaced)
173
+ if mock_respond_to? obj, replaced
170
174
  meta.__send__ :alias_method, sym, replaced
171
175
  meta.__send__ :remove_method, replaced
172
176
  else
@@ -32,9 +32,9 @@ class ContextState
32
32
  @parents = [self]
33
33
  @children = []
34
34
 
35
- @mock_verify = lambda { Mock.verify_count }
36
- @mock_cleanup = lambda { Mock.cleanup }
37
- @expectation_missing = lambda { raise SpecExpectationNotFoundError }
35
+ @mock_verify = Proc.new { Mock.verify_count }
36
+ @mock_cleanup = Proc.new { Mock.cleanup }
37
+ @expectation_missing = Proc.new { raise SpecExpectationNotFoundError }
38
38
  end
39
39
 
40
40
  # Returns true if this is a shared +ContextState+. Essentially, when
@@ -57,6 +57,12 @@ class ContextState
57
57
  end
58
58
  end
59
59
 
60
+ def replace_parent(parent)
61
+ @parents[0] = parent
62
+
63
+ children.each { |child| child.replace_parent parent }
64
+ end
65
+
60
66
  # Add the ContextState instance +child+ to the list of nested
61
67
  # describe blocks.
62
68
  def child(child)
@@ -124,6 +130,14 @@ class ContextState
124
130
  state.before(:each).each { |b| before :each, &b }
125
131
  state.after(:each).each { |b| after :each, &b }
126
132
  state.after(:all).each { |b| after :all, &b }
133
+
134
+ # There is a potential race here if mspec ever implements concurrency
135
+ # in process. Right now, the only way to run specs concurrently is
136
+ # with multiple processes, so we ignore this for the sake of simplicity.
137
+ state.children.each do |child|
138
+ child.replace_parent self
139
+ @children << child
140
+ end
127
141
  end
128
142
 
129
143
  # Evaluates each block in +blocks+ using the +MSpec.protect+ method
@@ -19,6 +19,10 @@ class Object
19
19
  MSpec.current.it_should_behave_like desc
20
20
  end
21
21
 
22
+ # For ReadRuby compatiability
23
+ def doc(*a)
24
+ end
25
+
22
26
  alias_method :context, :describe
23
27
  alias_method :specify, :it
24
28
  end
@@ -221,6 +221,8 @@ class MSpecOptions
221
221
  config[:target] = 'jruby'
222
222
  when 'i','ironruby'
223
223
  config[:target] = 'ir'
224
+ when 'm','maglev'
225
+ config[:target] = 'maglev-ruby'
224
226
  else
225
227
  config[:target] = t
226
228
  end
@@ -233,6 +235,7 @@ class MSpecOptions
233
235
  doc " X or rbx invokes rbx in PATH"
234
236
  doc " j or jruby invokes jruby in PATH"
235
237
  doc " i or ironruby invokes ir in PATH"
238
+ doc " m or maglev invokes maglev-ruby in PATH"
236
239
  doc " full path to EXE invokes EXE directly\n"
237
240
 
238
241
  on("-T", "--target-opt", "OPT",
data/lib/mspec/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'mspec/utils/version'
2
2
 
3
3
  module MSpec
4
- VERSION = SpecVersion.new "1.5.12"
4
+ VERSION = SpecVersion.new "1.5.13"
5
5
  end
@@ -270,11 +270,11 @@ describe "The -D, --gdb option" do
270
270
  @script.options
271
271
  end
272
272
 
273
- it "sets flags to --gdb" do
273
+ it "sets use_gdb to true" do
274
274
  ["-D", "--gdb"].each do |opt|
275
- @config[:flags] = []
275
+ @config[:use_gdb] = false
276
276
  @script.options [opt]
277
- @config[:flags].should include("--gdb")
277
+ @config[:use_gdb].should be_true
278
278
  end
279
279
  end
280
280
  end
@@ -180,6 +180,11 @@ describe SpecGuard, "#implementation?" do
180
180
  @guard.implementation?(:ironruby).should == true
181
181
  end
182
182
 
183
+ it "returns true if passed :maglev and RUBY_NAME == 'maglev'" do
184
+ Object.const_set :RUBY_NAME, 'maglev'
185
+ @guard.implementation?(:maglev).should == true
186
+ end
187
+
183
188
  it "returns true if passed :ruby and RUBY_NAME matches /^ruby/" do
184
189
  Object.const_set :RUBY_NAME, 'ruby'
185
190
  @guard.implementation?(:ruby).should == true
@@ -238,7 +243,7 @@ describe SpecGuard, "#platform?" do
238
243
  end
239
244
 
240
245
  it "returns false when no arg matches RUBY_PLATFORM" do
241
- @guard.platform?(:ruby, :jruby, :rubinius).should == false
246
+ @guard.platform?(:ruby, :jruby, :rubinius, :maglev).should == false
242
247
  end
243
248
 
244
249
  it "returns true when arg matches RUBY_PLATFORM" do
@@ -246,7 +251,7 @@ describe SpecGuard, "#platform?" do
246
251
  end
247
252
 
248
253
  it "returns true when any arg matches RUBY_PLATFORM" do
249
- @guard.platform?(:ruby, :jruby, :solarce, :rubinius).should == true
254
+ @guard.platform?(:ruby, :jruby, :solarce, :rubinius, :maglev).should == true
250
255
  end
251
256
 
252
257
  it "returns true when arg is :windows and RUBY_PLATFORM contains 'mswin'" do
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/guards/user'
3
+
4
+ describe Object, "#as_user" do
5
+ before :each do
6
+ @guard = UserGuard.new
7
+ UserGuard.stub!(:new).and_return(@guard)
8
+ ScratchPad.clear
9
+ end
10
+
11
+ it "yields when the Process.euid is not 0" do
12
+ Process.stub!(:euid).and_return(501)
13
+ as_user { ScratchPad.record :yield }
14
+ ScratchPad.recorded.should == :yield
15
+ end
16
+
17
+ it "does not yield when the Process.euid is 0" do
18
+ Process.stub!(:euid).and_return(0)
19
+ as_user { ScratchPad.record :yield }
20
+ ScratchPad.recorded.should_not == :yield
21
+ end
22
+
23
+ it "sets the name of the guard to :as_user" do
24
+ as_user { }
25
+ @guard.name.should == :as_user
26
+ end
27
+
28
+ it "calls #unregister even when an exception is raised in the guard block" do
29
+ @guard.should_receive(:match?).and_return(true)
30
+ @guard.should_receive(:unregister)
31
+ lambda do
32
+ as_user { raise Exception }
33
+ end.should raise_error(Exception)
34
+ end
35
+ end
@@ -0,0 +1,160 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/helpers/tmp'
3
+ require 'mspec/helpers/fs'
4
+
5
+ describe Object, "#cp" do
6
+ before :each do
7
+ @source = tmp("source.txt")
8
+ @copy = tmp("copied.txt")
9
+
10
+ @contents = "This is a copy."
11
+ File.open(@source, "w") { |f| f.write @contents }
12
+ end
13
+
14
+ after :each do
15
+ File.delete @source if File.exists? @source
16
+ File.delete @copy if File.exists? @copy
17
+ end
18
+
19
+ it "copies a file" do
20
+ cp @source, @copy
21
+ data = IO.read(@copy)
22
+ data.should == @contents
23
+ data.should == IO.read(@source)
24
+ end
25
+ end
26
+
27
+ describe Object, "#touch" do
28
+ before :all do
29
+ @name = tmp("touched.txt")
30
+ end
31
+
32
+ after :each do
33
+ File.delete @name if File.exists? @name
34
+ end
35
+
36
+ it "creates a file" do
37
+ touch @name
38
+ File.exists?(@name).should be_true
39
+ end
40
+
41
+ it "overwrites an existing file" do
42
+ File.open(@name, "w") { |f| f.puts "used" }
43
+ File.size(@name).should > 0
44
+
45
+ touch @name
46
+ File.size(@name).should == 0
47
+ end
48
+
49
+ it "yields the open file if passed a block" do
50
+ touch(@name) { |f| f.write "touching" }
51
+ IO.read(@name).should == "touching"
52
+ end
53
+ end
54
+
55
+ describe Object, "#touch" do
56
+ before :all do
57
+ @dir = tmp("subdir")
58
+ @name = tmp("subdir/touched.txt")
59
+ end
60
+
61
+ after :each do
62
+ File.delete @name if File.exists? @name
63
+ Dir.rmdir @dir if File.directory? @dir
64
+ end
65
+
66
+ it "creates all the directories in the path to the file" do
67
+ touch @name
68
+ File.exists?(@name).should be_true
69
+ end
70
+ end
71
+
72
+ describe Object, "#mkdir_p" do
73
+ before :all do
74
+ @dir1 = tmp("/nested")
75
+ @dir2 = @dir1 + "/directory"
76
+ @paths = [ @dir2, @dir1 ]
77
+ end
78
+
79
+ after :each do
80
+ File.delete @dir1 if File.file? @dir1
81
+ @paths.each { |path| Dir.rmdir path if File.directory? path }
82
+ end
83
+
84
+ it "creates all the directories in a path" do
85
+ mkdir_p @dir2
86
+ File.directory?(@dir2).should be_true
87
+ end
88
+
89
+ it "raises an ArgumentError if a path component is a file" do
90
+ File.open(@dir1, "w") { |f| }
91
+ lambda { mkdir_p @dir2 }.should raise_error(ArgumentError)
92
+ end
93
+ end
94
+
95
+ describe Object, "#rm_r" do
96
+ before :all do
97
+ @topdir = tmp("rm_r_tree")
98
+ @topfile = @topdir + "/file.txt"
99
+ @link = @topdir + "/file.lnk"
100
+ @socket = @topdir + "/socket.sck"
101
+ @subdir1 = @topdir + "/subdir1"
102
+ @subdir2 = @subdir1 + "/subdir2"
103
+ @subfile = @subdir1 + "/subfile.txt"
104
+ end
105
+
106
+ before :each do
107
+ mkdir_p @subdir2
108
+ touch @topfile
109
+ touch @subfile
110
+ end
111
+
112
+ after :each do
113
+ File.delete @link if File.exists? @link
114
+ File.delete @socket if File.exists? @socket
115
+ File.delete @subfile if File.exists? @subfile
116
+ File.delete @topfile if File.exists? @topfile
117
+
118
+ Dir.rmdir @subdir2 if File.directory? @subdir2
119
+ Dir.rmdir @subdir1 if File.directory? @subdir1
120
+ Dir.rmdir @topdir if File.directory? @topdir
121
+ end
122
+
123
+ it "raises an ArgumentError if the path is not prefixed by MSPEC_RM_PREFIX" do
124
+ lambda { rm_r "some_file.txt" }.should raise_error(ArgumentError)
125
+ end
126
+
127
+ it "removes a single file" do
128
+ rm_r @subfile
129
+ File.exists?(@subfile).should be_false
130
+ end
131
+
132
+ it "removes multiple files" do
133
+ rm_r @topfile, @subfile
134
+ File.exists?(@topfile).should be_false
135
+ File.exists?(@subfile).should be_false
136
+ end
137
+
138
+ it "removes a symlink" do
139
+ File.symlink @topfile, @link
140
+ rm_r @link
141
+ File.exists?(@link).should be_false
142
+ end
143
+
144
+ it "removes a socket" do
145
+ require 'socket'
146
+ UNIXServer.new(@socket).close
147
+ rm_r @socket
148
+ File.exists?(@socket).should be_false
149
+ end
150
+
151
+ it "removes a single directory" do
152
+ rm_r @subdir2
153
+ File.directory?(@subdir2).should be_false
154
+ end
155
+
156
+ it "recursively removes a directory tree" do
157
+ rm_r @topdir
158
+ File.directory?(@topdir).should be_false
159
+ end
160
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/helpers/infinity'
3
+
4
+ describe Object, "#infinity_value" do
5
+ it "returns Infinity" do
6
+ infinity_value.infinite?.should == 1
7
+ end
8
+ end
@@ -7,23 +7,33 @@ describe Object, "#language_version" do
7
7
 
8
8
  Object.const_set :RUBY_VERSION, "8.2.3"
9
9
 
10
- dir = File.dirname(File.expand_path(__FILE__))
11
- @name = "#{dir}/versions/method_8.2.rb"
10
+ dir = "#{File.expand_path('../', __FILE__)}/versions"
11
+ @method82 = "#{dir}/method_8.2.rb"
12
+ @method823 = "#{dir}/method_8.2.3.rb"
12
13
  end
13
14
 
14
15
  after :all do
15
16
  Object.const_set :RUBY_VERSION, @ruby_version
16
17
  end
17
18
 
18
- it "loads files conditionally based on name and RUBY_VERSION if it exists" do
19
- File.should_receive(:exists?).with(@name).and_return(true)
20
- should_receive(:require).with(@name)
19
+ it "loads the most version-specific file if it exists" do
20
+ File.should_receive(:exists?).with(@method823).and_return(true)
21
+ should_receive(:require).with(@method823)
22
+ language_version __FILE__, "method"
23
+ end
24
+
25
+ it "loads a less version-specific file if it exists" do
26
+ File.should_receive(:exists?).with(@method823).and_return(false)
27
+ File.should_receive(:exists?).with(@method82).and_return(true)
28
+ should_receive(:require).with(@method82)
21
29
  language_version __FILE__, "method"
22
30
  end
23
31
 
24
32
  it "does not load the file if it does not exist" do
25
- File.should_receive(:exists?).with(@name).and_return(false)
26
- should_not_receive(:require).with(@name)
33
+ File.should_receive(:exists?).with(@method82).and_return(false)
34
+ File.should_receive(:exists?).with(@method823).and_return(false)
35
+ should_not_receive(:require).with(@method82)
36
+ should_not_receive(:require).with(@method823)
27
37
  language_version __FILE__, "method"
28
38
  end
29
39
  end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/helpers/mock_to_path'
3
+
4
+ describe Object, "#mock_to_path" do
5
+ it "returns an object that responds to #to_path" do
6
+ obj = mock_to_path("foo")
7
+ obj.should respond_to(:to_path)
8
+ obj.to_path
9
+ end
10
+
11
+ it "returns the provided path when #to_path is called" do
12
+ obj = mock_to_path("/tmp/foo")
13
+ obj.to_path.should == "/tmp/foo"
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/helpers/nan'
3
+
4
+ describe Object, "#nan_value" do
5
+ it "returns NaN" do
6
+ nan_value.nan?.should be_true
7
+ end
8
+ end
@@ -46,6 +46,11 @@ describe "#ruby_exe_options" do
46
46
  @script.ruby_exe_options(:engine).should == 'ir'
47
47
  end
48
48
 
49
+ it "returns 'maglev-ruby' when passed :engine and RUBY_NAME is 'maglev'" do
50
+ Object.const_set :RUBY_NAME, 'maglev'
51
+ @script.ruby_exe_options(:engine).should == 'maglev-ruby'
52
+ end
53
+
49
54
  it "returns RUBY_NAME + $(EXEEXT) when passed :name" do
50
55
  bin = RUBY_NAME + (Config::CONFIG['EXEEXT'] || Config::CONFIG['exeext'] || '')
51
56
  name = File.join ".", bin
@@ -2,71 +2,9 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require 'mspec/helpers/tmp'
3
3
 
4
4
  describe Object, "#tmp" do
5
- before :each do
6
- File.stub!(:directory?).and_return(false)
7
- File.stub!(:symlink?).and_return(false)
8
- ENV.stub!(:[]).and_return(nil)
9
- end
10
-
11
- it "returns /tmp/<name> if /tmp is a writable directory" do
12
- dir = "/tmp"
13
- File.should_receive(:directory?).with(dir).and_return(true)
14
- File.should_receive(:writable?).with(dir).and_return(true)
15
- File.should_receive(:expand_path).with(dir).and_return(dir)
16
- tmp("test.txt").should == dir + "/test.txt"
17
- end
18
-
19
- it "returns /var/tmp/<name> if /var/tmp is a writable directory" do
20
- dir = "/var/tmp"
21
- File.should_receive(:directory?).with(dir).and_return(true)
22
- File.should_receive(:writable?).with(dir).and_return(true)
23
- File.should_receive(:expand_path).with(dir).and_return(dir)
24
- tmp("test.txt").should == dir + "/test.txt"
25
- end
26
-
27
- it "returns ENV['TMPDIR']/<name> if ENV['TMPDIR'] is a writable directory" do
28
- dir = "/tmpdir"
29
- ENV.should_receive(:[]).with("TMPDIR").and_return(dir)
30
- File.should_receive(:directory?).with(dir).and_return(true)
31
- File.should_receive(:writable?).with(dir).and_return(true)
32
- File.should_receive(:expand_path).with(dir).and_return(dir)
33
- tmp("test.txt").should == dir + "/test.txt"
34
- end
5
+ it "returns a name relative to the current working directory" do
6
+ dir = "#{File.expand_path(Dir.pwd)}/rubyspec_temp"
35
7
 
36
- it "returns ENV['TMP']/<name> if ENV['TMP'] is a writable directory" do
37
- dir = "/tmp/tmp"
38
- ENV.should_receive(:[]).with("TMP").and_return(dir)
39
- File.should_receive(:directory?).with(dir).and_return(true)
40
- File.should_receive(:writable?).with(dir).and_return(true)
41
- File.should_receive(:expand_path).with(dir).and_return(dir)
42
8
  tmp("test.txt").should == dir + "/test.txt"
43
9
  end
44
-
45
- it "returns ENV['TEMP']/<name> if ENV['TEMP'] is a writable directory" do
46
- dir = "/tmp/temp"
47
- ENV.should_receive(:[]).with("TEMP").and_return(dir)
48
- File.should_receive(:directory?).with(dir).and_return(true)
49
- File.should_receive(:writable?).with(dir).and_return(true)
50
- File.should_receive(:expand_path).with(dir).and_return(dir)
51
- tmp("test.txt").should == dir + "/test.txt"
52
- end
53
-
54
- it "returns ENV['USERPROFILE']/<name> if ENV['USERPROFILE'] is a writable directory" do
55
- dir = "/tmp/temp"
56
- ENV.should_receive(:[]).with("TEMP").and_return(dir)
57
- File.should_receive(:directory?).with(dir).and_return(true)
58
- File.should_receive(:writable?).with(dir).and_return(true)
59
- File.should_receive(:expand_path).with(dir).and_return(dir)
60
- tmp("test.txt").should == dir + "/test.txt"
61
- end
62
-
63
- it "returns the actual file name if the file is a symlink" do
64
- dir = "/tmp"
65
- File.should_receive(:directory?).with(dir).and_return(true)
66
- File.should_receive(:writable?).with(dir).and_return(true)
67
- File.should_receive(:expand_path).with(dir).and_return(dir)
68
- File.should_receive(:symlink?).with(dir).and_return(true)
69
- File.should_receive(:readlink).with(dir).and_return("/ponies"+dir)
70
- tmp("test.txt").should == "/ponies" + dir + "/test.txt"
71
- end
72
10
  end
@@ -22,7 +22,7 @@ end
22
22
  describe Mock, ".replaced_name" do
23
23
  it "returns the name for a method that is being replaced by a mock method" do
24
24
  m = mock('a fake id')
25
- m.stub!(:__id__).and_return(42)
25
+ m.stub!(:__mspec_object_id__).and_return(42)
26
26
  Mock.replaced_name(m, :method_call).should == :__mspec_42_method_call__
27
27
  end
28
28
  end
@@ -30,7 +30,7 @@ end
30
30
  describe Mock, ".replaced_key" do
31
31
  it "returns a key used internally by Mock" do
32
32
  m = mock('a fake id')
33
- m.stub!(:__id__).and_return(42)
33
+ m.stub!(:__mspec_object_id__).and_return(42)
34
34
  Mock.replaced_key(m, :method_call).should == [:__mspec_42_method_call__, :method_call]
35
35
  end
36
36
  end
@@ -910,7 +910,8 @@ end
910
910
 
911
911
  describe ContextState, "#it_should_behave_like" do
912
912
  before :each do
913
- @shared = ContextState.new("", :shared => true)
913
+ @shared_desc = "shared context"
914
+ @shared = ContextState.new(@shared_desc, :shared => true)
914
915
  MSpec.stub!(:retrieve_shared).and_return(@shared)
915
916
 
916
917
  @state = ContextState.new ""
@@ -923,10 +924,30 @@ describe ContextState, "#it_should_behave_like" do
923
924
  lambda { @state.it_should_behave_like "this" }.should raise_error(Exception)
924
925
  end
925
926
 
927
+ describe "for nested ContextState instances" do
928
+ before :each do
929
+ @nested = ContextState.new ""
930
+ @nested.parents.unshift @shared
931
+ @shared.children << @nested
932
+ end
933
+
934
+ it "adds nested describe blocks to the invoking ContextState" do
935
+ @state.it_should_behave_like @shared_desc
936
+ @shared.children.should_not be_empty
937
+ @state.children.should include(*@shared.children)
938
+ end
939
+
940
+ it "changes the parent ContextState" do
941
+ @shared.children.first.parents.first.should equal(@shared)
942
+ @state.it_should_behave_like @shared_desc
943
+ @shared.children.first.parents.first.should equal(@state)
944
+ end
945
+ end
946
+
926
947
  it "adds examples from the shared ContextState" do
927
948
  @shared.it "some", &@a
928
949
  @shared.it "thing", &@b
929
- @state.it_should_behave_like ""
950
+ @state.it_should_behave_like @shared_desc
930
951
  @state.examples.should include(*@shared.examples)
931
952
  end
932
953
 
@@ -934,34 +955,34 @@ describe ContextState, "#it_should_behave_like" do
934
955
  @shared.it "some", &@a
935
956
  @shared.it "thing", &@b
936
957
  @shared.examples.each { |ex| ex.should_receive(:context=).with(@state) }
937
- @state.it_should_behave_like ""
958
+ @state.it_should_behave_like @shared_desc
938
959
  end
939
960
 
940
961
  it "adds before(:all) blocks from the shared ContextState" do
941
962
  @shared.before :all, &@a
942
963
  @shared.before :all, &@b
943
- @state.it_should_behave_like ""
964
+ @state.it_should_behave_like @shared_desc
944
965
  @state.before(:all).should include(*@shared.before(:all))
945
966
  end
946
967
 
947
968
  it "adds before(:each) blocks from the shared ContextState" do
948
969
  @shared.before :each, &@a
949
970
  @shared.before :each, &@b
950
- @state.it_should_behave_like ""
971
+ @state.it_should_behave_like @shared_desc
951
972
  @state.before(:each).should include(*@shared.before(:each))
952
973
  end
953
974
 
954
975
  it "adds after(:each) blocks from the shared ContextState" do
955
976
  @shared.after :each, &@a
956
977
  @shared.after :each, &@b
957
- @state.it_should_behave_like ""
978
+ @state.it_should_behave_like @shared_desc
958
979
  @state.after(:each).should include(*@shared.after(:each))
959
980
  end
960
981
 
961
982
  it "adds after(:all) blocks from the shared ContextState" do
962
983
  @shared.after :all, &@a
963
984
  @shared.after :all, &@b
964
- @state.it_should_behave_like ""
985
+ @state.it_should_behave_like @shared_desc
965
986
  @state.after(:all).should include(*@shared.after(:all))
966
987
  end
967
988
  end
@@ -587,6 +587,15 @@ describe "The -t, --target TARGET option" do
587
587
  end
588
588
  end
589
589
 
590
+ it "sets the target to 'maglev' with TARGET 'm' or 'maglev'" do
591
+ ["-t", "--target"].each do |opt|
592
+ ["m", "maglev"].each do |t|
593
+ @options.parse [opt, t]
594
+ @config[:target].should == "maglev-ruby"
595
+ end
596
+ end
597
+ end
598
+
590
599
  it "sets the target to TARGET" do
591
600
  ["-t", "--target"].each do |opt|
592
601
  @options.parse [opt, "whateva"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.12
4
+ version: 1.5.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Ford
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-08 00:00:00 -07:00
12
+ date: 2009-12-25 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -49,6 +49,7 @@ files:
49
49
  - lib/mspec/guards/superuser.rb
50
50
  - lib/mspec/guards/support.rb
51
51
  - lib/mspec/guards/tty.rb
52
+ - lib/mspec/guards/user.rb
52
53
  - lib/mspec/guards/version.rb
53
54
  - lib/mspec/guards.rb
54
55
  - lib/mspec/helpers/argv.rb
@@ -59,10 +60,14 @@ files:
59
60
  - lib/mspec/helpers/environment.rb
60
61
  - lib/mspec/helpers/fixture.rb
61
62
  - lib/mspec/helpers/flunk.rb
63
+ - lib/mspec/helpers/fs.rb
62
64
  - lib/mspec/helpers/hash.rb
65
+ - lib/mspec/helpers/infinity.rb
63
66
  - lib/mspec/helpers/io.rb
64
67
  - lib/mspec/helpers/language_version.rb
65
68
  - lib/mspec/helpers/metaclass.rb
69
+ - lib/mspec/helpers/mock_to_path.rb
70
+ - lib/mspec/helpers/nan.rb
66
71
  - lib/mspec/helpers/ruby_exe.rb
67
72
  - lib/mspec/helpers/scratch.rb
68
73
  - lib/mspec/helpers/tmp.rb
@@ -173,6 +178,7 @@ files:
173
178
  - spec/guards/superuser_spec.rb
174
179
  - spec/guards/support_spec.rb
175
180
  - spec/guards/tty_spec.rb
181
+ - spec/guards/user_spec.rb
176
182
  - spec/guards/version_spec.rb
177
183
  - spec/helpers/argv_spec.rb
178
184
  - spec/helpers/bignum_spec.rb
@@ -182,9 +188,13 @@ files:
182
188
  - spec/helpers/environment_spec.rb
183
189
  - spec/helpers/fixture_spec.rb
184
190
  - spec/helpers/flunk_spec.rb
191
+ - spec/helpers/fs_spec.rb
185
192
  - spec/helpers/hash_spec.rb
193
+ - spec/helpers/infinity_spec.rb
186
194
  - spec/helpers/io_spec.rb
187
195
  - spec/helpers/language_version_spec.rb
196
+ - spec/helpers/mock_to_path_spec.rb
197
+ - spec/helpers/nan_spec.rb
188
198
  - spec/helpers/ruby_exe_spec.rb
189
199
  - spec/helpers/scratch_spec.rb
190
200
  - spec/helpers/tmp_spec.rb
@@ -257,6 +267,8 @@ files:
257
267
  - LICENSE
258
268
  has_rdoc: true
259
269
  homepage: http://rubyspec.org
270
+ licenses: []
271
+
260
272
  post_install_message:
261
273
  rdoc_options:
262
274
  - --title
@@ -281,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
281
293
  requirements: []
282
294
 
283
295
  rubyforge_project: http://rubyforge.org/projects/mspec
284
- rubygems_version: 1.3.1
296
+ rubygems_version: 1.3.5
285
297
  signing_key:
286
298
  specification_version: 2
287
299
  summary: 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.