mspec 1.4.0 → 1.5.0

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.
@@ -3,9 +3,9 @@
3
3
  MSPEC_HOME = File.expand_path(File.dirname(__FILE__) + '/../../..')
4
4
 
5
5
  require 'fileutils'
6
- require 'optparse'
7
6
  require 'rbconfig'
8
7
  require 'mspec/version'
8
+ require 'mspec/utils/options'
9
9
  require 'mspec/utils/name_map'
10
10
 
11
11
 
@@ -22,39 +22,33 @@ class MkSpec
22
22
  end
23
23
 
24
24
  def options(argv=ARGV)
25
- options = OptionParser.new
26
- options.version = MSpec::VERSION
27
- options.banner = "mkspec [options]"
28
- options.separator ""
25
+ options = MSpecOptions.new "mkspec [options]"
29
26
 
30
- options.on("-c", "--constant CONSTANT", String,
27
+ options.on("-c", "--constant", "CONSTANT",
31
28
  "Class or Module to generate spec stubs for") do |name|
32
29
  config[:constants] << name
33
30
  end
34
- options.on("-b", "--base DIR", String,
31
+ options.on("-b", "--base", "DIR",
35
32
  "Directory to generate specs into") do |directory|
36
33
  config[:base] = File.expand_path directory
37
34
  end
38
- options.on("-r", "--require LIBRARY", String,
35
+ options.on("-r", "--require", "LIBRARY",
39
36
  "A library to require") do |file|
40
37
  config[:requires] << file
41
38
  end
42
-
43
- options.separator "\n How might this work in the real world?\n"
44
- options.separator " 1. To create spec stubs for every class or module in Object\n"
45
- options.separator " $ mkspec\n"
46
- options.separator " 2. To create spec stubs for Fixnum\n"
47
- options.separator " $ mkspec -c Fixnum\n"
48
- options.separator " 3. To create spec stubs for Complex in 'superspec/complex'\n"
49
- options.separator " $ mkspec -c Complex -rcomplex -b superspec"
50
- options.separator ""
39
+ options.version MSpec::VERSION
40
+ options.help
41
+
42
+ options.doc "\n How might this work in the real world?\n"
43
+ options.doc " 1. To create spec stubs for every class or module in Object\n"
44
+ options.doc " $ mkspec\n"
45
+ options.doc " 2. To create spec stubs for Fixnum\n"
46
+ options.doc " $ mkspec -c Fixnum\n"
47
+ options.doc " 3. To create spec stubs for Complex in 'superspec/complex'\n"
48
+ options.doc " $ mkspec -c Complex -rcomplex -b superspec"
49
+ options.doc ""
51
50
 
52
51
  options.parse argv
53
- rescue OptionParser::ParseError => e
54
- puts options
55
- puts
56
- puts e
57
- exit 1
58
52
  end
59
53
 
60
54
  def create_directory(mod)
@@ -2,69 +2,60 @@
2
2
 
3
3
  $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
4
 
5
- require 'optparse'
5
+ require 'mspec/version'
6
6
  require 'mspec/utils/options'
7
7
  require 'mspec/utils/script'
8
8
 
9
9
 
10
10
  class MSpecCI < MSpecScript
11
11
  def options(argv=ARGV)
12
- options = MSpecOptions.new config, "ci", "", 28, " "
13
-
14
- options.separator " Ask yourself:"
15
- options.separator " 1. How to run the specs?"
16
- options.separator " 2. How to display the output?"
17
- options.separator " 3. What action to perform?"
18
- options.separator " 4. When to perform it?"
19
-
20
- options.separator "\n How to run the specs"
21
- options.add_config { |f| load f }
22
- options.add_name
23
- options.add_pretend
24
- options.add_interrupt
25
-
26
- options.separator "\n How to display their output"
27
- options.add_formatters
28
- options.add_verbose
29
-
30
- options.separator "\n What action to perform"
31
- options.add_actions
32
-
33
- options.separator "\n When to perform it"
34
- options.add_action_filters
35
-
36
- options.separator "\n Help!"
37
- options.add_version
38
- options.add_help
39
-
40
- options.separator "\n How might this work in the real world?"
41
- options.separator "\n 1. To simply run the known good specs"
42
- options.separator "\n $ mspec ci"
43
- options.separator "\n 2. To run a subset of the known good specs"
44
- options.separator "\n $ mspec ci path/to/specs"
45
- options.separator "\n 3. To start the debugger before the spec matching 'this crashes'"
46
- options.separator "\n $ mspec ci --spec-debug -S 'this crashes'"
47
- options.separator ""
12
+ options = MSpecOptions.new "mspec ci [options] (FILE|DIRECTORY|GLOB)+", 30, config
13
+
14
+ options.doc " Ask yourself:"
15
+ options.doc " 1. How to run the specs?"
16
+ options.doc " 2. How to display the output?"
17
+ options.doc " 3. What action to perform?"
18
+ options.doc " 4. When to perform it?"
19
+
20
+ options.doc "\n How to run the specs"
21
+ options.configure { |f| load f }
22
+ options.name
23
+ options.pretend
24
+ options.interrupt
25
+
26
+ options.doc "\n How to display their output"
27
+ options.formatters
28
+ options.verbose
29
+
30
+ options.doc "\n What action to perform"
31
+ options.actions
32
+
33
+ options.doc "\n When to perform it"
34
+ options.action_filters
35
+
36
+ options.doc "\n Help!"
37
+ options.version MSpec::VERSION
38
+ options.help
39
+
40
+ options.doc "\n How might this work in the real world?"
41
+ options.doc "\n 1. To simply run the known good specs"
42
+ options.doc "\n $ mspec ci"
43
+ options.doc "\n 2. To run a subset of the known good specs"
44
+ options.doc "\n $ mspec ci path/to/specs"
45
+ options.doc "\n 3. To start the debugger before the spec matching 'this crashes'"
46
+ options.doc "\n $ mspec ci --spec-debug -S 'this crashes'"
47
+ options.doc ""
48
48
 
49
49
  @patterns = options.parse argv
50
50
  @patterns = config[:ci_files] if @patterns.empty?
51
51
  end
52
52
 
53
53
  def run
54
- files = []
55
- @patterns.each do |item|
56
- stat = File.stat(File.expand_path(item))
57
- files << item if stat.file?
58
- files.concat(Dir[item+"/**/*_spec.rb"].sort) if stat.directory?
59
- end
60
-
61
54
  MSpec.register_tags_patterns config[:tags_patterns]
62
- MSpec.register_files files
63
- TagFilter.new(:exclude, "fails").register
64
- TagFilter.new(:exclude, "critical").register
65
- TagFilter.new(:exclude, "unstable").register
66
- TagFilter.new(:exclude, "incomplete").register
67
- TagFilter.new(:exclude, "unsupported").register
55
+ MSpec.register_files files(@patterns)
56
+ filter = TagFilter.new(:exclude,
57
+ "fails", "critical", "unstable", "incomplete", "unsupported")
58
+ filter.register
68
59
 
69
60
  MSpec.process
70
61
  exit MSpec.exit_code
@@ -2,75 +2,68 @@
2
2
 
3
3
  $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
4
 
5
- require 'optparse'
5
+ require 'mspec/version'
6
6
  require 'mspec/utils/options'
7
7
  require 'mspec/utils/script'
8
8
 
9
9
 
10
10
  class MSpecRun < MSpecScript
11
11
  def options(argv=ARGV)
12
- options = MSpecOptions.new config, "run", "", 28, " "
13
-
14
- options.separator " Ask yourself:"
15
- options.separator " 1. What specs to run?"
16
- options.separator " 2. How to modify the execution?"
17
- options.separator " 3. How to display the output?"
18
- options.separator " 4. What action to perform?"
19
- options.separator " 5. When to perform it?"
20
-
21
- options.separator "\n What specs to run"
22
- options.add_filters
23
-
24
- options.separator "\n How to modify the execution"
25
- options.add_config { |f| load f }
26
- options.add_name
27
- options.add_randomize
28
- options.add_pretend
29
- options.add_interrupt
30
-
31
- options.separator "\n How to display their output"
32
- options.add_formatters
33
- options.add_verbose
34
-
35
- options.separator "\n What action to perform"
36
- options.add_actions
37
- options.add_verify
38
-
39
- options.separator "\n When to perform it"
40
- options.add_action_filters
41
-
42
- options.separator "\n Help!"
43
- options.add_version
44
- options.add_help
45
-
46
- options.separator "\n How might this work in the real world?"
47
- options.separator "\n 1. To simply run some specs"
48
- options.separator "\n $ mspec path/to/the/specs"
49
- options.separator " mspec path/to/the_file_spec.rb"
50
- options.separator "\n 2. To run specs tagged with 'fails'"
51
- options.separator "\n $ mspec -g fails path/to/the_file_spec.rb"
52
- options.separator "\n 3. To start the debugger before the spec matching 'this crashes'"
53
- options.separator "\n $ mspec --spec-debug -S 'this crashes' path/to/the_file_spec.rb"
54
- options.separator ""
12
+ options = MSpecOptions.new "mspec run [options] (FILE|DIRECTORY|GLOB)+", 30, config
13
+
14
+ options.doc " Ask yourself:"
15
+ options.doc " 1. What specs to run?"
16
+ options.doc " 2. How to modify the execution?"
17
+ options.doc " 3. How to display the output?"
18
+ options.doc " 4. What action to perform?"
19
+ options.doc " 5. When to perform it?"
20
+
21
+ options.doc "\n What specs to run"
22
+ options.filters
23
+
24
+ options.doc "\n How to modify the execution"
25
+ options.configure { |f| load f }
26
+ options.name
27
+ options.randomize
28
+ options.pretend
29
+ options.interrupt
30
+
31
+ options.doc "\n How to display their output"
32
+ options.formatters
33
+ options.verbose
34
+
35
+ options.doc "\n What action to perform"
36
+ options.actions
37
+ options.verify
38
+
39
+ options.doc "\n When to perform it"
40
+ options.action_filters
41
+
42
+ options.doc "\n Help!"
43
+ options.version MSpec::VERSION
44
+ options.help
45
+
46
+ options.doc "\n How might this work in the real world?"
47
+ options.doc "\n 1. To simply run some specs"
48
+ options.doc "\n $ mspec path/to/the/specs"
49
+ options.doc " mspec path/to/the_file_spec.rb"
50
+ options.doc "\n 2. To run specs tagged with 'fails'"
51
+ options.doc "\n $ mspec -g fails path/to/the_file_spec.rb"
52
+ options.doc "\n 3. To start the debugger before the spec matching 'this crashes'"
53
+ options.doc "\n $ mspec --spec-debug -S 'this crashes' path/to/the_file_spec.rb"
54
+ options.doc ""
55
55
 
56
56
  @patterns = options.parse argv
57
57
  if @patterns.empty?
58
- puts options.parser
58
+ puts options
59
59
  puts "No files specified."
60
60
  exit 1
61
61
  end
62
62
  end
63
63
 
64
64
  def run
65
- files = []
66
- @patterns.each do |item|
67
- stat = File.stat(File.expand_path(item))
68
- files << item if stat.file?
69
- files.concat(Dir[item+"/**/*_spec.rb"].sort) if stat.directory?
70
- end
71
-
72
65
  MSpec.register_tags_patterns config[:tags_patterns]
73
- MSpec.register_files files
66
+ MSpec.register_files files(@patterns)
74
67
 
75
68
  MSpec.process
76
69
  exit MSpec.exit_code
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'optparse'
3
+ require 'mspec/version'
4
4
  require 'mspec/utils/options'
5
5
  require 'mspec/utils/script'
6
6
 
@@ -12,72 +12,103 @@ class MSpecTag < MSpecScript
12
12
  config[:tagger] = :add
13
13
  config[:tag] = 'fails:'
14
14
  config[:outcome] = :fail
15
+ config[:ltags] = []
15
16
  end
16
17
 
17
18
  def options(argv=ARGV)
18
- options = MSpecOptions.new config, "tag", "", 28, " "
19
-
20
- options.separator " Ask yourself:"
21
- options.separator " 1. What specs to run?"
22
- options.separator " 2. How to modify the execution?"
23
- options.separator " 3. How to display the output?"
24
- options.separator " 4. What tag action to perform?"
25
- options.separator " 5. When to perform it?"
26
-
27
- options.separator "\n What specs to run"
28
- options.add_filters
29
-
30
- options.separator "\n How to modify the execution"
31
- options.add_config { |f| load f }
32
- options.add_name
33
- options.add_pretend
34
- options.add_interrupt
35
-
36
- options.separator "\n How to display their output"
37
- options.add_formatters
38
- options.add_verbose
39
-
40
- options.separator "\n What action to perform and when to perform it"
41
- options.add_tagging
42
-
43
- options.separator "\n Help!"
44
- options.add_version
45
- options.add_help
46
-
47
- options.separator "\n How might this work in the real world?"
48
- options.separator "\n 1. To add the 'fails' tag to failing specs"
49
- options.separator "\n $ mspec tag path/to/the_file_spec.rb"
50
- options.separator "\n 2. To remove the 'fails' tag from passing specs"
51
- options.separator "\n $ mspec tag --del fails path/to/the_file_spec.rb"
52
- options.separator ""
19
+ options = MSpecOptions.new "mspec tag [options] (FILE|DIRECTORY|GLOB)+", 30, config
20
+
21
+ options.doc " Ask yourself:"
22
+ options.doc " 1. What specs to run?"
23
+ options.doc " 2. How to modify the execution?"
24
+ options.doc " 3. How to display the output?"
25
+ options.doc " 4. What tag action to perform?"
26
+ options.doc " 5. When to perform it?"
27
+
28
+ options.doc "\n What specs to run"
29
+ options.filters
30
+
31
+ options.doc "\n How to modify the execution"
32
+ options.configure { |f| load f }
33
+ options.name
34
+ options.pretend
35
+ options.interrupt
36
+
37
+ options.doc "\n How to display their output"
38
+ options.formatters
39
+ options.verbose
40
+
41
+ options.doc "\n What action to perform and when to perform it"
42
+ options.on("-N", "--add", "TAG",
43
+ "Add TAG with format 'tag' or 'tag(comment)' (see -Q, -F, -L)") do |o|
44
+ config[:tagger] = :add
45
+ config[:tag] = "#{o}:"
46
+ end
47
+ options.on("-R", "--del", "TAG",
48
+ "Delete TAG (see -Q, -F, -L)") do |o|
49
+ config[:tagger] = :del
50
+ config[:tag] = "#{o}:"
51
+ config[:outcome] = :pass
52
+ end
53
+ options.on("-Q", "--pass", "Apply action to specs that pass (default for --del)") do
54
+ config[:outcome] = :pass
55
+ end
56
+ options.on("-F", "--fail", "Apply action to specs that fail (default for --add)") do
57
+ config[:outcome] = :fail
58
+ end
59
+ options.on("-L", "--all", "Apply action to all specs") do
60
+ config[:outcome] = :all
61
+ end
62
+ options.on("--list", "TAG", "Display descriptions of any specs tagged with TAG") do |t|
63
+ config[:tagger] = :list
64
+ config[:ltags] << t
65
+ end
66
+ options.on("--list-all", "Display descriptions of any tagged specs") do
67
+ config[:tagger] = :list_all
68
+ end
69
+
70
+ options.doc "\n Help!"
71
+ options.version MSpec::VERSION
72
+ options.help
73
+
74
+ options.doc "\n How might this work in the real world?"
75
+ options.doc "\n 1. To add the 'fails' tag to failing specs"
76
+ options.doc "\n $ mspec tag path/to/the_file_spec.rb"
77
+ options.doc "\n 2. To remove the 'fails' tag from passing specs"
78
+ options.doc "\n $ mspec tag --del fails path/to/the_file_spec.rb"
79
+ options.doc "\n 3. To display the descriptions for all specs tagged with 'fails'"
80
+ options.doc "\n $ mspec tag --list fails path/to/the/specs"
81
+ options.doc ""
53
82
 
54
83
  @patterns = options.parse argv
55
84
  if @patterns.empty?
56
- puts options.parser
85
+ puts options
57
86
  puts "No files specified."
58
87
  exit 1
59
88
  end
60
89
  end
61
90
 
62
91
  def register
63
- super
64
-
65
- tag = SpecTag.new config[:tag]
66
- tagger = TagAction.new(config[:tagger], config[:outcome], tag.tag, tag.comment,
67
- config[:atags], config[:astrings])
92
+ case config[:tagger]
93
+ when :add, :del
94
+ tag = SpecTag.new config[:tag]
95
+ tagger = TagAction.new(config[:tagger], config[:outcome], tag.tag, tag.comment,
96
+ config[:atags], config[:astrings])
97
+ when :list, :list_all
98
+ tagger = TagListAction.new config[:tagger] == :list_all ? nil : config[:ltags]
99
+ MSpec.register_mode :pretend
100
+ config[:formatter] = nil
101
+ else
102
+ raise ArgumentError, "No recognized action given"
103
+ end
68
104
  tagger.register
105
+
106
+ super
69
107
  end
70
108
 
71
109
  def run
72
- files = []
73
- @patterns.each do |item|
74
- stat = File.stat(File.expand_path(item))
75
- files << item if stat.file?
76
- files.concat(Dir[item+"/**/*_spec.rb"].sort) if stat.directory?
77
- end
78
-
79
110
  MSpec.register_tags_patterns config[:tags_patterns]
80
- MSpec.register_files files
111
+ MSpec.register_files files(@patterns)
81
112
 
82
113
  MSpec.process
83
114
  exit MSpec.exit_code