mspec 1.0.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.
Files changed (162) hide show
  1. data/LICENSE +22 -0
  2. data/README +101 -0
  3. data/Rakefile +44 -0
  4. data/bin/mkspec +7 -0
  5. data/bin/mspec +7 -0
  6. data/bin/mspec-ci +8 -0
  7. data/bin/mspec-run +8 -0
  8. data/bin/mspec-tag +8 -0
  9. data/lib/mspec.rb +6 -0
  10. data/lib/mspec/commands/mkspec.rb +147 -0
  11. data/lib/mspec/commands/mspec-ci.rb +71 -0
  12. data/lib/mspec/commands/mspec-run.rb +80 -0
  13. data/lib/mspec/commands/mspec-tag.rb +87 -0
  14. data/lib/mspec/commands/mspec.rb +143 -0
  15. data/lib/mspec/expectations.rb +2 -0
  16. data/lib/mspec/expectations/expectations.rb +12 -0
  17. data/lib/mspec/expectations/should.rb +23 -0
  18. data/lib/mspec/guards.rb +13 -0
  19. data/lib/mspec/guards/bug.rb +27 -0
  20. data/lib/mspec/guards/compliance.rb +18 -0
  21. data/lib/mspec/guards/conflict.rb +16 -0
  22. data/lib/mspec/guards/endian.rb +40 -0
  23. data/lib/mspec/guards/extensions.rb +12 -0
  24. data/lib/mspec/guards/guard.rb +120 -0
  25. data/lib/mspec/guards/noncompliance.rb +12 -0
  26. data/lib/mspec/guards/platform.rb +38 -0
  27. data/lib/mspec/guards/quarantine.rb +15 -0
  28. data/lib/mspec/guards/runner.rb +30 -0
  29. data/lib/mspec/guards/superuser.rb +15 -0
  30. data/lib/mspec/guards/support.rb +12 -0
  31. data/lib/mspec/guards/version.rb +40 -0
  32. data/lib/mspec/helpers.rb +6 -0
  33. data/lib/mspec/helpers/bignum.rb +5 -0
  34. data/lib/mspec/helpers/const_lookup.rb +5 -0
  35. data/lib/mspec/helpers/flunk.rb +5 -0
  36. data/lib/mspec/helpers/io.rb +13 -0
  37. data/lib/mspec/helpers/scratch.rb +17 -0
  38. data/lib/mspec/helpers/tmp.rb +32 -0
  39. data/lib/mspec/matchers.rb +16 -0
  40. data/lib/mspec/matchers/base.rb +95 -0
  41. data/lib/mspec/matchers/be_ancestor_of.rb +24 -0
  42. data/lib/mspec/matchers/be_close.rb +27 -0
  43. data/lib/mspec/matchers/be_empty.rb +20 -0
  44. data/lib/mspec/matchers/be_false.rb +20 -0
  45. data/lib/mspec/matchers/be_kind_of.rb +24 -0
  46. data/lib/mspec/matchers/be_nil.rb +20 -0
  47. data/lib/mspec/matchers/be_true.rb +20 -0
  48. data/lib/mspec/matchers/complain.rb +56 -0
  49. data/lib/mspec/matchers/eql.rb +26 -0
  50. data/lib/mspec/matchers/equal.rb +26 -0
  51. data/lib/mspec/matchers/equal_utf16.rb +34 -0
  52. data/lib/mspec/matchers/include.rb +32 -0
  53. data/lib/mspec/matchers/output.rb +67 -0
  54. data/lib/mspec/matchers/output_to_fd.rb +71 -0
  55. data/lib/mspec/matchers/raise_error.rb +48 -0
  56. data/lib/mspec/mocks.rb +3 -0
  57. data/lib/mspec/mocks/mock.rb +123 -0
  58. data/lib/mspec/mocks/object.rb +28 -0
  59. data/lib/mspec/mocks/proxy.rb +112 -0
  60. data/lib/mspec/runner.rb +13 -0
  61. data/lib/mspec/runner/actions.rb +6 -0
  62. data/lib/mspec/runner/actions/debug.rb +17 -0
  63. data/lib/mspec/runner/actions/filter.rb +40 -0
  64. data/lib/mspec/runner/actions/gdb.rb +17 -0
  65. data/lib/mspec/runner/actions/tag.rb +97 -0
  66. data/lib/mspec/runner/actions/tally.rb +80 -0
  67. data/lib/mspec/runner/actions/timer.rb +22 -0
  68. data/lib/mspec/runner/filters.rb +4 -0
  69. data/lib/mspec/runner/filters/match.rb +22 -0
  70. data/lib/mspec/runner/filters/profile.rb +54 -0
  71. data/lib/mspec/runner/filters/regexp.rb +7 -0
  72. data/lib/mspec/runner/filters/tag.rb +29 -0
  73. data/lib/mspec/runner/formatters.rb +7 -0
  74. data/lib/mspec/runner/formatters/dotted.rb +81 -0
  75. data/lib/mspec/runner/formatters/html.rb +87 -0
  76. data/lib/mspec/runner/formatters/specdoc.rb +27 -0
  77. data/lib/mspec/runner/formatters/spinner.rb +89 -0
  78. data/lib/mspec/runner/formatters/summary.rb +8 -0
  79. data/lib/mspec/runner/formatters/unit.rb +25 -0
  80. data/lib/mspec/runner/formatters/yaml.rb +43 -0
  81. data/lib/mspec/runner/mspec.rb +232 -0
  82. data/lib/mspec/runner/object.rb +20 -0
  83. data/lib/mspec/runner/shared.rb +12 -0
  84. data/lib/mspec/runner/state.rb +116 -0
  85. data/lib/mspec/runner/tag.rb +20 -0
  86. data/lib/mspec/utils/name_map.rb +130 -0
  87. data/lib/mspec/utils/options.rb +344 -0
  88. data/lib/mspec/utils/script.rb +77 -0
  89. data/lib/mspec/version.rb +3 -0
  90. data/spec/commands/mkspec_spec.rb +321 -0
  91. data/spec/commands/mspec_ci_spec.rb +139 -0
  92. data/spec/commands/mspec_run_spec.rb +146 -0
  93. data/spec/commands/mspec_spec.rb +359 -0
  94. data/spec/commands/mspec_tag_spec.rb +131 -0
  95. data/spec/expectations/expectations_spec.rb +16 -0
  96. data/spec/expectations/should_spec.rb +99 -0
  97. data/spec/guards/bug_spec.rb +137 -0
  98. data/spec/guards/compliance_spec.rb +70 -0
  99. data/spec/guards/conflict_spec.rb +20 -0
  100. data/spec/guards/endian_spec.rb +42 -0
  101. data/spec/guards/extensions_spec.rb +36 -0
  102. data/spec/guards/guard_spec.rb +355 -0
  103. data/spec/guards/noncompliance_spec.rb +36 -0
  104. data/spec/guards/platform_spec.rb +84 -0
  105. data/spec/guards/quarantine_spec.rb +19 -0
  106. data/spec/guards/runner_spec.rb +75 -0
  107. data/spec/guards/superuser_spec.rb +22 -0
  108. data/spec/guards/support_spec.rb +22 -0
  109. data/spec/guards/version_spec.rb +133 -0
  110. data/spec/helpers/bignum_spec.rb +11 -0
  111. data/spec/helpers/const_lookup_spec.rb +19 -0
  112. data/spec/helpers/flunk_spec.rb +15 -0
  113. data/spec/helpers/io_spec.rb +34 -0
  114. data/spec/helpers/scratch_spec.rb +22 -0
  115. data/spec/helpers/tmp_spec.rb +72 -0
  116. data/spec/matchers/base_spec.rb +180 -0
  117. data/spec/matchers/be_ancestor_of_spec.rb +28 -0
  118. data/spec/matchers/be_close_spec.rb +46 -0
  119. data/spec/matchers/be_empty_spec.rb +26 -0
  120. data/spec/matchers/be_false_spec.rb +28 -0
  121. data/spec/matchers/be_kind_of_spec.rb +29 -0
  122. data/spec/matchers/be_nil_spec.rb +27 -0
  123. data/spec/matchers/be_true_spec.rb +28 -0
  124. data/spec/matchers/complain_spec.rb +52 -0
  125. data/spec/matchers/eql_spec.rb +33 -0
  126. data/spec/matchers/equal_spec.rb +33 -0
  127. data/spec/matchers/equal_utf16_spec.rb +47 -0
  128. data/spec/matchers/include_spec.rb +37 -0
  129. data/spec/matchers/output_spec.rb +74 -0
  130. data/spec/matchers/output_to_fd_spec.rb +33 -0
  131. data/spec/matchers/raise_error_spec.rb +56 -0
  132. data/spec/mocks/mock_spec.rb +272 -0
  133. data/spec/mocks/proxy_spec.rb +259 -0
  134. data/spec/runner/actions/debug_spec.rb +61 -0
  135. data/spec/runner/actions/filter_spec.rb +84 -0
  136. data/spec/runner/actions/gdb_spec.rb +61 -0
  137. data/spec/runner/actions/tag_spec.rb +253 -0
  138. data/spec/runner/actions/tally_spec.rb +107 -0
  139. data/spec/runner/actions/timer_spec.rb +42 -0
  140. data/spec/runner/filters/a.yaml +4 -0
  141. data/spec/runner/filters/b.yaml +11 -0
  142. data/spec/runner/filters/match_spec.rb +44 -0
  143. data/spec/runner/filters/profile_spec.rb +117 -0
  144. data/spec/runner/filters/regexp_spec.rb +13 -0
  145. data/spec/runner/filters/tag_spec.rb +77 -0
  146. data/spec/runner/formatters/dotted_spec.rb +184 -0
  147. data/spec/runner/formatters/html_spec.rb +191 -0
  148. data/spec/runner/formatters/specdoc_spec.rb +57 -0
  149. data/spec/runner/formatters/spinner_spec.rb +78 -0
  150. data/spec/runner/formatters/summary_spec.rb +29 -0
  151. data/spec/runner/formatters/unit_spec.rb +71 -0
  152. data/spec/runner/formatters/yaml_spec.rb +123 -0
  153. data/spec/runner/mspec_spec.rb +393 -0
  154. data/spec/runner/shared_spec.rb +41 -0
  155. data/spec/runner/state_spec.rb +535 -0
  156. data/spec/runner/tag_spec.rb +93 -0
  157. data/spec/runner/tags.txt +3 -0
  158. data/spec/spec_helper.rb +46 -0
  159. data/spec/utils/name_map_spec.rb +178 -0
  160. data/spec/utils/options_spec.rb +862 -0
  161. data/spec/utils/script_spec.rb +240 -0
  162. metadata +217 -0
