mspec 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'spec/rake/spectask'
3
3
  require 'rake/gempackagetask'
4
+
5
+ $:.unshift File.expand_path(File.dirname(__FILE__) + '/lib')
4
6
  require 'lib/mspec/version'
5
7
 
6
8
  Spec::Rake::SpecTask.new
@@ -10,13 +12,13 @@ task :default => :spec
10
12
 
11
13
  spec = Gem::Specification.new do |s|
12
14
  s.name = %q{mspec}
13
- s.version = MSpec::VERSION
15
+ s.version = MSpec::VERSION.to_s
14
16
 
15
17
  s.specification_version = 2 if s.respond_to? :specification_version=
16
18
 
17
19
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
18
20
  s.authors = ["Brian Ford"]
19
- s.date = %q{2008-12-1}
21
+ s.date = %q{2008-12-29}
20
22
  s.email = %q{bford@engineyard.com}
21
23
  s.has_rdoc = true
22
24
  s.extra_rdoc_files = %w[ README LICENSE ]
@@ -21,6 +21,7 @@ class MSpecCI < MSpecScript
21
21
  options.configure { |f| load f }
22
22
  options.name
23
23
  options.pretend
24
+ options.unguarded
24
25
  options.interrupt
25
26
 
26
27
  options.doc "\n How to display their output"
@@ -32,6 +32,7 @@ class MSpecRun < MSpecScript
32
32
  options.name
33
33
  options.randomize
34
34
  options.pretend
35
+ options.unguarded
35
36
  options.interrupt
36
37
 
37
38
  options.doc "\n How to display their output"
@@ -32,6 +32,7 @@ class MSpecTag < MSpecScript
32
32
  options.configure { |f| load f }
33
33
  options.name
34
34
  options.pretend
35
+ options.unguarded
35
36
  options.interrupt
36
37
 
37
38
  options.doc "\n How to display their output"
@@ -105,6 +106,7 @@ class MSpecTag < MSpecScript
105
106
  when :purge
106
107
  tagger = TagPurgeAction.new
107
108
  MSpec.register_mode :pretend
109
+ MSpec.register_mode :unguarded
108
110
  config[:formatter] = false
109
111
  else
110
112
  raise ArgumentError, "No recognized action given"
@@ -53,7 +53,7 @@ class MSpecMain < MSpecScript
53
53
  if config[:command]
54
54
  config[:options] << "-v"
55
55
  else
56
- puts options
56
+ puts "#{File.basename $0} #{MSpec::VERSION}"
57
57
  exit
58
58
  end
59
59
  end
@@ -1,6 +1,8 @@
1
- require 'mspec/ruby_name'
1
+ require 'mspec/utils/ruby_name'
2
2
  require 'mspec/guards/bug'
3
3
  require 'mspec/guards/compliance'
4
+ require 'mspec/guards/conflict'
5
+ require 'mspec/guards/endian'
4
6
  require 'mspec/guards/extensions'
5
7
  require 'mspec/guards/guard'
6
8
  require 'mspec/guards/noncompliance'
@@ -8,7 +10,6 @@ require 'mspec/guards/platform'
8
10
  require 'mspec/guards/quarantine'
9
11
  require 'mspec/guards/runner'
10
12
  require 'mspec/guards/support'
11
- require 'mspec/guards/endian'
12
13
  require 'mspec/guards/superuser'
13
- require 'mspec/guards/conflict'
14
+ require 'mspec/guards/tty'
14
15
  require 'mspec/guards/version'
@@ -3,14 +3,7 @@ require 'mspec/guards/version'
3
3
  class BugGuard < VersionGuard
4
4
  def initialize(bug, version)
5
5
  @bug = bug
6
- @version = to_v version
7
- end
8
-
9
- def to_v(str)
10
- major, minor, tiny, patch = str.split "."
11
- tiny = 99 unless tiny
12
- patch = 9999 unless patch
13
- ("1%02d%02d%02d%04d" % [major, minor, tiny, patch].map { |x| x.to_i }).to_i
6
+ @version = SpecVersion.new version, true
14
7
  end
15
8
 
16
9
  def match?
@@ -19,16 +19,47 @@ class SpecGuard
19
19
  print "\n#{self.class}\n#{@tally.format}\n"
20
20
  end
21
21
 
22
+ # Returns a partial Ruby version string based on +which+. For example,
23
+ # if RUBY_VERSION = 8.2.3 and RUBY_PATCHLEVEL = 71:
24
+ #
25
+ # :major => "8"
26
+ # :minor => "8.2"
27
+ # :tiny => "8.2.3"
28
+ # :teeny => "8.2.3"
29
+ # :full => "8.2.3.71"
30
+ def self.ruby_version(which = :minor)
31
+ case which
32
+ when :major
33
+ n = 1
34
+ when :minor
35
+ n = 2
36
+ when :tiny, :teeny
37
+ n = 3
38
+ else
39
+ n = 4
40
+ end
41
+
42
+ version = "#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}"
43
+ version.split('.')[0,n].join('.')
44
+ end
45
+
46
+ def self.windows?(key = RUBY_PLATFORM)
47
+ !!key.match(/(mswin|mingw)/)
48
+ end
49
+
50
+
22
51
  def initialize(*args)
23
52
  @args = args
24
53
  end
25
54
 
26
55
  def yield?(invert=false)
27
- if MSpec.report_mode?
56
+ if MSpec.mode? :unguarded
57
+ return true
58
+ elsif MSpec.mode? :report
28
59
  self.class.register
