mspec 1.5.5 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,9 +18,12 @@ class MSpecCI < MSpecScript
18
18
  options.doc " 4. When to perform it?"
19
19
 
20
20
  options.doc "\n How to run the specs"
21
+ options.chdir
22
+ options.prefix
21
23
  options.configure { |f| load f }
22
24
  options.name
23
25
  options.pretend
26
+ options.background
24
27
  options.unguarded
25
28
  options.interrupt
26
29
 
@@ -28,10 +28,13 @@ class MSpecRun < MSpecScript
28
28
  options.filters
29
29
 
30
30
  options.doc "\n How to modify the execution"
31
+ options.chdir
32
+ options.prefix
31
33
  options.configure { |f| load f }
32
34
  options.name
33
35
  options.randomize
34
36
  options.pretend
37
+ options.background
35
38
  options.unguarded
36
39
  options.interrupt
37
40
 
@@ -1,4 +1,5 @@
1
1
  require 'mspec/utils/ruby_name'
2
+ require 'mspec/guards/background'
2
3
  require 'mspec/guards/bug'
3
4
  require 'mspec/guards/compliance'
4
5
  require 'mspec/guards/conflict'
@@ -0,0 +1,19 @@
1
+ require 'mspec/guards/guard'
2
+
3
+ # Some specs, notably those for Readline, will block under certain
4
+ # circumstances when run as background or subprocesses. Use this guard for
5
+ # such specs.
6
+
7
+ class BackgroundGuard < SpecGuard
8
+ def match?
9
+ MSpec.mode? :background
10
+ end
11
+ end
12
+
13
+ class Object
14
+ def process_is_foreground
15
+ g = BackgroundGuard.new
16
+ yield if g.yield? true
17
+ g.unregister
18
+ end
19
+ end
@@ -1,9 +1,7 @@
1
1
  require 'mspec/guards/guard'
2
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.
3
+ # If a spec depends on STDOUT being a tty, use this guard. For specs that may
4
+ # block if run as a background process, see BackgroundGuard.
7
5
 
8
6
  class TTYGuard < SpecGuard
9
7
  def match?
@@ -91,14 +91,14 @@ class Object
91
91
 
92
92
  def resolve_ruby_exe
93
93
  [:env, :engine, :name, :install_name].each do |option|
94
- exe = ruby_exe_options option
94
+ next unless cmd = ruby_exe_options(option)
95
+ exe = cmd.split.first
95
96
 
96
97
  # It has been reported that File.executable is not reliable
97
98
  # on Windows platforms (see commit 56bc555c). So, we check the
98
99
  # platform.
99
- if exe and File.exists?(exe) and
100
- (SpecGuard.windows? || File.executable?(exe))
101
- return exe
100
+ if File.exists?(exe) and (SpecGuard.windows? or File.executable?(exe))
101
+ return cmd
102
102
  end
103
103
  end
104
104
  nil
@@ -327,6 +327,19 @@ class MSpecOptions
327
327
  end
328
328
  end
329
329
 
330
+ def chdir
331
+ on("-C", "--chdir", "DIR",
332
+ "Change the working directory to DIR before running specs") do |d|
333
+ Dir.chdir d
334
+ end
335
+ end
336
+
337
+ def prefix
338
+ on("--prefix", "STR", "Prepend STR when resolving spec file names") do |p|
339
+ config[:prefix] = p
340
+ end
341
+ end
342
+
330
343
  def pretend
331
344
  on("-Z", "--dry-run",
332
345
  "Invoke formatters and other actions, but don't execute the specs") do
@@ -334,6 +347,13 @@ class MSpecOptions
334
347
  end
335
348
  end
336
349
 
350
+ def background
351
+ on("--background",
352
+ "Enable guard for specs that may hang in background processes") do
353
+ MSpec.register_mode :background
354
+ end
355
+ end
356
+
337
357
  def unguarded
338
358
  on("--unguarded", "Turn off all guards") do
339
359
  MSpec.register_mode :unguarded
@@ -25,6 +25,18 @@ class MSpecScript
25
25
  config[key] = value
26
26
  end
27
27
 
28
+ # Gets the value of +key+ from the config object. Simplifies
29
+ # getting values in a config file:
30
+ #
31
+ # class MSpecScript
32
+ # set :a, 1
33
+ # set :b, 2
34
+ # set :c, get(:a) + get(:b)
35
+ # end
36
+ def self.get(key)
37
+ config[key]
38
+ end
39
+
28
40
  def initialize