@@ -0,0 +1,93 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/runner/tag'
3
+
4
+ describe SpecTag do
5
+ it "accepts an optional string to parse into fields" do
6
+ tag = SpecTag.new "tag(comment):description"
7
+ tag.tag.should == "tag"
8
+ tag.comment.should == "comment"
9
+ tag.description.should == "description"
10
+ end
11
+ end
12
+
13
+ describe SpecTag, "#parse" do
14
+ before :each do
15
+ @tag = SpecTag.new
16
+ end
17
+
18
+ it "accepts 'tag(comment):description'" do
19
+ @tag.parse "tag(I'm real):Some#method returns a value"
20
+ @tag.tag.should == "tag"
21
+ @tag.comment.should == "I'm real"
22
+ @tag.description.should == "Some#method returns a value"
23
+ end
24
+
25
+ it "accepts 'tag:description'" do
26
+ @tag.parse "tag:Another#method"
27
+ @tag.tag.should == "tag"
28
+ @tag.comment.should == nil
29
+ @tag.description.should == "Another#method"
30
+ end
31
+
32
+ it "accepts 'tag():description'" do
33
+ @tag.parse "tag():Another#method"
34
+ @tag.tag.should == "tag"
35
+ @tag.comment.should == nil
36
+ @tag.description.should == "Another#method"
37
+ end
38
+
39
+ it "accepts 'tag:'" do
40
+ @tag.parse "tag:"
41
+ @tag.tag.should == "tag"
42
+ @tag.comment.should == nil
43
+ @tag.description.should == ""
44
+ end
45
+
46
+ it "accepts 'tag(bug:555):Another#method'" do
47
+ @tag.parse "tag(bug:555):Another#method"
48
+ @tag.tag.should == "tag"
49
+ @tag.comment.should == "bug:555"
50
+ @tag.description.should == "Another#method"
51
+ end
52
+
53
+ it "accepts 'tag(http://someplace.com/neato):Another#method'" do
54
+ @tag.parse "tag(http://someplace.com/neato):Another#method"
55
+ @tag.tag.should == "tag"
56
+ @tag.comment.should == "http://someplace.com/neato"
57
+ @tag.description.should == "Another#method"
58
+ end
59
+
60
+ it "ignores '#anything'" do
61
+ @tag.parse "# this could be a comment"
62
+ @tag.tag.should == nil
63
+ @tag.comment.should == nil
64
+ @tag.description.should == nil
65
+ end
66
+ end
67
+
68
+ describe SpecTag, "#to_s" do
69
+ it "formats itself as 'tag(comment):description'" do
70
+ tag = SpecTag.new("tag(comment):description")
71
+ tag.tag.should == "tag"
72
+ tag.comment.should == "comment"
73
+ tag.description.should == "description"
74
+ tag.to_s.should == "tag(comment):description"
75
+ end
76
+
77
+ it "formats itself as 'tag:description" do
78
+ tag = SpecTag.new("tag:description")
79
+ tag.tag.should == "tag"
80
+ tag.comment.should == nil
81
+ tag.description.should == "description"
82
+ tag.to_s.should == "tag:description"
83
+ end
84
+ end
85
+
86
+ describe SpecTag, "#==" do
87
+ it "returns true if the tags have the same fields" do
88
+ one = SpecTag.new "tag(this):unicorn"
89
+ two = SpecTag.new "tag(this):unicorn"
90
+ one.==(two).should == true
91
+ [one].==([two]).should == true
92
+ end
93
+ end
@@ -0,0 +1,3 @@
1
+ fail(broken):Some#method? works
2
+ incomplete(20%):The#best method ever
3
+ benchmark(0.01825):The#fastest method today
@@ -0,0 +1,46 @@
1
+ dir_path = File.dirname(__FILE__)
2
+ lib_path = File.expand_path(dir_path + '/../lib')
3
+ bin_path = File.expand_path(dir_path + '/..')
4
+ $:.unshift lib_path unless $:.include? lib_path
5
+ $:.unshift bin_path unless $:.include? bin_path
6
+
7
+ require 'mspec/helpers/io'
8
+ require 'mspec/helpers/scratch'
9
+
10
+ # Remove this when MRI has intelligent warnings
11
+ $VERBOSE = nil unless $VERBOSE
12
+
13
+ module Kernel
14
+ def pretty_inspect
15
+ inspect
16
+ end
17
+ end
18
+
19
+ class MOSConfig < Hash
20
+ def initialize
21
+ self[:includes] = []
22
+ self[:requires] = []
23
+ self[:flags] = []
24
+ self[:options] = []
25
+ self[:includes] = []
26
+ self[:excludes] = []
27
+ self[:patterns] = []
28
+ self[:xpatterns] = []
29
+ self[:tags] = []
30
+ self[:xtags] = []
31
+ self[:atags] = []
32
+ self[:astrings] = []
33
+ self[:target] = 'ruby'
34
+ self[:command] = nil
35
+ end
36
+ end
37
+
38
+ def new_option
39
+ config = MOSConfig.new
40
+ return MSpecOptions.new(config, "spec"), config
41
+ end
42
+
43
+ # Just to have an exception name output not be "Exception"
44
+ class MSpecExampleError < Exception
45
+ end
46
+
@@ -0,0 +1,178 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/utils/name_map'
3
+
4
+ module NameMapSpecs
5
+ class A
6
+ A = self
7
+
8
+ def self.a; end
9
+ def a; end
10
+ def c; end
11
+
12
+ class B
13
+ def b; end
14
+ end
15
+ end
16
+
17
+ class Error
18
+ end
19
+
20
+ class Fixnum
21
+ def f; end
22
+ end
23
+
24
+ def self.n; end
25
+ def n; end
26
+ end
27
+
28
+ describe NameMap, "#exception?" do
29
+ before :each do
30
+ @map = NameMap.new
31
+ end
32
+
33
+ it "returns true if the constant is Errno" do
34
+ @map.exception?("Errno").should == true
35
+ end
36
+
37
+ it "returns true if the constant is a kind of Exception" do
38
+ @map.exception?("Errno::EBADF").should == true
39
+ @map.exception?("LoadError").should == true
40
+ @map.exception?("SystemExit").should == true
41
+ end
42
+
43
+ it "returns false if the constant is not a kind of Exception" do
44
+ @map.exception?("NameMapSpecs::Error").should == false
45
+ @map.exception?("NameMapSpecs").should == false
46
+ end
47
+
48
+ it "returns false if the constant does not exist" do
49
+ @map.exception?("Nonexistent").should == false
50
+ end
51
+ end
52
+
53
+ describe NameMap, "#class_or_module" do
54
+ before :each do
55
+ @map = NameMap.new true
56
+ end
57
+
58
+ it "returns the constant specified by the string" do
59
+ @map.class_or_module("NameMapSpecs").should == NameMapSpecs
60
+ end
61
+
62
+ it "returns the constant specified by the 'A::B' string" do
63
+ @map.class_or_module("NameMapSpecs::A").should == NameMapSpecs::A
64
+ end
65
+
66
+ it "returns nil if the constant is not a class or module" do
67
+ @map.class_or_module("Float::MAX").should == nil
68
+ end
69
+
70
+ it "returns nil if the constant is in the set of excluded constants" do
71
+ excluded = %w[
72
+ MSpecScript
73
+ MkSpec
74
+ DTracer
75
+ NameMap
76
+ OptionParser
77
+ YAML
78
+ ]
79
+
80
+ excluded.each do |const|
81
+ @map.class_or_module(const).should == nil
82
+ end
83
+ end
84
+
85
+ it "returns nil if the constant does not exist" do
86
+ @map.class_or_module("Heaven").should == nil
87
+ @map.class_or_module("Hell").should == nil
88
+ @map.class_or_module("Bush::Brain").should == nil
89
+ end
90
+ end
91
+
92
+ describe NameMap, "#dir_name" do
93
+ before :each do
94
+ @map = NameMap.new
95
+ end
96
+
97
+ it "returns a directory name from the base name and constant" do
98
+ @map.dir_name("NameMapSpecs", 'spec/core').should == 'spec/core/namemapspecs'
99
+ end
100
+
101
+ it "returns a directory name from the components in the constants name" do
102
+ @map.dir_name("NameMapSpecs::A", 'spec').should == 'spec/namemapspecs/a'
103
+ @map.dir_name("NameMapSpecs::A::B", 'spec').should == 'spec/namemapspecs/a/b'
104
+ end
105
+
106
+ it "returns a directory name without 'class' for constants like TrueClass" do
107
+ @map.dir_name("TrueClass", 'spec').should == 'spec/true'
108
+ @map.dir_name("FalseClass", 'spec').should == 'spec/false'
109
+ end
110
+
111
+ it "returns 'exception' for the directory name of any Exception subclass" do
112
+ @map.dir_name("SystemExit", 'spec').should == 'spec/exception'
113
+ @map.dir_name("Errno::EBADF", 'spec').should == 'spec/exception'
114
+ end
115
+
116
+ it "returns 'class' for Class" do
117
+ @map.dir_name("Class", 'spec').should == 'spec/class'
118
+ end
119
+ end
120
+
121
+ # These specs do not cover all the mappings, but only describe how the
122
+ # name is derived when the hash item maps to a single value, a hash with
123
+ # a specific item, or a hash with a :default item.
124
+ describe NameMap, "#file_name" do
125
+ before :each do
126
+ @map = NameMap.new
127
+ end
128
+
129
+ it "returns the name of the spec file based on the constant and method" do
130
+ @map.file_name("[]=", "Array").should == "element_set_spec.rb"
131
+ end
132
+
133
+ it "returns the name of the spec file based on the special entry for the method" do
134
+ @map.file_name("~", "Regexp").should == "match_spec.rb"
135
+ @map.file_name("~", "Fixnum").should == "complement_spec.rb"
136
+ end
137
+
138
+ it "returns the name of the spec file based on the default entry for the method" do
139
+ @map.file_name("<<", "NameMapSpecs").should == "append_spec.rb"
140
+ end
141
+
142
+ it "uses the last component of the constant to look up the method name" do
143
+ @map.file_name("^", "NameMapSpecs::Fixnum").should == "bit_xor_spec.rb"
144
+ end
145
+ end
146
+
147
+ describe NameMap, "#namespace" do
148
+ before :each do
149
+ @map = NameMap.new
150
+ end
151
+
152
+ it "prepends the module to the constant name" do
153
+ @map.namespace("SubModule", Fixnum).should == "SubModule::Fixnum"
154
+ end
155
+
156
+ it "does not prepend Object, Class, or Module to the constant name" do
157
+ @map.namespace("Object", Fixnum).should == "Fixnum"
158
+ @map.namespace("Module", Integer).should == "Integer"
159
+ @map.namespace("Class", Float).should == "Float"
160
+ end
161
+ end
162
+
163
+ describe NameMap, "#map" do
164
+ before :each do
165
+ @map = NameMap.new
166
+ end
167
+
168
+ it "flattens an object hierarchy into a single Hash" do
169
+ @map.map({}, [NameMapSpecs]).should == {
170
+ "NameMapSpecs." => ["n"],
171
+ "NameMapSpecs#" => ["n"],
172
+ "NameMapSpecs::A." => ["a"],
173
+ "NameMapSpecs::A#" => ["a", "c"],
174
+ "NameMapSpecs::A::B#" => ["b"],
175
+ "NameMapSpecs::Fixnum#" => ["f"]
176
+ }
177
+ end
178
+ end
@@ -0,0 +1,862 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/utils/options'
3
+ require 'mspec/version'
4
+ require 'mspec/runner/mspec'
5
+ require 'mspec/runner/formatters'
6
+
7
+ describe MSpecOptions, "#parser" do
8
+ it "returns an OptionParser instance" do
9
+ MSpecOptions.new({}, "spec").parser.should be_kind_of(OptionParser)
10
+ end
11
+ end
12
+
13
+ describe "The -B, --config FILE option" do
14
+ before :each do
15
+ @options, @config = new_option
16
+ end
17
+
18
+ it "is enabled with #add_config { }" do
19
+ @options.should_receive(:on).with("-B", "--config FILE",
20
+ String, an_instance_of(String))
21
+ @options.add_config {}
22
+ end
23
+
24
+ it "calls the passed block" do
25
+ ["-B", "--config"].each do |opt|
26
+ ScratchPad.clear
27
+
28
+ @options.add_config { |x| ScratchPad.record x }
29
+ @options.parse [opt, "file"]
30
+ ScratchPad.recorded.should == "file"
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "The -n, --name RUBY_NAME option" do
36
+ before :each do
37
+ @verbose, $VERBOSE = $VERBOSE, nil
38
+ @options, @config = new_option
39
+ end
40
+
41
+ after :each do
42
+ $VERBOSE = @verbose
43
+ end
44
+
45
+ it "is enabled with #add_name" do
46
+ @options.should_receive(:on).with("-n", "--name RUBY_NAME",
47
+ String, an_instance_of(String))
48
+ @options.add_name
49
+ end
50
+
51
+ it "sets RUBY_NAME when invoked" do
52
+ Object.should_receive(:const_set).with(:RUBY_NAME, "name").twice
53
+ @options.add_name
54
+ @options.parse ["-n", "name"]
55
+ @options.parse ["--name", "name"]
56
+ end
57
+ end
58
+
59
+ describe "The -t, --target TARGET option" do
60
+ before :each do
61
+ @options, @config = new_option
62
+ @options.add_targets
63
+ end
64
+
65
+ it "is enabled with #add_targets" do
66
+ @options.stub!(:on)
67
+ @options.should_receive(:on).with("-t", "--target TARGET",
68
+ String, an_instance_of(String))
69
+ @options.add_targets
70
+ end
71
+
72
+ it "sets the target to 'ruby' and flags to verbose with TARGET 'ruby'" do
73
+ ["-t", "--target"].each do |opt|
74
+ @options.parse [opt, "ruby"]
75
+ @config[:target].should == "ruby"
76
+ @config[:flags].should include("-v")
77
+ end
78
+ end
79
+
80
+ it "sets the target to 'ruby19' with TARGET 'r19' or 'ruby19'" do
81
+ ["-t", "--target"].each do |opt|
82
+ ["r19", "ruby19"].each do |t|
83
+ @options.parse [opt, t]
84
+ @config[:target].should == "ruby19"
85
+ end
86
+ end
87
+ end
88
+
89
+ it "sets the target to 'jruby' with TARGET 'j' or 'jruby'" do
90
+ ["-t", "--target"].each do |opt|
91
+ ["j", "jruby"].each do |t|
92
+ @options.parse [opt, t]
93
+ @config[:target].should == "jruby"
94
+ end
95
+ end
96
+ end
97
+
98
+ it "sets the target to 'shotgun/rubinius' with TARGET 'x' or 'rubinius'" do
99
+ ["-t", "--target"].each do |opt|
100
+ ["x", "rubinius"].each do |t|
101
+ @options.parse [opt, t]
102
+ @config[:target].should == "shotgun/rubinius"
103
+ end
104
+ end
105
+ end
106
+
107
+ it "set the target to 'rbx' with TARGET 'rbx'" do
108
+ ["-t", "--target"].each do |opt|
109
+ ["X", "rbx"].each do |t|
110
+ @options.parse [opt, t]
111
+ @config[:target].should == "rbx"
112
+ end
113
+ end
114
+ end
115
+
116
+ it "sets the target to TARGET" do
117
+ ["-t", "--target"].each do |opt|
118
+ @options.parse [opt, "whateva"]
119
+ @config[:target].should == "whateva"
120
+ end
121
+ end
122
+ end
123
+
124
+ describe "The -T, --target-opt OPT option" do
125
+ before :each do
126
+ @options, @config = new_option
127
+ @options.add_targets
128
+ end
129
+
130
+ it "is enabled with #add_targets" do
131
+ @options.stub!(:on)
132
+ @options.should_receive(:on).with("-T", "--target-opt OPT",
133
+ String, an_instance_of(String))
134
+ @options.add_targets
135
+ end
136
+
137
+ it "adds OPT to flags" do
138
+ ["-T", "--target-opt"].each do |opt|
139
+ @config[:flags].delete "--whateva"
140
+ @options.parse [opt, "--whateva"]
141
+ @config[:flags].should include("--whateva")
142
+ end
143
+ end
144
+ end
145
+
146
+ describe "The -I, --include DIR option" do
147
+ before :each do
148
+ @options, @config = new_option
149
+ @options.add_targets
150
+ end
151
+
152
+ it "is enabled with #add_targets" do
153
+ @options.stub!(:on)
154
+ @options.should_receive(:on).with("-I", "--include DIR",
155
+ String, an_instance_of(String))
156
+ @options.add_targets
157
+ end
158
+
159
+ it "add DIR to the includes list" do
160
+ ["-I", "--include"].each do |opt|
161
+ @config[:includes].delete "-Ipackage"
162
+ @options.parse [opt, "package"]
163
+ @config[:includes].should include("-Ipackage")
164
+ end
165
+ end
166
+ end
167
+
168
+ describe "The -r, --require LIBRARY option" do
169
+ before :each do
170
+ @options, @config = new_option
171
+ @options.add_targets
172
+ end
173
+
174
+ it "is enabled with #add_targets" do
175
+ @options.stub!(:on)
176
+ @options.should_receive(:on).with("-r", "--require LIBRARY",
177
+ String, an_instance_of(String))
178
+ @options.add_targets
179
+ end
180
+
181
+ it "adds LIBRARY to the requires list" do
182
+ ["-r", "--require"].each do |opt|
183
+ @config[:requires].delete "-rlibrick"
184
+ @options.parse [opt, "librick"]
185
+ @config[:requires].should include("-rlibrick")
186
+ end
187
+ end
188
+ end
189
+
190
+ describe "The -X, --tags-dir DIR option" do
191
+ before :each do
192
+ @options, @config = new_option
193
+ @options.add_tags_dir
194
+ end
195
+
196
+ it "is enabled with #add_tags_dir" do
197
+ @options.should_receive(:on).with("-X", "--tags-dir DIR",
198
+ String, an_instance_of(String))
199
+ @options.add_tags_dir
200
+ end
201
+
202
+ it "sets the tags directory to DIR" do
203
+ ["-X", "--tags-dir"].each do |opt|
204
+ @config[:tags_dir] = nil
205
+ @options.parse [opt, "tags"]
206
+ @config[:tags_dir].should == "tags"
207
+ end
208
+ end
209
+ end
210
+
211
+ describe "The -f, --format FORMAT option" do
212
+ before :each do
213
+ @options, @config = new_option
214
+ @options.add_formatters
215
+ end
216
+
217
+ it "is enabled with #add_formatters" do
218
+ @options.stub!(:on)
219
+ @options.should_receive(:on).with("-f", "--format FORMAT",
220
+ String, an_instance_of(String))
221
+ @options.add_formatters
222
+ end
223
+
224
+ it "sets the SpecdocFormatter with FORMAT 's' or 'specdoc'" do
225
+ ["-f", "--format"].each do |opt|
226
+ ["s", "specdoc"].each do |f|
227
+ @config[:formatter] = nil
228
+ @options.parse [opt, f]
229
+ @config[:formatter].should == SpecdocFormatter
230
+ end
231
+ end
232
+ end
233
+
234
+ it "sets the HtmlFormatter with FORMAT 'h' or 'html'" do
235
+ ["-f", "--format"].each do |opt|
236
+ ["h", "html"].each do |f|
237
+ @config[:formatter] = nil
238
+ @options.parse [opt, f]
239
+ @config[:formatter].should == HtmlFormatter
240
+ end
241
+ end
242
+ end
243
+
244
+ it "sets the DottedFormatter with FORMAT 'd', 'dot' or 'dotted'" do
245
+ ["-f", "--format"].each do |opt|
246
+ ["d", "dot", "dotted"].each do |f|
247
+ @config[:formatter] = nil
248
+ @options.parse [opt, f]
249
+ @config[:formatter].should == DottedFormatter
250
+ end
251
+ end
252
+ end
253
+
254
+ it "sets the UnitdiffFormatter with FORMAT 'u', 'unit', or 'unitdiff'" do
255
+ ["-f", "--format"].each do |opt|
256
+ ["u", "unit", "unitdiff"].each do |f|
257
+ @config[:formatter] = nil
258
+ @options.parse [opt, f]
259
+ @config[:formatter].should == UnitdiffFormatter
260
+ end
261
+ end
262
+ end
263
+
264
+ it "sets the SummaryFormatter with FORMAT 'm' or 'summary'" do
265
+ ["-f", "--format"].each do |opt|
266
+ ["m", "summary"].each do |f|
267
+ @config[:formatter] = nil
268
+ @options.parse [opt, f]
269
+ @config[:formatter].should == SummaryFormatter
270
+ end
271
+ end
272
+ end
273
+
274
+ it "sets the SpinnerFormatter with FORMAT 'a', '*', or 'spin'" do
275
+ ["-f", "--format"].each do |opt|
276
+ ["a", "*", "spin"].each do |f|
277
+ @config[:formatter] = nil
278
+ @options.parse [opt, f]
279
+ @config[:formatter].should == SpinnerFormatter
280
+ end
281
+ end
282
+ end
283
+ end
284
+
285
+ describe "The -o, --output FILE option" do
286
+ before :each do
287
+ @options, @config = new_option
288
+ @options.add_formatters
289
+ end
290
+
291
+ it "is enabled with #add_formatters" do
292
+ @options.stub!(:on)
293
+ @options.should_receive(:on).with("-o", "--output FILE",
294
+ String, an_instance_of(String))
295
+ @options.add_formatters
296
+ end
297
+
298
+ it "sets the output to FILE" do
299
+ ["-o", "--output"].each do |opt|
300
+ @config[:output] = nil
301
+ @options.parse [opt, "some/file"]
302
+ @config[:output].should == "some/file"
303
+ end
304
+ end
305
+ end
306
+
307
+ describe "The -e, --example STR" do
308
+ before :each do
309
+ @options, @config = new_option
310
+ @options.add_filters
311
+ end
312
+
313
+ it "is enabled with #add_filters" do
314
+ @options.stub!(:on)
315
+ @options.should_receive(:on).with("-e", "--example STR",
316
+ String, an_instance_of(String))
317
+ @options.add_filters
318
+ end
319
+
320
+ it "adds STR to the includes list" do
321
+ ["-e", "--example"].each do |opt|
322
+ @config[:includes] = []
323
+ @options.parse [opt, "this spec"]
324
+ @config[:includes].should include("this spec")
325
+ end
326
+ end
327
+ end
328
+
329
+ describe "The -E, --exclude STR" do
330
+ before :each do
331
+ @options, @config = new_option
332
+ @options.add_filters
333
+ end
334
+
335
+ it "is enabled with #add_filters" do
336
+ @options.stub!(:on)
337
+ @options.should_receive(:on).with("-E", "--exclude STR",
338
+ String, an_instance_of(String))
339
+ @options.add_filters
340
+ end
341
+
342
+ it "adds STR to the excludes list" do
343
+ ["-E", "--exclude"].each do |opt|
344
+ @config[:excludes] = []
345
+ @options.parse [opt, "this spec"]
346
+ @config[:excludes].should include("this spec")
347
+ end
348
+ end
349
+ end
350
+
351
+ describe "The -p, --pattern PATTERN" do
352
+ before :each do
353
+ @options, @config = new_option
354
+ @options.add_filters
355
+ end
356
+
357
+ it "is enabled with #add_filters" do
358
+ @options.stub!(:on)
359
+ @options.should_receive(:on).with("-p", "--pattern PATTERN",
360
+ Regexp, an_instance_of(String))
361
+ @options.add_filters
362
+ end
363
+
364
+ it "adds PATTERN to the included patterns list" do
365
+ ["-p", "--pattern"].each do |opt|
366
+ @config[:patterns] = []
367
+ @options.parse [opt, "this spec"]
368
+ @config[:patterns].should include(/this spec/)
369
+ end
370
+ end
371
+ end
372
+
373
+ describe "The -P, --excl-pattern PATTERN" do
374
+ before :each do
375
+ @options, @config = new_option
376
+ @options.add_filters
377
+ end
378
+
379
+ it "is enabled with #add_filters" do
380
+ @options.stub!(:on)
381
+ @options.should_receive(:on).with("-P", "--excl-pattern PATTERN",
382
+ Regexp, an_instance_of(String))
383
+ @options.add_filters
384
+ end
385
+
386
+ it "adds PATTERN to the excluded patterns list" do
387
+ ["-P", "--excl-pattern"].each do |opt|
388
+ @config[:xpatterns] = []
389
+ @options.parse [opt, "this spec"]
390
+ @config[:xpatterns].should include(/this spec/)
391
+ end
392
+ end
393
+ end
394
+
395
+ describe "The -g, --tag TAG" do
396
+ before :each do
397
+ @options, @config = new_option
398
+ @options.add_filters
399
+ end
400
+
401
+ it "is enabled with #add_filters" do
402
+ @options.stub!(:on)
403
+ @options.should_receive(:on).with("-g", "--tag TAG",
404
+ String, an_instance_of(String))
405
+ @options.add_filters
406
+ end
407
+
408
+ it "adds TAG to the included tags list" do
409
+ ["-g", "--tag"].each do |opt|
410
+ @config[:tags] = []
411
+ @options.parse [opt, "this spec"]
412
+ @config[:tags].should include("this spec")
413
+ end
414
+ end
415
+ end
416
+
417
+ describe "The -G, --excl-tag TAG" do
418
+ before :each do
419
+ @options, @config = new_option
420
+ @options.add_filters
421
+ end
422
+
423
+ it "is enabled with #add_filters" do
424
+ @options.stub!(:on)
425
+ @options.should_receive(:on).with("-G", "--excl-tag TAG",
426
+ String, an_instance_of(String))
427
+ @options.add_filters
428
+ end
429
+
430
+ it "adds TAG to the excluded tags list" do
431
+ ["-G", "--excl-tag"].each do |opt|
432
+ @config[:xtags] = []
433
+ @options.parse [opt, "this spec"]
434
+ @config[:xtags].should include("this spec")
435
+ end
436
+ end
437
+ end
438
+
439
+ describe "The -w, --profile FILE option" do
440
+ before :each do
441
+ @options, @config = new_option
442
+ @options.add_filters
443
+ end
444
+
445
+ it "is enabled with #add_filters" do
446
+ @options.stub!(:on)
447
+ @options.should_receive(:on).with("-w", "--profile FILE",
448
+ String, an_instance_of(String))
449
+ @options.add_filters
450
+ end
451
+
452
+ it "adds FILE to the included profiles list" do
453
+ ["-w", "--profile"].each do |opt|
454
+ @config[:profiles] = []
455
+ @options.parse [opt, "spec/profiles/rails.yaml"]
456
+ @config[:profiles].should include("spec/profiles/rails.yaml")
457
+ end
458
+ end
459
+ end
460
+
461
+ describe "The -W, --excl-profile FILE option" do
462
+ before :each do
463
+ @options, @config = new_option
464
+ @options.add_filters
465
+ end
466
+
467
+ it "is enabled with #add_filters" do
468
+ @options.stub!(:on)
469
+ @options.should_receive(:on).with("-W", "--excl-profile FILE",
470
+ String, an_instance_of(String))
471
+ @options.add_filters
472
+ end
473
+
474
+ it "adds FILE to the excluded profiles list" do
475
+ ["-W", "--excl-profile"].each do |opt|
476
+ @config[:xprofiles] = []
477
+ @options.parse [opt, "spec/profiles/rails.yaml"]
478
+ @config[:xprofiles].should include("spec/profiles/rails.yaml")
479
+ end
480
+ end
481
+ end
482
+
483
+ describe "The -Z", "--dry-run option" do
484
+ before :each do
485
+ @options, @config = new_option
486
+ @options.add_pretend
487
+ end
488
+
489
+ it "is enabled with #add_pretend" do
490
+ @options.should_receive(:on).with("-Z", "--dry-run", an_instance_of(String))
491
+ @options.add_pretend
492
+ end
493
+
494
+ it "registers the MSpec pretend mode" do
495
+ MSpec.should_receive(:register_mode).with(:pretend).twice
496
+ ["-Z", "--dry-run"].each do |opt|
497
+ @options.parse opt
498
+ end
499
+ end
500
+ end
501
+
502
+ describe "The -H, --random option" do
503
+ before :each do
504
+ @options, @config = new_option
505
+ @options.add_randomize
506
+ end
507
+
508
+ it "is enabled with #add_randomize" do
509
+ @options.should_receive(:on).with("-H", "--random", an_instance_of(String))
510
+ @options.add_randomize
511
+ end
512
+
513
+ it "registers the MSpec randomize mode" do
514
+ MSpec.should_receive(:randomize).twice
515
+ ["-H", "--random"].each do |opt|
516
+ @options.parse opt
517
+ end
518
+ end
519
+ end
520
+
521
+ describe "The -V, --verbose option" do
522
+ before :each do
523
+ @options, @config = new_option
524
+ @options.add_verbose
525
+ end
526
+
527
+ it "is enabled with #add_verbose" do
528
+ @options.stub!(:on)
529
+ @options.should_receive(:on).with("-V", "--verbose", an_instance_of(String))
530
+ @options.add_verbose
531
+ end
532
+
533
+ it "registers a verbose output object with MSpec" do
534
+ MSpec.should_receive(:register).with(:start, anything()).twice
535
+ MSpec.should_receive(:register).with(:load, anything()).twice
536
+ ["-V", "--verbose"].each do |opt|
537
+ @options.parse opt
538
+ end
539
+ end
540
+ end
541
+
542
+ describe "The -m, --marker MARKER option" do
543
+ before :each do
544
+ @options, @config = new_option
545
+ @options.add_verbose
546
+ end
547
+
548
+ it "is enabled with #add_verbose" do
549
+ @options.stub!(:on)
550
+ @options.should_receive(:on).with("-m", "--marker MARKER",
551
+ String, an_instance_of(String))
552
+ @options.add_verbose
553
+ end
554
+
555
+ it "registers a marker output object with MSpec" do
556
+ MSpec.should_receive(:register).with(:load, anything()).twice
557
+ ["-m", "--marker"].each do |opt|
558
+ @options.parse [opt, ","]
559
+ end
560
+ end
561
+ end
562
+
563
+ describe "The --int-spec option" do
564
+ before :each do
565
+ @options, @config = new_option
566
+ @options.add_interrupt
567
+ end
568
+
569
+ it "is enabled with #add_interrupt" do
570
+ @options.should_receive(:on).with("--int-spec", an_instance_of(String))
571
+ @options.add_interrupt
572
+ end
573
+
574
+ it "sets the abort config option to false to only abort the running spec with ^C" do
575
+ @config[:abort] = true
576
+ @options.parse "--int-spec"
577
+ @config[:abort].should == false
578
+ end
579
+ end
580
+
581
+ describe "The -Y, --verify option" do
582
+ before :each do
583
+ @options, @config = new_option
584
+ @options.add_verify
585
+ end
586
+
587
+ it "is enabled with #add_interrupt" do
588
+ @options.stub!(:on)
589
+ @options.should_receive(:on).with("-Y", "--verify", an_instance_of(String))
590
+ @options.add_verify
591
+ end
592
+
593
+ it "sets the MSpec mode to :verify" do
594
+ MSpec.should_receive(:set_mode).with(:verify).twice
595
+ ["-Y", "--verify"].each do |m|
596
+ @options.parse m
597
+ end
598
+ end
599
+ end
600
+
601
+ describe "The -O, --report option" do
602
+ before :each do
603
+ @options, @config = new_option
604
+ @options.add_verify
605
+ end
606
+
607
+ it "is enabled with #add_interrupt" do
608
+ @options.stub!(:on)
609
+ @options.should_receive(:on).with("-O", "--report", an_instance_of(String))
610
+ @options.add_verify
611
+ end
612
+
613
+ it "sets the MSpec mode to :report" do
614
+ MSpec.should_receive(:set_mode).with(:report).twice
615
+ ["-O", "--report"].each do |m|
616
+ @options.parse m
617
+ end
618
+ end
619
+ end
620
+
621
+ describe "The -N, --add TAG option" do
622
+ before :each do
623
+ @options, @config = new_option
624
+ @options.add_tagging
625
+ end
626
+
627
+ it "is enabled with #add_tagging" do
628
+ @options.stub!(:on)
629
+ @options.should_receive(:on).with("-N", "--add TAG",
630
+ String, an_instance_of(String))
631
+ @options.add_tagging
632
+ end
633
+
634
+ it "sets the mode to :add and sets the tag to TAG" do
635
+ ["-N", "--add"].each do |opt|
636
+ @config[:tagger] = nil
637
+ @config[:tag] = nil
638
+ @options.parse [opt, "taggit"]
639
+ @config[:tagger].should == :add
640
+ @config[:tag].should == "taggit:"
641
+ end
642
+ end
643
+ end
644
+
645
+ describe "The -R, --del TAG option" do
646
+ before :each do
647
+ @options, @config = new_option
648
+ @options.add_tagging
649
+ end
650
+
651
+ it "is enabled with #add_tagging" do
652
+ @options.stub!(:on)
653
+ @options.should_receive(:on).with("-R", "--del TAG",
654
+ String, an_instance_of(String))
655
+ @options.add_tagging
656
+ end
657
+
658
+ it "it sets the mode to :del, the tag to TAG, and the outcome to :pass" do
659
+ ["-R", "--del"].each do |opt|
660
+ @config[:tagger] = nil
661
+ @config[:tag] = nil
662
+ @config[:outcome] = nil
663
+ @options.parse [opt, "taggit"]
664
+ @config[:tagger].should == :del
665
+ @config[:tag].should == "taggit:"
666
+ @config[:outcome].should == :pass
667
+ end
668
+ end
669
+ end
670
+
671
+ describe "The -Q, --pass option" do
672
+ before :each do
673
+ @options, @config = new_option
674
+ @options.add_tagging
675
+ end
676
+
677
+ it "is enabled with #add_tagging" do
678
+ @options.stub!(:on)
679
+ @options.should_receive(:on).with("-Q", "--pass", an_instance_of(String))
680
+ @options.add_tagging
681
+ end
682
+
683
+ it "sets the outcome to :pass" do
684
+ ["-Q", "--pass"].each do |opt|
685
+ @config[:outcome] = nil
686
+ @options.parse opt
687
+ @config[:outcome].should == :pass
688
+ end
689
+ end
690
+ end
691
+
692
+ describe "The -F, --fail option" do
693
+ before :each do
694
+ @options, @config = new_option
695
+ @options.add_tagging
696
+ end
697
+
698
+ it "is enabled with #add_tagging" do
699
+ @options.stub!(:on)
700
+ @options.should_receive(:on).with("-F", "--fail", an_instance_of(String))
701
+ @options.add_tagging
702
+ end
703
+
704
+ it "sets the outcome to :fail" do
705
+ ["-F", "--fail"].each do |opt|
706
+ @config[:outcome] = nil
707
+ @options.parse opt
708
+ @config[:outcome].should == :fail
709
+ end
710
+ end
711
+ end
712
+
713
+ describe "The -L, --all option" do
714
+ before :each do
715
+ @options, @config = new_option
716
+ @options.add_tagging
717
+ end
718
+
719
+ it "is enabled with #add_tagging" do
720
+ @options.stub!(:on)
721
+ @options.should_receive(:on).with("-L", "--all", an_instance_of(String))
722
+ @options.add_tagging
723
+ end
724
+
725
+ it "sets the outcome to :all" do
726
+ ["-L", "--all"].each do |opt|
727
+ @config[:outcome] = nil
728
+ @options.parse opt
729
+ @config[:outcome].should == :all
730
+ end
731
+ end
732
+ end
733
+
734
+ describe "The -K, --action-tag TAG option" do
735
+ before :each do
736
+ @options, @config = new_option
737
+ @options.add_action_filters
738
+ end
739
+
740
+ it "is enabled with #add_action_filters" do
741
+ @options.stub!(:on)
742
+ @options.should_receive(:on).with("-K", "--action-tag TAG",
743
+ String, an_instance_of(String))
744
+ @options.add_action_filters
745
+ end
746
+
747
+ it "adds TAG to the list of tags that trigger actions" do
748
+ ["-K", "--action-tag"].each do |opt|
749
+ @config[:atags] = []
750
+ @options.parse [opt, "action-tag"]
751
+ @config[:atags].should include("action-tag")
752
+ end
753
+ end
754
+ end
755
+
756
+ describe "The -S, --action-string STR option" do
757
+ before :each do
758
+ @options, @config = new_option
759
+ @options.add_action_filters
760
+ end
761
+
762
+ it "is enabled with #add_action_filters" do
763
+ @options.stub!(:on)
764
+ @options.should_receive(:on).with("-S", "--action-string STR",
765
+ String, an_instance_of(String))
766
+ @options.add_action_filters
767
+ end
768
+
769
+ it "adds STR to the list of spec descriptions that trigger actions" do
770
+ ["-S", "--action-string"].each do |opt|
771
+ @config[:astrings] = []
772
+ @options.parse [opt, "action-str"]
773
+ @config[:astrings].should include("action-str")
774
+ end
775
+ end
776
+ end
777
+
778
+ describe "The --spec-debug option" do
779
+ before :each do
780
+ @options, @config = new_option
781
+ @options.add_actions
782
+ end
783
+
784
+ it "is enabled with #add_actions" do
785
+ @options.stub!(:on)
786
+ @options.should_receive(:on).with("--spec-debug", an_instance_of(String))
787
+ @options.add_actions
788
+ end
789
+
790
+ it "enables the triggering the ruby debugger" do
791
+ @options.add_action_filters
792
+ @options.parse ["-S", "some spec"]
793
+
794
+ @config[:debugger] = nil
795
+ @options.parse "--spec-debug"
796
+ @config[:debugger].should == true
797
+ end
798
+ end
799
+
800
+ describe "The --spec-gdb option" do
801
+ before :each do
802
+ @options, @config = new_option
803
+ @options.add_actions
804
+ end
805
+
806
+ it "is enabled with #add_actions" do
807
+ @options.stub!(:on)
808
+ @options.should_receive(:on).with("--spec-gdb", an_instance_of(String))
809
+ @options.add_actions
810
+ end
811
+
812
+ it "enables triggering the gdb debugger" do
813
+ @options.add_action_filters
814
+ @options.parse ["-S", "some spec"]
815
+
816
+ @config[:gdb] = nil
817
+ @options.parse "--spec-gdb"
818
+ @config[:gdb].should == true
819
+ end
820
+ end
821
+
822
+ describe "The -v, --version option" do
823
+ before :each do
824
+ @options, @config = new_option
825
+ @options.add_version
826
+ end
827
+
828
+ it "is enabled with #add_version" do
829
+ @options.stub!(:on)
830
+ @options.should_receive(:on).with("-v", "--version", an_instance_of(String))
831
+ @options.add_version
832
+ end
833
+
834
+ it "prints the version and exits" do
835
+ @options.should_receive(:puts).twice
836
+ @options.should_receive(:exit).twice
837
+ ["-v", "--version"].each do |opt|
838
+ @options.parse opt
839
+ end
840
+ end
841
+ end
842
+
843
+ describe "The -h, --help option" do
844
+ before :each do
845
+ @options, @config = new_option
846
+ @options.add_help
847
+ end
848
+
849
+ it "is enabled with #add_help" do
850
+ @options.stub!(:on)
851
+ @options.should_receive(:on).with("-h", "--help", an_instance_of(String))
852
+ @options.add_help
853
+ end
854
+
855
+ it "prints help and exits" do
856
+ @options.should_receive(:puts).twice
857
+ @options.should_receive(:exit).twice
858
+ ["-h", "--help"].each do |opt|
859
+ @options.parse opt
860
+ end
861
+ end
862
+ end