29
60
  MSpec.register :before, self
30
61
  return true
31
- elsif MSpec.verify_mode?
62
+ elsif MSpec.mode? :verify
32
63
  self.class.register
33
64
  MSpec.register :after, self
34
65
  return true
@@ -75,7 +106,7 @@ class SpecGuard
75
106
  end
76
107
 
77
108
  def windows?(sym, key)
78
- sym == :windows && !!key.match(/(mswin|mingw)/)
109
+ sym == :windows && SpecGuard.windows?(key)
79
110
  end
80
111
 
81
112
  def platform?(*args)
@@ -0,0 +1,20 @@
1
+ require 'mspec/guards/guard'
2
+
3
+ # Some specs will block if run under as subprocess where STDOUT is not a TTY.
4
+ # For most specs, there is probably a way to provide an IOStub that could
5
+ # pretend to be a TTY. See the IOStub helper. That helper needs combined with
6
+ # the output_to_fd helper.
7
+
8
+ class TTYGuard < SpecGuard
9
+ def match?
10
+ STDOUT.tty?
11
+ end
12
+ end
13
+
14
+ class Object
15
+ def with_tty
16
+ g = TTYGuard.new
17
+ yield if g.yield?
18
+ g.unregister
19
+ end
20
+ end
@@ -1,32 +1,27 @@
1
+ require 'mspec/utils/version'
1
2
  require 'mspec/guards/guard'
2
3
 
3
4
  class VersionGuard < SpecGuard
4
5
  def initialize(version)
5
6
  case version
6
7
  when String
7
- @version = to_v version
8
+ @version = SpecVersion.new version
8
9
  when Range
9
- a = to_v version.first
10
- b = to_v version.last
10
+ a = SpecVersion.new version.first
11
+ b = SpecVersion.new version.last
11
12
  @version = version.exclude_end? ? a...b : a..b
12
13
  end
13
14
  end
14
15
 
15
- def to_v(str)
16
- major, minor, tiny, patch = str.split "."
17
- ("1%02d%02d%02d%04d" % [major, minor, tiny, patch].map { |x| x.to_i }).to_i
18
- end
19
-
20
16
  def ruby_version
21
- to_v("#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}")
17
+ @ruby_version ||= SpecVersion.new self.class.ruby_version(:full)
22
18
  end
23
19
 
24
20
  def match?
25
- case @version
26
- when Integer
27
- ruby_version >= @version
28
- when Range
21
+ if Range === @version
29
22
  @version.include? ruby_version
23
+ else
24
+ ruby_version >= @version
30
25
  end
31
26
  end
32
27
  end
@@ -1,9 +1,11 @@
1
+ require 'mspec/helpers/argv'
1
2
  require 'mspec/helpers/bignum'
3
+ require 'mspec/helpers/const_lookup'
4
+ require 'mspec/helpers/environment'
5
+ require 'mspec/helpers/fixture'
2
6
  require 'mspec/helpers/flunk'
3
7
  require 'mspec/helpers/io'
8
+ require 'mspec/helpers/language_version'
9
+ require 'mspec/helpers/ruby_exe'
4
10
  require 'mspec/helpers/scratch'
5
11
  require 'mspec/helpers/tmp'
6
- require 'mspec/helpers/const_lookup'
7
- require 'mspec/helpers/ruby_exe'
8
- require 'mspec/helpers/fixture'
9
- require 'mspec/helpers/argv'
@@ -0,0 +1,23 @@
1
+ require 'mspec/guards/guard'
2
+
3
+ class Object
4
+ def env
5
+ env = ""
6
+ if SpecGuard.windows?
7
+ env = Hash[*`cmd.exe /C set`.split("\n").map { |e| e.split("=", 2) }.flatten]
8
+ else
9
+ env = Hash[*`env`.split("\n").map { |e| e.split("=", 2) }.flatten]
10
+ end
11
+ env
12
+ end
13
+
14
+ def username
15
+ user = ""
16
+ if SpecGuard.windows?
17
+ user = `cmd.exe /C ECHO %USERNAME%`.strip
18
+ else
19
+ user = `whoami`.strip
20
+ end
21
+ user
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ require 'mspec/guards/guard'
2
+
3
+ class Object
4
+ # Helper for syntax-sensitive specs. The specs should be placed in a file in
5
+ # the +versions+ subdirectory. For example, suppose language/method_spec.rb
6
+ # contains specs whose syntax depends on the Ruby version. In the
7
+ # language/method_spec.rb use the helper as follows:
8
+ #
9
+ # language_version __FILE__, "method"
10
+ #
11
+ # Then add a file "language/versions/method_1.8.rb" for the specs that are
12
+ # syntax-compatible with Ruby 1.8.x.
13
+ def language_version(dir, name)
14
+ path = File.dirname(File.expand_path(dir))
15
+ name = "#{name}_#{SpecGuard.ruby_version}.rb"
16
+ file = File.join path, "versions", name
17
+
18
+ require file if File.exists? file
19
+ end
20
+ end
@@ -1,4 +1,5 @@
1
- require 'mspec/ruby_name'
1
+ require 'mspec/utils/ruby_name'
2
+ require 'mspec/guards/guard'
2
3
 
3
4
  # The ruby_exe helper provides a wrapper for invoking the
4
5
  # same Ruby interpreter as the one running the specs and
@@ -92,13 +93,11 @@ class Object
92
93
  [:env, :engine, :name, :install_name].each do |option|
