mspec 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,6 +29,7 @@ class MSpecMain < MSpecScript
29
29
  options.doc " with different implementations like ruby, jruby, rbx, etc.\n"
30
30
 
31
31
  options.configure do |f|
32
+ load f
32
33
  config[:options] << '-B' << f
33
34
  end
34
35
 
@@ -3,6 +3,9 @@ require 'mspec/runner/formatters/dotted'
3
3
  # MSpecScript provides a skeleton for all the MSpec runner scripts.
4
4
 
5
5
  class MSpecScript
6
+ # Returns the config object. Maintained at the class
7
+ # level to easily enable simple config files. See the
8
+ # class method +set+.
6
9
  def self.config
7
10
  @config ||= {
8
11
  :path => ['.', 'spec'],
@@ -10,6 +13,13 @@ class MSpecScript
10
13
  }
11
14
  end
12
15
 
16
+ # Associates +value+ with +key+ in the config object. Enables
17
+ # simple config files of the form:
18
+ #
19
+ # class MSpecScript
20
+ # set :target, "ruby"
21
+ # set :files, ["one_spec.rb", "two_spec.rb"]
22
+ # end
13
23
  def self.set(key, value)
14
24
  config[key] = value
15
25
  end
@@ -30,10 +40,15 @@ class MSpecScript
30
40
  config[:abort] = true
31
41
  end
32
42
 
43
+ # Returns the config object maintained by the instance's class.
44
+ # See the class methods +set+ and +config+.
33
45
  def config
34
46
  MSpecScript.config
35
47
  end
36
48
 
49
+ # Returns +true+ if the file was located in +config[:path]+,
50
+ # possibly appending +config[:config_ext]. Returns +false+
51
+ # otherwise.
37
52
  def load(target)
38
53
  names = [target]
39
54
  unless target[-6..-1] == config[:config_ext]
@@ -48,9 +63,18 @@ class MSpecScript
48
63
  return Kernel.load(file) if File.exist? file
49
64
  end
50
65
  end
66
+
67
+ false
51
68
  end
52
69
 
70
+ # Attempts to load a default config file. First tries to load
71
+ # 'default.mspec'. If that fails, attempts to load a config
72
+ # file name constructed from the value of RUBY_ENGINE and the
73
+ # first two numbers in RUBY_VERSION. For example, on MRI 1.8.6,
74
+ # the file name would be 'ruby.1.8.mspec'.
53
75
  def load_default
76
+ return if load 'default.mspec'
77
+
54
78
  if Object.const_defined?(:RUBY_ENGINE)
55
79
  engine = RUBY_ENGINE
56
80
  else
@@ -61,6 +85,7 @@ class MSpecScript
61
85
  load "#{engine}.#{version}.mspec"
62
86
  end
63
87
 
88
+ # Registers all filters and actions.
64
89
  def register
65
90
  if config[:formatter].nil?
66
91
  config[:formatter] = @files.size < 50 ? DottedFormatter : FileFormatter
@@ -80,6 +105,8 @@ class MSpecScript
80
105
  GdbAction.new(config[:atags], config[:astrings]).register if config[:gdb]
81
106
  end
82
107
 
108
+ # Sets up signal handlers. Only a handler for SIGINT is
109
+ # registered currently.
83
110
  def signals
84
111
  if config[:abort]
85
112
  Signal.trap "INT" do
@@ -89,6 +116,10 @@ class MSpecScript
89
116
  end
90
117
  end
91
118
 
119
+ # Resolves +pattern+ as a file name, directory name or pattern.
120
+ # If it is a file name, returns the name as an entry in an array.
121
+ # If it is a directory, returns all *_spec.rb files in the
122
+ # directory and subdirectory. Otherwise, passes +pattern+ to +Dir[]+.
92
123
  def entries(pattern)
93
124
  expanded = File.expand_path(pattern)
94
125
  return [pattern] if File.file?(expanded)
@@ -96,6 +127,9 @@ class MSpecScript
96
127
  Dir[pattern]
97
128
  end
98
129
 
130
+ # Resolves each entry in +list+ to a set of files. If the entry
131
+ # has a leading '^' character, the list of files is subtracted
132
+ # from the list of files accumulated to that point.
99
133
  def files(list)
100
134
  list.inject([]) do |files, item|
101
135
  if item[0] == ?^
@@ -107,6 +141,8 @@ class MSpecScript
107
141
  end
108
142
  end
109
143
 
144
+ # Instantiates an instance and calls the series of methods to
145
+ # invoke the script.
110
146
  def self.main
111
147
  $VERBOSE = nil unless ENV['OUTPUT_WARNINGS']
112
148
  script = new
@@ -1,3 +1,3 @@
1
1
  module MSpec
2
- VERSION = '1.5.2'
2
+ VERSION = '1.5.3'
3
3
  end
@@ -9,6 +9,7 @@ describe MSpecMain, "#options" do
9
9
 
10
10
  @script = MSpecMain.new
11
11
  @script.stub!(:config).and_return(@config)
12
+ @script.stub!(:load)
12
13
  end
13
14
 
14
15
  it "enables the configure option" do
@@ -21,6 +22,11 @@ describe MSpecMain, "#options" do
21
22
  @config[:options].should include("-B", "config")
22
23
  end
23
24
 
25
+ it "loads the file specified by the config option" do
26
+ @script.should_receive(:load).with("config")
27
+ @script.options ["-B", "config"]
28
+ end
29
+
24
30
  it "enables the target options" do
25
31
  @options.should_receive(:targets)
26
32
  @script.options
@@ -56,10 +56,16 @@ describe MSpecScript, "#load_default" do
56
56
  Object.const_set :RUBY_ENGINE, @engine if @engine
57
57
  end
58
58
 
59
+ it "attempts to load 'default.mspec'" do
60
+ @script.should_receive(:load).with('default.mspec').and_return(true)
61
+ @script.load_default
62
+ end
63
+
59
64
  it "attempts to load a config file based on RUBY_ENGINE and RUBY_VERSION" do
60
65
  Object.const_set :RUBY_ENGINE, "ybur"
61
66
  Object.const_set :RUBY_VERSION, "1.8.9"
62
67
  default = "ybur.1.8.mspec"
68
+ @script.should_receive(:load).with('default.mspec').and_return(false)
63
69
  @script.should_receive(:load).with(default)
64
70
  @script.load_default
65
71
  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.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Ford