29
41
  config[:formatter] = nil
30
42
  config[:includes] = []
@@ -140,19 +152,30 @@ class MSpecScript
140
152
  patterns.each do |pattern|
141
153
  expanded = File.expand_path(pattern)
142
154
  return [pattern] if File.file?(expanded)
143
- return Dir[pattern+"/**/*_spec.rb"].sort if File.directory?(expanded)
155
+
156
+ specs = File.join pattern, "/**/*_spec.rb"
157
+ return Dir[specs].sort if File.directory?(expanded)
144
158
  end
145
159
 
146
160
  Dir[partial]
147
161
  end
148
162
 
149
- # Resolves each entry in +list+ to a set of files. If the entry
150
- # has a leading '^' character, the list of files is subtracted
151
- # from the list of files accumulated to that point.
163
+ # Resolves each entry in +list+ to a set of files.
164
+ #
165
+ # If the entry has a leading '^' character, the list of files
166
+ # is subtracted from the list of files accumulated to that point.
167
+ #
168
+ # If the entry has a leading ':' character, the corresponding
169
+ # key is looked up in the config object and the entries in the
170
+ # value retrieved are processed through #entries.
152
171
  def files(list)
153
172
  list.inject([]) do |files, item|
154
- if item[0] == ?^
173
+ case item[0]
174
+ when ?^
155
175
  files -= entries(item[1..-1])
176
+ when ?:
177
+ key = item[1..-1].to_sym
178
+ files += files(Array(config[key]))
156
179
  else
157
180
  files += entries(item)
158
181
  end
@@ -1,5 +1,5 @@
1
1
  require 'mspec/utils/version'
2
2
 
3
3
  module MSpec
4
- VERSION = SpecVersion.new "1.5.5"
4
+ VERSION = SpecVersion.new "1.5.6"
5
5
  end
@@ -13,6 +13,16 @@ describe MSpecCI, "#options" do
13
13
  @script.stub!(:files).and_return([])
14
14
  end
15
15
 
16
+ it "enables the chdir option" do
17
+ @options.should_receive(:chdir)
18
+ @script.options
19
+ end
20
+
21
+ it "enables the prefix option" do
22
+ @options.should_receive(:prefix)
23
+ @script.options
24
+ end
25
+
16
26
  it "enables the config option" do
17
27
  @options.should_receive(:configure)
18
28
  @script.options
@@ -33,6 +43,11 @@ describe MSpecCI, "#options" do
33
43
  @script.options
34
44
  end
35
45
 
46
+ it "enables the background option" do
47
+ @options.should_receive(:background)
48
+ @script.options
49
+ end
50
+
36
51
  it "enables the unguarded option" do
37
52
  @options.should_receive(:unguarded)
38
53
  @script.options
@@ -33,6 +33,16 @@ describe MSpecRun, "#options" do
33
33
  @script.options @argv
34
34
  end
35
35
 
36
+ it "enables the chdir option" do
37
+ @options.should_receive(:chdir)
38
+ @script.options @argv
39
+ end
40
+
41
+ it "enables the prefix option" do
42
+ @options.should_receive(:prefix)
43
+ @script.options @argv
44
+ end
45
+
36
46
  it "enables the configure option" do
37
47
  @options.should_receive(:configure)
38
48
  @script.options @argv
@@ -58,6 +68,11 @@ describe MSpecRun, "#options" do
58
68
  @script.options @argv
59
69
  end
60
70
 
71
+ it "enables the background option" do
72
+ @options.should_receive(:background)
73
+ @script.options @argv
74
+ end
75
+
61
76
  it "enables the unguarded option" do
62
77
  @options.should_receive(:unguarded)
63
78
  @script.options @argv
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/guards/background'
3
+
4
+ describe Object, "#process_is_foreground" do
5
+ before :each do
6
+ MSpec.clear_modes
7
+ ScratchPad.clear
8
+ end
9
+
10
+ it "yields if MSpec.mode?(:background) is false" do
11
+ MSpec.mode?(:background).should be_false
12
+ process_is_foreground { ScratchPad.record :yield }
13
+ ScratchPad.recorded.should == :yield
14
+ end
15
+
16
+ it "does not yield if MSpec.mode?(:background) is true" do
17
+ MSpec.register_mode :background
18
+ process_is_foreground { ScratchPad.record :yield }
19
+ ScratchPad.recorded.should_not == :yield
20
+ end
21
+ end
@@ -467,6 +467,44 @@ describe "The -B, --config FILE option" do
467
467
  end