93
94
  exe = ruby_exe_options option
94
95
 
95
- # TODO: It has been reported that File.executable is not reliable
96
+ # It has been reported that File.executable is not reliable
96
97
  # on Windows platforms (see commit 56bc555c). So, we check the
97
- # platform. This check is the same as the one used by the guards.
98
- # This test should be abstracted so it is available in general to
99
- # MSpec code.
98
+ # platform.
100
99
  if exe and File.exists?(exe) and
101
- (RUBY_PLATFORM.match(/(mswin|mingw)/) || File.executable?(exe))
100
+ (SpecGuard.windows? || File.executable?(exe))
102
101
  return exe
103
102
  end
104
103
  end
@@ -124,10 +124,10 @@ class ContextState
124
124
 
125
125
  # Evaluates each block in +blocks+ using the +MSpec.protect+ method
126
126
  # so that exceptions are handled and tallied. Returns true and does
127
- # NOT evaluate any blocks if +check+ is true and +MSpec.pretend_mode?+
128
- # is true.
127
+ # NOT evaluate any blocks if +check+ is true and
128
+ # <tt>MSpec.mode?(:pretend)</tt> is true.
129
129
  def protect(what, blocks, check=true)
130
- return true if check and MSpec.pretend_mode?
130
+ return true if check and MSpec.mode? :pretend
131
131
  Array(blocks).all? { |block| MSpec.protect what, &block }
132
132
  end
133
133
 
@@ -15,10 +15,10 @@ module MSpec
15
15
  @exclude = nil
16
16
  @include = nil
17
17
  @leave = nil
18
- @mode = nil
19
18
  @load = nil
20
19
  @unload = nil
21
20
  @current = nil
21
+ @modes = []
22
22
  @shared = {}
23
23
  @exception = nil
24
24
  @randomize = nil
@@ -125,8 +125,26 @@ module MSpec
125
125
  store :tags_patterns, patterns
126
126
  end
127
127
 
128
+ # Registers an operating mode. Modes recognized by MSpec:
129
+ #
130
+ # :pretend - actions execute but specs are not run
131
+ # :verify - specs are run despite guards and the result is
132
+ # verified to match the expectation of the guard
133
+ # :report - specs that are guarded are reported
134
+ # :unguarded - all guards are forced off
128
135
  def self.register_mode(mode)
129
- store :mode, mode
136
+ modes = retrieve :modes
137
+ modes << mode unless modes.include? mode
138
+ end
139
+
140
+ # Clears all registered modes.
141
+ def self.clear_modes
142
+ store :modes, []
143
+ end
144
+
145
+ # Returns +true+ if +mode+ is registered.
146
+ def self.mode?(mode)
147
+ retrieve(:modes).include? mode
130
148
  end
131
149
 
132
150
  def self.retrieve(symbol)
@@ -174,18 +192,6 @@ module MSpec
174
192
  end
175
193
  end
176
194
 
177
- def self.verify_mode?
178
- @mode == :verify
179
- end
180
-
181
- def self.report_mode?
182
- @mode == :report
183
- end
184
-
185
- def self.pretend_mode?
186
- @mode == :pretend
187
- end
188
-
189
195
  def self.randomize(flag=true)
190
196
  @randomize = flag
191
197
  end
@@ -334,6 +334,12 @@ class MSpecOptions
334
334
  end
335
335
  end
336
336
 
337
+ def unguarded
338
+ on("--unguarded", "Turn off all guards") do
339
+ MSpec.register_mode :unguarded
340
+ end
341
+ end
342
+
337
343
  def randomize
338
344
  on("-H", "--random",
339
345
  "Randomize the list of spec files") do
@@ -1,3 +1,4 @@
1
+ require 'mspec/guards/guard'
1
2
  require 'mspec/runner/formatters/dotted'
2
3
 
3
4
  # MSpecScript provides a skeleton for all the MSpec runner scripts.
@@ -80,9 +81,7 @@ class MSpecScript
80
81
  else
81
82
  engine = 'ruby'
82
83
  end
83
- version = RUBY_VERSION.split('.')[0,2].join('.')
84
-
85
- load "#{engine}.#{version}.mspec"
84
+ load "#{engine}.#{SpecGuard.ruby_version}.mspec"
86
85
  end
87
86
 
88
87
  # Registers all filters and actions.
@@ -0,0 +1,53 @@
1
+ class SpecVersion
2
+ # If beginning implementations have a problem with this include, we can
3
+ # manually implement the relational operators that are needed.
4
+ include Comparable
5
+
6
+ # SpecVersion handles comparison correctly for the context by filling in
7
+ # missing version parts according to the value of +ceil+. If +ceil+ is
8
+ # +false+, 0 digits fill in missing version parts. If +ceil+ is +true+, 9
9
+ # digits fill in missing parts. (See e.g. VersionGuard and BugGuard.)
10
+ def initialize(version, ceil = false)
11
+ @version = version
12
+ @ceil = ceil
13
+ @integer = nil
14
+ end
15
+
16
+ def to_s
17
+ @version
18
+ end
19
+
20
+ def to_str
21
+ to_s
22
+ end
23
+
24
+ # Converts a string representation of a version major.minor.tiny.patchlevel
25
+ # to an integer representation so that comparisons can be made. For example,
26
+ # "1.8.6.77" < "1.8.6.123" would be false if compared as strings.
27
+ def to_i
28
+ unless @integer
29
+ major, minor, tiny, patch = @version.split "."
30
+ if @ceil
31
+ tiny = 99 unless tiny
32
+ patch = 9999 unless patch
33
+ end
34
+ parts = [major, minor, tiny, patch].map { |x| x.to_i }
35
+ @integer = ("1%02d%02d%02d%04d" % parts).to_i
36
+ end
37
+ @integer
38
+ end
39
+
40
+ def to_int
41
+ to_i
42
+ end
43
+
44
+ def <=>(other)
45
+ if other.respond_to? :to_int
46
+ other = Integer other
47
+ else
48
+ other = SpecVersion.new(String(other)).to_i
49
+ end
50
+
51
+ self.to_i <=> other
52
+ end
53
+ end
@@ -1,3 +1,5 @@
1
+ require 'mspec/utils/version'
2
+
1
3
  module MSpec
2
- VERSION = '1.5.4'
4
+ VERSION = SpecVersion.new "1.5.5"
3
5
  end
@@ -33,6 +33,11 @@ describe MSpecCI, "#options" do
33
33
  @script.options
34
34
  end
35
35
 
36
+ it "enables the unguarded option" do
37
+ @options.should_receive(:unguarded)
38
+ @script.options
39
+ end
40
+
36
41
  it "enables the interrupt single specs option" do
37
42
  @options.should_receive(:interrupt)
38
43
  @script.options
@@ -58,6 +58,11 @@ describe MSpecRun, "#options" do
58
58
  @script.options @argv
59
59
  end
60
60
 
61
+ it "enables the unguarded option" do
62
+ @options.should_receive(:unguarded)
63
+ @script.options @argv
64
+ end
65
+
61
66
  it "enables the interrupt single specs option" do
62
67
  @options.should_receive(:interrupt)
63
68
  @script.options @argv
@@ -32,32 +32,11 @@ describe MSpecMain, "#options" do
32
32
  @script.options
33
33
  end
34
34
 
35
- it "enables the version option" do
36
- @options.should_receive(:version)
37
- @script.options
38
- end
39
-
40
35
  it "sets config[:options] to all argv entries that are not registered options" do
41
36
  @options.on "-X", "--exclude", "ARG", "description"
42
37
  @script.options [".", "-G", "fail", "-X", "ARG", "--list", "unstable", "some/file.rb"]
43
38
  @config[:options].should == [".", "-G", "fail", "--list", "unstable", "some/file.rb"]
44
39
  end
45
-
46
- it "passes -h, --help to the subscript" do
47
- ["-h", "--help"].each do |opt|
48
- @config[:options] = []
49
- @script.options ["ci", opt]
50
- @config[:options].sort.should == ["-h"]
51
- end
52
- end
53
-
54
- it "passes -v, --version to the subscript" do
55
- ["-v", "--version"].each do |opt|
56
- @config[:options] = []
57
- @script.options ["ci", opt]
58
- @config[:options].sort.should == ["-v"]
59
- end
60
- end
61
40
  end
62
41
 
63
42
  describe MSpecMain, "#parallel" do
@@ -390,6 +369,14 @@ describe "The -h, --help option" do
390
369
  @script.options
391
370
  end
392
371
 
372
+ it "passes the option to the subscript" do
373
+ ["-h", "--help"].each do |opt|
374
+ @config[:options] = []
375
+ @script.options ["ci", opt]
376
+ @config[:options].sort.should == ["-h"]
377
+ end
378
+ end
379
+
393
380
  it "prints help and exits" do
394
381
  @script.should_receive(:puts).twice
395
382
  @script.should_receive(:exit).twice
@@ -398,3 +385,36 @@ describe "The -h, --help option" do
398
385
  end
399
386
  end
400
387
  end
388
+
389
+ describe "The -v, --version option" do
390
+ before :each do
391
+ @options, @config = new_option
392
+ MSpecOptions.stub!(:new).and_return(@options)
393
+ @script = MSpecMain.new
394
+ @script.stub!(:config).and_return(@config)
395
+ end
396
+
397
+ it "is enabled by #options" do
398
+ @options.stub!(:on)
399
+ @options.should_receive(:on).with("-v", "--version", an_instance_of(String))
400
+ @script.options
401
+ end
402
+
403
+ it "passes the option to the subscripts" do
404
+ ["-v", "--version"].each do |opt|
405
+ @config[:options] = []
406
+ @script.options ["ci", opt]
407
+ @config[:options].sort.should == ["-v"]
408
+ end
409
+ end
410
+
411
+ it "prints the version and exits if no subscript is invoked" do
412
+ @config[:command] = nil
413
+ File.stub!(:basename).and_return("mspec")
414
+ @script.should_receive(:puts).twice.with("mspec #{MSpec::VERSION}")
415
+ @script.should_receive(:exit).twice
416
+ ["-v", "--version"].each do |opt|
417
+ @script.options [opt]
418
+ end
419
+ end
420
+ end
@@ -68,6 +68,11 @@ describe MSpecTag, "#options" do
68
68
  @script.options @argv
69
69
  end
70
70
 
71
+ it "enables the unguarded option" do
72
+ @options.should_receive(:unguarded)
73
+ @script.options @argv
74
+ end
75
+
71
76
  it "enables the interrupt single specs option" do
72
77
  @options.should_receive(:interrupt)
73
78
  @script.options @argv
@@ -372,6 +377,7 @@ describe MSpecTag, "#register" do
372
377
 
373
378
  describe "when config[:tagger] is :purge" do