468
468
  end
469
469
 
470
+ describe "The -C, --chdir DIR option" do
471
+ before :each do
472
+ @options, @config = new_option
473
+ @options.chdir
474
+ end
475
+
476
+ it "is enabled with #chdir" do
477
+ @options.should_receive(:on).with("-C", "--chdir", "DIR",
478
+ an_instance_of(String))
479
+ @options.chdir
480
+ end
481
+
482
+ it "changes the working directory to DIR" do
483
+ Dir.should_receive(:chdir).with("dir").twice
484
+ ["-C", "--chdir"].each do |opt|
485
+ @options.parse [opt, "dir"]
486
+ end
487
+ end
488
+ end
489
+
490
+ describe "The --prefix STR option" do
491
+ before :each do
492
+ @options, @config = new_option
493
+ end
494
+
495
+ it "is enabled with #prefix" do
496
+ @options.should_receive(:on).with("--prefix", "STR",
497
+ an_instance_of(String))
498
+ @options.prefix
499
+ end
500
+
501
+ it "sets the prefix config value" do
502
+ @options.prefix
503
+ @options.parse ["--prefix", "some/dir"]
504
+ @config[:prefix].should == "some/dir"
505
+ end
506
+ end
507
+
470
508
  describe "The -n, --name RUBY_NAME option" do
471
509
  before :each do
472
510
  @verbose, $VERBOSE = $VERBOSE, nil
@@ -942,6 +980,23 @@ describe "The -Z, --dry-run option" do
942
980
  end
943
981
  end
944
982
 
983
+ describe "The --background option" do
984
+ before :each do
985
+ @options, @config = new_option
986
+ end
987
+
988
+ it "is enabled with #background" do
989
+ @options.should_receive(:on).with("--background", an_instance_of(String))
990
+ @options.background
991
+ end
992
+
993
+ it "registers the MSpec background mode" do
994
+ MSpec.should_receive(:register_mode).with(:background)
995
+ @options.background
996
+ @options.parse "--background"
997
+ end
998
+ end
999
+
945
1000
  describe "The --unguarded option" do
946
1001
  before :each do
947
1002
  @options, @config = new_option
@@ -19,6 +19,13 @@ describe MSpecScript, ".set" do
19
19
  end
20
20
  end
21
21
 
22
+ describe MSpecScript, ".get" do
23
+ it "gets the config hash value for a key" do
24
+ MSpecScript.set :a, 10
25
+ MSpecScript.get(:a).should == 10
26
+ end
27
+ end
28
+
22
29
  describe MSpecScript, "#config" do
23
30
  it "returns the MSpecScript config hash" do
24
31
  MSpecScript.set :b, 5
@@ -380,3 +387,24 @@ describe MSpecScript, "#files" do
380
387
  @script.files(["^a", "a", "b"]).should == ["file1", "file2"]
381
388
  end
382
389
  end
390
+
391
+ describe MSpecScript, "#files" do
392
+ before :each do
393
+ MSpecScript.set :files, ["file1", "file2"]
394
+
395
+ @script = MSpecScript.new
396
+ end
397
+
398
+ after :each do
399
+ MSpecScript.config.delete :files
400
+ end
401
+
402
+ it "looks up items with leading ':' in the config object" do
403
+ @script.should_receive(:entries).and_return(["file1"], ["file2"])
404
+ @script.files(":files").should == ["file1", "file2"]
405
+ end
406
+
407
+ it "returns an empty list if the config key is not set" do
408
+ @script.files(":all_files").should == []
409
+ end
410
+ 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.5
4
+ version: 1.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Ford
@@ -35,6 +35,7 @@ files:
35
35
  - lib/mspec/expectations/expectations.rb
36
36
  - lib/mspec/expectations/should.rb
37
37
  - lib/mspec/expectations.rb
38
+ - lib/mspec/guards/background.rb
38
39
  - lib/mspec/guards/bug.rb
39
40
  - lib/mspec/guards/compliance.rb
40
41
  - lib/mspec/guards/conflict.rb
@@ -140,6 +141,7 @@ files:
140
141
  - spec/commands/mspec_tag_spec.rb
141
142
  - spec/expectations/expectations_spec.rb
142
143
  - spec/expectations/should_spec.rb
144
+ - spec/guards/background_spec.rb
143
145
  - spec/guards/bug_spec.rb
144
146
  - spec/guards/compliance_spec.rb
145
147
  - spec/guards/conflict_spec.rb