374
379
  before :each do
380
+ MSpec.stub!(:register_mode)
375
381
  @config[:tagger] = :purge
376
382
  end
377
383
 
@@ -386,6 +392,11 @@ describe MSpecTag, "#register" do
386
392
  @script.register
387
393
  end
388
394
 
395
+ it "registers MSpec in unguarded mode" do
396
+ MSpec.should_receive(:register_mode).with(:unguarded)
397
+ @script.register
398
+ end
399
+
389
400
  it "sets config[:formatter] to false" do
390
401
  @script.register
391
402
  @config[:formatter].should be_false
@@ -1,22 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require 'mspec/guards/bug'
3
3
 
4
- describe BugGuard, "#to_v" do
5
- before :each do
6
- @guard = BugGuard.new "#1", "x.x.x.x"
7
- end
8
-
9
- it "returns a version string containing only digits" do
10
- @guard.to_v("1.8.6.22").should == 10108060022
11
- end
12
-
13
- it "replaces missing version parts with zeros" do
14
- @guard.to_v("1.8").should == 10108999999
15
- @guard.to_v("1.8.6").should == 10108069999
16
- @guard.to_v("1.8.7.333").should == 10108070333
17
- end
18
- end
19
-
20
4
  describe BugGuard, "#match? when #implementation? is 'ruby'" do
21
5
  before :all do
22
6
  @verbose = $VERBOSE
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/utils/ruby_name'
2
3
  require 'mspec/guards/guard'
3
4
  require 'rbconfig'
4
5
 
@@ -38,29 +39,100 @@ describe SpecGuard, ".unregister" do
38
39
  end
39
40
  end
40
41
 
42
+ describe SpecGuard, ".ruby_version" do
43
+ before :all do
44
+ @ruby_version = Object.const_get :RUBY_VERSION
45
+ @ruby_patchlevel = Object.const_get :RUBY_PATCHLEVEL
46
+
47
+ Object.const_set :RUBY_VERSION, "8.2.3"
48
+ Object.const_set :RUBY_PATCHLEVEL, 71
49
+ end
50
+
51
+ after :all do
52
+ Object.const_set :RUBY_VERSION, @ruby_version
53
+ Object.const_set :RUBY_PATCHLEVEL, @ruby_patchlevel
54
+ end
55
+
56
+ it "returns the version and patchlevel for :full" do
57
+ SpecGuard.ruby_version(:full).should == "8.2.3.71"
58
+ end
59
+
60
+ it "returns major.minor.tiny for :tiny" do
61
+ SpecGuard.ruby_version(:tiny).should == "8.2.3"
62
+ end
63
+
64
+ it "returns major.minor.tiny for :teeny" do
65
+ SpecGuard.ruby_version(:tiny).should == "8.2.3"
66
+ end
67
+
68
+ it "returns major.minor for :minor" do
69
+ SpecGuard.ruby_version(:minor).should == "8.2"
70
+ end
71
+
72
+ it "defaults to :minor" do
73
+ SpecGuard.ruby_version.should == "8.2"
74
+ end
75
+
76
+ it "returns major for :major" do
77
+ SpecGuard.ruby_version(:major).should == "8"
78
+ end
79
+ end
80
+
81
+ describe SpecGuard, ".windows?" do
82
+ before :all do
83
+ @ruby_platform = Object.const_get :RUBY_PLATFORM
84
+ end
85
+
86
+ after :all do
87
+ Object.const_set :RUBY_PLATFORM, @ruby_platform
88
+ end
89
+
90
+ it "returns true if key is mswin32" do
91
+ SpecGuard.windows?("mswin32").should be_true
92
+ end
93
+
94
+ it "returns true if key is mingw" do
95
+ SpecGuard.windows?("mingw").should be_true
96
+ end
97
+
98
+ it "returns false for non-windows" do
99
+ SpecGuard.windows?("notwindows").should be_false
100
+ end
101
+
102
+ it "uses RUBY_PLATFORM by default" do
103
+ Object.const_set :RUBY_PLATFORM, "mswin32"
104
+ SpecGuard.windows?.should be_true
105
+ end
106
+ end
107
+
41
108
  describe SpecGuard, "#yield?" do
42
109
  before :each do
43
- MSpec.store :mode, nil
110
+ MSpec.clear_modes
44
111
  @guard = SpecGuard.new
45
112
  end
46
113
 
47
- it "returns true if MSpec.verify_mode? is true" do
48
- MSpec.should_receive(:verify_mode?).and_return(true)
114
+ it "returns true if MSpec.mode?(:unguarded) is true" do
115
+ MSpec.register_mode :unguarded
116
+ @guard.yield?.should == true
117
+ end
118
+
119
+ it "returns true if MSpec.mode?(:verify) is true" do
120
+ MSpec.register_mode :verify
49
121
  @guard.yield?.should == true
50
122
  end
51
123
 
52
- it "returns true if MSpec.verify_mode? is true regardless of invert being true" do
53
- MSpec.should_receive(:verify_mode?).and_return(true)
124
+ it "returns true if MSpec.mode?(:verify) is true regardless of invert being true" do
125
+ MSpec.register_mode :verify
54
126
  @guard.yield?(true).should == true
55
127
  end
56
128
 
57
- it "returns true if MSpec.report_mode? is true" do
58
- MSpec.should_receive(:report_mode?).and_return(true)
129
+ it "returns true if MSpec.mode?(:report) is true" do
130
+ MSpec.register_mode :report
59
131
  @guard.yield?.should == true
60
132
  end
61
133
 
62
- it "returns true if MSpec.report_mode? is true regardless of invert being true" do
63
- MSpec.should_receive(:report_mode?).and_return(true)
134
+ it "returns true if MSpec.mode?(:report) is true regardless of invert being true" do
135
+ MSpec.register_mode :report
64
136
  @guard.yield?(true).should == true
65
137
  end
66
138
 
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/guards/tty'
3
+
4
+ describe Object, "#with_tty" do
5
+ before :each do
6
+ ScratchPad.clear
7
+ end
8
+
9
+ it "yields if STDOUT is a TTY" do
10
+ STDOUT.should_receive(:tty?).and_return(true)
11
+ with_tty { ScratchPad.record :yield }
12
+ ScratchPad.recorded.should == :yield
13
+ end
14
+
15
+ it "does not yield if STDOUT is not a TTY" do
16
+ STDOUT.should_receive(:tty?).and_return(false)
17
+ with_tty { ScratchPad.record :yield }
18
+ ScratchPad.recorded.should_not == :yield
19
+ end
20
+ end
@@ -41,22 +41,6 @@ describe VersionGuard, "#ruby_version" do
41
41
  end
42
42
  end
43
43
 
44
- describe VersionGuard, "#to_v" do
45
- before :each do
46
- @guard = VersionGuard.new 'x.x.x.x'
47
- end
48
-
49
- it "returns a version string containing only digits" do
50
- @guard.to_v("1.8.6.22").should == 10108060022
51
- end
52
-
53
- it "replaces missing version parts with zeros" do
54
- @guard.to_v("1.8").should == 10108000000
55
- @guard.to_v("1.8.6").should == 10108060000
56
- @guard.to_v("1.8.7.333").should == 10108070333
57
- end
58
- end
59
-
60
44
  describe VersionGuard, "#match?" do
61
45
  before :all do
62
46
  @verbose = $VERBOSE
@@ -0,0 +1,82 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/helpers/environment'
3
+
4
+ describe "#env" do
5
+ before(:all) do
6
+ @ruby_platform = Object.const_get :RUBY_PLATFORM
7
+ end
8
+
9
+ after(:all) do
10
+ Object.const_set :RUBY_PLATFORM, @ruby_platform
11
+ end
12
+
13
+ it "returns a hash of variables" do
14
+ env.class.should == Hash
15
+ end
16
+
17
+ it "calls `env` on non-Windows" do
18
+ Object.const_set :RUBY_PLATFORM, "notwindows"
19
+ should_receive(:`).with("env").and_return("one=two\nthree=four")
20
+ env
21
+ end
22
+
23
+ it "calls `cmd.exe /C set` on Windows (mswin32)" do
24
+ Object.const_set :RUBY_PLATFORM, "mswin32"
25
+ should_receive(:`).with("cmd.exe /C set").and_return("one=two\nthree=four")
26
+ env
27
+ end
28
+
29
+ it "calls `cmd.exe /C set` on Windows (mingw)" do
30
+ Object.const_set :RUBY_PLATFORM, "mingw"
31
+ should_receive(:`).with("cmd.exe /C set").and_return("one=two\nthree=four")
32
+ env
33
+ end
34
+
35
+ it "returns the current user's environment variables" do
36
+ Object.const_set :RUBY_PLATFORM, "notwindows"
37
+ should_receive(:`).with("env").and_return("one=two\nthree=four")
38
+ env.should == {"one" => "two", "three" => "four"}
39
+
40
+ Object.const_set :RUBY_PLATFORM, "mswin32"
41
+ should_receive(:`).with("cmd.exe /C set").and_return("five=six\nseven=eight")
42
+ env.should == {"five" => "six", "seven" => "eight"}
43
+ end
44
+ end
45
+
46
+ describe "#username" do
47
+ before(:all) do
48
+ @ruby_platform = Object.const_get :RUBY_PLATFORM
49
+ end
50
+
51
+ after(:all) do
52
+ Object.const_set :RUBY_PLATFORM, @ruby_platform
53
+ end
54
+
55
+ it "calls `cmd.exe /C ECHO %USERNAME%` on Windows (mswin32)" do
56
+ Object.const_set :RUBY_PLATFORM, "mswin32"
57
+ should_receive(:`).with("cmd.exe /C ECHO %USERNAME%").and_return("john")
58
+ username
59
+ end
60
+
61
+ it "calls `cmd.exe /C ECHO %USERNAME%` on Windows (mingw)" do
62
+ Object.const_set :RUBY_PLATFORM, "mingw"
63
+ should_receive(:`).with("cmd.exe /C ECHO %USERNAME%").and_return("john")
64
+ username
65
+ end
66
+
67
+ it "calls `env` on non-Windows" do
68
+ Object.const_set :RUBY_PLATFORM, "notwindows"
69
+ should_receive(:`).with("whoami").and_return("john")
70
+ username
71
+ end
72
+
73
+ it "returns the user's username" do
74
+ Object.const_set :RUBY_PLATFORM, "mswin32"
75
+ should_receive(:`).with("cmd.exe /C ECHO %USERNAME%").and_return("johnonwin")
76
+ username.should == "johnonwin"
77
+
78
+ Object.const_set :RUBY_PLATFORM, "notwindows"
79
+ should_receive(:`).with("whoami").and_return("john")
80
+ username.should == "john"
81
+ end
82
+ end
@@ -11,7 +11,7 @@ describe Object, "#fixture" do
11
11
  name.should == "#{@dir}/some/path/fixtures/dir/file.txt"
12
12
  end
13
13
 
14
- it "omits '/shared' if it the suffix of the directory string" do
14
+ it "omits '/shared' if it is the suffix of the directory string" do
15
15
  name = fixture("some/path/shared/file.rb", "dir", "file.txt")
16
16
  name.should == "#{@dir}/some/path/fixtures/dir/file.txt"
17
17
  end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/helpers/language_version'
3
+
4
+ describe Object, "#language_version" do
5
+ before :all do
6
+ @ruby_version = Object.const_get :RUBY_VERSION
7
+
8
+ Object.const_set :RUBY_VERSION, "8.2.3"
9
+
10
+ dir = File.dirname(File.expand_path(__FILE__))
11
+ @name = "#{dir}/versions/method_8.2.rb"
12
+ end
13
+
14
+ after :all do
15
+ Object.const_set :RUBY_VERSION, @ruby_version
16
+ end
17
+
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)
21
+ language_version __FILE__, "method"
22
+ end
23
+
24
+ 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)
27
+ language_version __FILE__, "method"
28
+ end
29
+ end
@@ -208,14 +208,14 @@ describe ContextState, "#protect" do
208
208
  @c = lambda { raise Exception, "Fail!" }
209
209
  end
210
210
 
211
- it "returns true and does execute any blocks if check is true and MSpec.pretend_mode? is true" do
212
- MSpec.stub!(:pretend_mode?).and_return(true)
211
+ it "returns true and does execute any blocks if check and MSpec.mode?(:pretend) are true" do
212
+ MSpec.should_receive(:mode?).with(:pretend).and_return(true)
213
213
  ContextState.new("").protect("message", [@a, @b]).should be_true
214
214
  ScratchPad.recorded.should == []
215
215
  end
216
216
 
217
- it "executes the blocks if MSpec.pretend_mode? is false" do
218
- MSpec.stub!(:pretend_mode?).and_return(false)
217
+ it "executes the blocks if MSpec.mode?(:pretend) is false" do
218
+ MSpec.should_receive(:mode?).with(:pretend).and_return(false)
219
219
  ContextState.new("").protect("message", [@a, @b])
220
220
  ScratchPad.recorded.should == [:a, :b]
221
221
  end
@@ -11,9 +11,13 @@ describe MSpec, ".register_files" do
11
11
  end
12
12
 
13
13
  describe MSpec, ".register_mode" do
14
+ before :each do
15
+ MSpec.clear_modes
16
+ end
17
+
14
18
  it "sets execution mode flags" do
15
19
  MSpec.register_mode :verify
16
- MSpec.retrieve(:mode).should == :verify
20
+ MSpec.retrieve(:modes).should == [:verify]
17
21
  end
18
22
  end
19
23
 
@@ -196,27 +200,30 @@ describe MSpec, ".actions" do
196
200
  end
197
201
  end
198
202
 
199
- describe MSpec, ".verify_mode?" do
203
+ describe MSpec, ".mode?" do
200
204
  before :each do
201
- MSpec.store :mode, nil
205
+ MSpec.clear_modes
202
206
  end
203
207
 
204
- it "returns true if register_mode(:verify) is called" do
205
- MSpec.verify_mode?.should == false
208
+ it "returns true if the mode has been set" do
209
+ MSpec.mode?(:verify).should == false
206
210
  MSpec.register_mode :verify
207
- MSpec.verify_mode?.should == true
211
+ MSpec.mode?(:verify).should == true
208
212
  end
209
213
  end
210
214
 
211
- describe MSpec, ".report_mode?" do
212
- before :each do
213
- MSpec.store :mode, nil
214
- end
215
+ describe MSpec, ".clear_modes" do
216
+ it "clears all registered modes" do
217
+ MSpec.register_mode(:pretend)
218
+ MSpec.register_mode(:verify)
219
+
220
+ MSpec.mode?(:pretend).should == true
221
+ MSpec.mode?(:verify).should == true
222
+
223
+ MSpec.clear_modes
215
224
 
216
- it "returns true if register_mode(:report) is called" do
217
- MSpec.report_mode?.should == false
218
- MSpec.register_mode :report
219
- MSpec.report_mode?.should == true
225
+ MSpec.mode?(:pretend).should == false
226
+ MSpec.mode?(:verify).should == false
220
227
  end
221
228
  end
222
229
 
@@ -923,7 +923,7 @@ describe "The -W, --excl-profile FILE option" do
923
923
  end
924
924
  end
925
925
 
926
- describe "The -Z", "--dry-run option" do
926
+ describe "The -Z, --dry-run option" do
927
927
  before :each do
928
928
  @options, @config = new_option
929
929
  @options.pretend
@@ -942,6 +942,23 @@ describe "The -Z", "--dry-run option" do
942
942
  end
943
943
  end
944
944
 
945
+ describe "The --unguarded option" do
946
+ before :each do
947
+ @options, @config = new_option
948
+ @options.unguarded
949
+ end
950
+
951
+ it "is enabled with #unguarded" do
952
+ @options.should_receive(:on).with("--unguarded", an_instance_of(String))
953
+ @options.unguarded
954
+ end
955
+
956
+ it "registers the MSpec unguarded mode" do
957
+ MSpec.should_receive(:register_mode).with(:unguarded)
958
+ @options.parse "--unguarded"
959
+ end
960
+ end
961
+
945
962
  describe "The -H, --random option" do
946
963
  before :each do
947
964
  @options, @config = new_option
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/utils/version'
3
+
4
+ describe SpecVersion, "#to_s" do
5
+ it "returns the string with which it was initialized" do
6
+ SpecVersion.new("1.8").to_s.should == "1.8"
7
+ SpecVersion.new("2.118.9.2").to_s.should == "2.118.9.2"
8
+ end
9
+ end
10
+
11
+ describe SpecVersion, "#to_str" do
12
+ it "returns the same string as #to_s" do
13
+ version = SpecVersion.new("2.118.9.2")
14
+ version.to_str.should == version.to_s
15
+ end
16
+ end
17
+
18
+ describe SpecVersion, "#to_i with ceil = false" do
19
+ it "returns an integer representation of the version string" do
20
+ SpecVersion.new("1.8.6.22").to_i.should == 10108060022
21
+ end
22
+
23
+ it "replaces missing version parts with zeros" do
24
+ SpecVersion.new("1.8").to_i.should == 10108000000
25
+ SpecVersion.new("1.8.6").to_i.should == 10108060000
26
+ SpecVersion.new("1.8.7.333").to_i.should == 10108070333
27
+ end
28
+ end
29
+
30
+ describe SpecVersion, "#to_i with ceil = true" do
31
+ it "returns an integer representation of the version string" do
32
+ SpecVersion.new("1.8.6.22", true).to_i.should == 10108060022
33
+ end
34
+
35
+ it "fills in 9s for missing tiny and patchlevel values" do
36
+ SpecVersion.new("1.8", true).to_i.should == 10108999999
37
+ SpecVersion.new("1.8.6", true).to_i.should == 10108069999
38
+ SpecVersion.new("1.8.7.333", true).to_i.should == 10108070333
39
+ end
40
+ end
41
+
42
+ describe SpecVersion, "#to_int" do
43
+ it "returns the same value as #to_i" do
44
+ version = SpecVersion.new("4.16.87.333")
45
+ version.to_int.should == version.to_i
46
+ end
47
+ end
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.4
4
+ version: 1.5.5
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: 2008-12-01 00:00:00 -08:00
12
+ date: 2008-12-29 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -47,14 +47,17 @@ files:
47
47
  - lib/mspec/guards/runner.rb
48
48
  - lib/mspec/guards/superuser.rb
49
49
  - lib/mspec/guards/support.rb
50
+ - lib/mspec/guards/tty.rb
50
51
  - lib/mspec/guards/version.rb
51
52
  - lib/mspec/guards.rb
52
53
  - lib/mspec/helpers/argv.rb
53
54
  - lib/mspec/helpers/bignum.rb
54
55
  - lib/mspec/helpers/const_lookup.rb
56
+ - lib/mspec/helpers/environment.rb
55
57
  - lib/mspec/helpers/fixture.rb
56
58
  - lib/mspec/helpers/flunk.rb
57
59
  - lib/mspec/helpers/io.rb
60
+ - lib/mspec/helpers/language_version.rb
58
61
  - lib/mspec/helpers/ruby_exe.rb
59
62
  - lib/mspec/helpers/scratch.rb
60
63
  - lib/mspec/helpers/tmp.rb
@@ -83,7 +86,6 @@ files:
83
86
  - lib/mspec/mocks/object.rb
84
87
  - lib/mspec/mocks/proxy.rb
85
88
  - lib/mspec/mocks.rb
86
- - lib/mspec/ruby_name.rb
87
89
  - lib/mspec/runner/actions/debug.rb
88
90
  - lib/mspec/runner/actions/filter.rb
89
91
  - lib/mspec/runner/actions/gdb.rb
@@ -118,7 +120,9 @@ files:
118
120
  - lib/mspec/runner.rb
119
121
  - lib/mspec/utils/name_map.rb
120
122
  - lib/mspec/utils/options.rb
123
+ - lib/mspec/utils/ruby_name.rb
121
124
  - lib/mspec/utils/script.rb
125
+ - lib/mspec/utils/version.rb
122
126
  - lib/mspec/version.rb
123
127
  - lib/mspec.rb
124
128
  - spec/runner/filters/a.yaml
@@ -148,13 +152,16 @@ files:
148
152
  - spec/guards/runner_spec.rb
149
153
  - spec/guards/superuser_spec.rb
150
154
  - spec/guards/support_spec.rb
155
+ - spec/guards/tty_spec.rb
151
156
  - spec/guards/version_spec.rb
152
157
  - spec/helpers/argv_spec.rb
153
158
  - spec/helpers/bignum_spec.rb
154
159
  - spec/helpers/const_lookup_spec.rb
160
+ - spec/helpers/environment_spec.rb
155
161
  - spec/helpers/fixture_spec.rb
156
162
  - spec/helpers/flunk_spec.rb
157
163
  - spec/helpers/io_spec.rb
164
+ - spec/helpers/language_version_spec.rb
158
165
  - spec/helpers/ruby_exe_spec.rb
159
166
  - spec/helpers/scratch_spec.rb
160
167
  - spec/helpers/tmp_spec.rb
@@ -210,6 +217,7 @@ files:
210
217
  - spec/utils/name_map_spec.rb
211
218
  - spec/utils/options_spec.rb
212
219
  - spec/utils/script_spec.rb
220
+ - spec/utils/version_spec.rb
213
221
  - Rakefile
214
222
  - README
215
223
  - LICENSE