rhodes-framework 1.0.10 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/Manifest.txt +159 -30
  2. data/Rakefile +3 -19
  3. data/lib/erb.rb +1 -1
  4. data/lib/rho/rho.rb +94 -107
  5. data/lib/rho/rhofsconnector.rb +4 -0
  6. data/lib/rho/rhoutils.rb +26 -0
  7. data/lib/rho/rhoviewhelpers.rb +1 -1
  8. data/lib/rhodes.rb +2 -2
  9. data/lib/rhoframework.rb +9 -9
  10. data/lib/rhom/rhom.rb +1 -1
  11. data/lib/rhom/rhom_db_adapter.rb +36 -15
  12. data/lib/rhom/rhom_db_adapterME.rb +2 -3
  13. data/lib/rhom/rhom_object.rb +14 -2
  14. data/lib/rhom/rhom_object_factory.rb +42 -11
  15. data/lib/version.rb +2 -2
  16. data/spec/README +1 -0
  17. data/spec/Rakefile +1 -0
  18. data/spec/{configs/account.rb → app/Account/config.rb} +0 -0
  19. data/spec/{configs/case.rb → app/Case/config.rb} +0 -0
  20. data/spec/app/Question/config.rb +3 -0
  21. data/spec/app/Settings/controller.rb +10 -0
  22. data/spec/app/Settings/index.erb +11 -0
  23. data/spec/app/SpecRunner/controller.rb +15 -0
  24. data/spec/app/SpecRunner/index.erb +14 -0
  25. data/spec/app/application.rb +4 -0
  26. data/spec/app/index.erb +17 -0
  27. data/spec/app/layout.erb +27 -0
  28. data/spec/app/loading.html +11 -0
  29. data/spec/app/mspec.rb +11 -0
  30. data/spec/app/mspec/expectations.rb +2 -0
  31. data/spec/app/mspec/expectations/expectations.rb +17 -0
  32. data/spec/app/mspec/expectations/should.rb +25 -0
  33. data/spec/app/mspec/fileutils.rb +1590 -0
  34. data/spec/app/mspec/guards.rb +16 -0
  35. data/spec/app/mspec/guards/background.rb +21 -0
  36. data/spec/app/mspec/guards/bug.rb +24 -0
  37. data/spec/app/mspec/guards/compliance.rb +37 -0
  38. data/spec/app/mspec/guards/conflict.rb +18 -0
  39. data/spec/app/mspec/guards/endian.rb +44 -0
  40. data/spec/app/mspec/guards/extensions.rb +20 -0
  41. data/spec/app/mspec/guards/guard.rb +166 -0
  42. data/spec/app/mspec/guards/noncompliance.rb +20 -0
  43. data/spec/app/mspec/guards/platform.rb +43 -0
  44. data/spec/app/mspec/guards/quarantine.rb +17 -0
  45. data/spec/app/mspec/guards/runner.rb +34 -0
  46. data/spec/app/mspec/guards/superuser.rb +17 -0
  47. data/spec/app/mspec/guards/support.rb +20 -0
  48. data/spec/app/mspec/guards/tty.rb +20 -0
  49. data/spec/app/mspec/guards/version.rb +38 -0
  50. data/spec/app/mspec/helpers.rb +11 -0
  51. data/spec/app/mspec/helpers/argv.rb +43 -0
  52. data/spec/app/mspec/helpers/bignum.rb +5 -0
  53. data/spec/app/mspec/helpers/const_lookup.rb +9 -0
  54. data/spec/app/mspec/helpers/environment.rb +23 -0
  55. data/spec/app/mspec/helpers/fixture.rb +20 -0
  56. data/spec/app/mspec/helpers/flunk.rb +5 -0
  57. data/spec/app/mspec/helpers/io.rb +17 -0
  58. data/spec/app/mspec/helpers/language_version.rb +20 -0
  59. data/spec/app/mspec/helpers/ruby_exe.rb +123 -0
  60. data/spec/app/mspec/helpers/scratch.rb +17 -0
  61. data/spec/app/mspec/helpers/tmp.rb +32 -0
  62. data/spec/app/mspec/matchers.rb +23 -0
  63. data/spec/app/mspec/matchers/base.rb +95 -0
  64. data/spec/app/mspec/matchers/be_an_instance_of.rb +26 -0
  65. data/spec/app/mspec/matchers/be_ancestor_of.rb +24 -0
  66. data/spec/app/mspec/matchers/be_close.rb +27 -0
  67. data/spec/app/mspec/matchers/be_empty.rb +20 -0
  68. data/spec/app/mspec/matchers/be_false.rb +20 -0
  69. data/spec/app/mspec/matchers/be_kind_of.rb +24 -0
  70. data/spec/app/mspec/matchers/be_nil.rb +20 -0
  71. data/spec/app/mspec/matchers/be_true.rb +20 -0
  72. data/spec/app/mspec/matchers/complain.rb +56 -0
  73. data/spec/app/mspec/matchers/eql.rb +26 -0
  74. data/spec/app/mspec/matchers/equal.rb +26 -0
  75. data/spec/app/mspec/matchers/equal_element.rb +78 -0
  76. data/spec/app/mspec/matchers/equal_utf16.rb +34 -0
  77. data/spec/app/mspec/matchers/have_constant.rb +30 -0
  78. data/spec/app/mspec/matchers/have_instance_method.rb +24 -0
  79. data/spec/app/mspec/matchers/have_method.rb +24 -0
  80. data/spec/app/mspec/matchers/have_private_instance_method.rb +24 -0
  81. data/spec/app/mspec/matchers/include.rb +32 -0
  82. data/spec/app/mspec/matchers/match_yaml.rb +47 -0
  83. data/spec/app/mspec/matchers/method.rb +14 -0
  84. data/spec/app/mspec/matchers/output.rb +67 -0
  85. data/spec/app/mspec/matchers/output_to_fd.rb +71 -0
  86. data/spec/app/mspec/matchers/raise_error.rb +48 -0
  87. data/spec/app/mspec/matchers/respond_to.rb +24 -0
  88. data/spec/app/mspec/matchers/stringsymboladapter.rb +8 -0
  89. data/spec/app/mspec/mocks.rb +3 -0
  90. data/spec/app/mspec/mocks/mock.rb +159 -0
  91. data/spec/app/mspec/mocks/object.rb +20 -0
  92. data/spec/app/mspec/mocks/proxy.rb +136 -0
  93. data/spec/app/mspec/pp.rb +893 -0
  94. data/spec/app/mspec/runner.rb +15 -0
  95. data/spec/app/mspec/runner/actions.rb +8 -0
  96. data/spec/app/mspec/runner/actions/debug.rb +17 -0
  97. data/spec/app/mspec/runner/actions/filter.rb +40 -0
  98. data/spec/app/mspec/runner/actions/gdb.rb +17 -0
  99. data/spec/app/mspec/runner/actions/tag.rb +133 -0
  100. data/spec/app/mspec/runner/actions/taglist.rb +56 -0
  101. data/spec/app/mspec/runner/actions/tagpurge.rb +56 -0
  102. data/spec/app/mspec/runner/actions/tally.rb +116 -0
  103. data/spec/app/mspec/runner/actions/timer.rb +22 -0
  104. data/spec/app/mspec/runner/context.rb +188 -0
  105. data/spec/app/mspec/runner/example.rb +34 -0
  106. data/spec/app/mspec/runner/exception.rb +43 -0
  107. data/spec/app/mspec/runner/filters.rb +4 -0
  108. data/spec/app/mspec/runner/filters/match.rb +22 -0
  109. data/spec/app/mspec/runner/filters/profile.rb +54 -0
  110. data/spec/app/mspec/runner/filters/regexp.rb +7 -0
  111. data/spec/app/mspec/runner/filters/tag.rb +29 -0
  112. data/spec/app/mspec/runner/formatters.rb +10 -0
  113. data/spec/app/mspec/runner/formatters/describe.rb +24 -0
  114. data/spec/app/mspec/runner/formatters/dotted.rb +98 -0
  115. data/spec/app/mspec/runner/formatters/file.rb +19 -0
  116. data/spec/app/mspec/runner/formatters/html.rb +81 -0
  117. data/spec/app/mspec/runner/formatters/method.rb +93 -0
  118. data/spec/app/mspec/runner/formatters/specdoc.rb +41 -0
  119. data/spec/app/mspec/runner/formatters/spinner.rb +99 -0
  120. data/spec/app/mspec/runner/formatters/summary.rb +11 -0
  121. data/spec/app/mspec/runner/formatters/unit.rb +21 -0
  122. data/spec/app/mspec/runner/formatters/yaml.rb +44 -0
  123. data/spec/app/mspec/runner/mspec.rb +361 -0
  124. data/spec/app/mspec/runner/object.rb +24 -0
  125. data/spec/app/mspec/runner/shared.rb +12 -0
  126. data/spec/app/mspec/runner/tag.rb +32 -0
  127. data/spec/app/mspec/utils/name_map.rb +129 -0
  128. data/spec/app/mspec/utils/options.rb +441 -0
  129. data/spec/app/mspec/utils/ruby_name.rb +8 -0
  130. data/spec/app/mspec/utils/script.rb +220 -0
  131. data/spec/app/mspec/utils/version.rb +53 -0
  132. data/spec/app/mspec/version.rb +5 -0
  133. data/spec/app/spec/fixtures/client_info.txt +2 -0
  134. data/spec/app/spec/fixtures/object_values.txt +90 -0
  135. data/spec/{rho_controller_spec.rb → app/spec/rho_controller_spec.rb} +4 -7
  136. data/spec/{rho_spec.rb → app/spec/rho_spec.rb} +15 -36
  137. data/spec/{rhom_object_factory_spec.rb → app/spec/rhom_object_factory_spec.rb} +108 -72
  138. data/spec/{rhom_spec.rb → app/spec/rhom_spec.rb} +8 -4
  139. data/spec/app/spec/spec_helper.rb +15 -0
  140. data/spec/app/spec/webview_spec.rb +27 -0
  141. data/spec/app/spec_runner.rb +26 -0
  142. data/spec/build.yml +28 -0
  143. data/spec/public/css/base.css +39 -0
  144. data/spec/public/css/blackberry.css +99 -0
  145. data/spec/public/css/iphone.css +392 -0
  146. data/spec/public/css/rho.css +3 -0
  147. data/spec/public/css/xhtml.css +114 -0
  148. data/spec/public/images/IUI_LICENSE.txt +21 -0
  149. data/spec/public/images/backButton.png +0 -0
  150. data/spec/public/images/blueButton.png +0 -0
  151. data/spec/public/images/cancel.png +0 -0
  152. data/spec/public/images/grayButton.png +0 -0
  153. data/spec/public/images/iui-logo-touch-icon.png +0 -0
  154. data/spec/public/images/listArrow.png +0 -0
  155. data/spec/public/images/listArrowSel.png +0 -0
  156. data/spec/public/images/listGroup.png +0 -0
  157. data/spec/public/images/loading.gif +0 -0
  158. data/spec/public/images/pinstripes.png +0 -0
  159. data/spec/public/images/right_button.png +0 -0
  160. data/spec/public/images/selection.png +0 -0
  161. data/spec/public/images/thumb.png +0 -0
  162. data/spec/public/images/toggle.png +0 -0
  163. data/spec/public/images/toggleOn.png +0 -0
  164. data/spec/public/images/toolButton.png +0 -0
  165. data/spec/public/images/toolButton_new.png +0 -0
  166. data/spec/public/images/toolbar.png +0 -0
  167. data/spec/public/images/whiteButton.png +0 -0
  168. data/spec/public/js/application.js +1 -0
  169. data/spec/public/js/jquery-1.2.6.min.js +32 -0
  170. data/spec/public/js/rho.js +4 -0
  171. data/spec/public/js/rhogeolocation-wm.js +59 -0
  172. data/spec/public/js/rhogeolocation.js +11 -0
  173. data/spec/rhoconfig.txt +19 -0
  174. metadata +169 -39
  175. data/History.txt +0 -37
  176. data/README.rdoc +0 -2
  177. data/lib/TestServe.rb +0 -9
  178. data/res/sqlite3/constants.rb +0 -49
  179. data/res/sqlite3/database.rb +0 -715
  180. data/res/sqlite3/driver/dl/api.rb +0 -154
  181. data/res/sqlite3/driver/dl/driver.rb +0 -307
  182. data/res/sqlite3/driver/native/driver.rb +0 -257
  183. data/res/sqlite3/errors.rb +0 -68
  184. data/res/sqlite3/pragmas.rb +0 -271
  185. data/res/sqlite3/resultset.rb +0 -176
  186. data/res/sqlite3/sqlite3_api.rb +0 -0
  187. data/res/sqlite3/statement.rb +0 -230
  188. data/res/sqlite3/translator.rb +0 -109
  189. data/res/sqlite3/value.rb +0 -57
  190. data/res/sqlite3/version.rb +0 -14
  191. data/rhodes.gemspec +0 -18
  192. data/spec/app_manifest.txt +0 -4
  193. data/spec/configs/contact.rb +0 -3
  194. data/spec/configs/employee.rb +0 -3
  195. data/spec/spec.opts +0 -1
  196. data/spec/spec_helper.rb +0 -49
  197. data/spec/stubs.rb +0 -39
  198. data/spec/syncdbtest.sqlite +0 -0
@@ -0,0 +1,12 @@
1
+ require 'mspec/runner/mspec'
2
+
3
+ class Object
4
+ def it_behaves_like(desc, meth, obj=nil)
5
+ send :before, :all do
6
+ @method = meth
7
+ @object = obj if obj
8
+ end
9
+
10
+ send :it_should_behave_like, desc.to_s
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ class SpecTag
2
+ attr_accessor :tag, :comment, :description
3
+
4
+ def initialize(string=nil)
5
+ parse(string) if string
6
+ end
7
+
8
+ def parse(string)
9
+ m = /^([^()#:]+)(\(([^)]+)?\))?:(.*)$/.match string
10
+ @tag, @comment, description = m.values_at(1, 3, 4) if m
11
+ @description = unescape description
12
+ end
13
+
14
+ def unescape(str)
15
+ return unless str
16
+ str = str[1..-2] if str[0] == ?" and str[-1] == ?"
17
+ str.gsub(/\\n/, "\n")
18
+ end
19
+
20
+ def escape(str)
21
+ str = %["#{str.gsub(/\n/, '\n')}"] if /\n/ =~ str
22
+ str
23
+ end
24
+
25
+ def to_s
26
+ "#{@tag}#{ "(#{@comment})" if @comment }:#{escape @description}"
27
+ end
28
+
29
+ def ==(o)
30
+ @tag == o.tag and @comment == o.comment and @description == o.description
31
+ end
32
+ end
@@ -0,0 +1,129 @@
1
+ require 'mspec/helpers/const_lookup'
2
+
3
+ class NameMap
4
+ MAP = {
5
+ '`' => 'backtick',
6
+ '+' => 'plus',
7
+ '-' => 'minus',
8
+ '+@' => 'uplus',
9
+ '-@' => 'uminus',
10
+ '*' => 'multiply',
11
+ '/' => 'divide',
12
+ '%' => 'modulo',
13
+ '<<' => {'Bignum' => 'left_shift',
14
+ 'Fixnum' => 'left_shift',
15
+ 'IO' => 'output',
16
+ :default => 'append' },
17
+ '>>' => 'right_shift',
18
+ '<' => 'lt',
19
+ '<=' => 'lte',
20
+ '>' => 'gt',
21
+ '>=' => 'gte',
22
+ '=' => 'assignment',
23
+ '==' => 'equal_value',
24
+ '===' => 'case_compare',
25
+ '<=>' => 'comparison',
26
+ '[]' => 'element_reference',
27
+ '[]=' => 'element_set',
28
+ '**' => 'exponent',
29
+ '!' => 'not',
30
+ '~' => {'Bignum' => 'complement',
31
+ 'Fixnum' => 'complement',
32
+ 'Regexp' => 'match',
33
+ 'String' => 'match' },
34
+ '!=' => 'not_equal',
35
+ '!~' => 'not_match',
36
+ '=~' => 'match',
37
+ '&' => {'Bignum' => 'bit_and',
38
+ 'Fixnum' => 'bit_and',
39
+ 'Array' => 'intersection',
40
+ 'TrueClass' => 'and',
41
+ 'FalseClass' => 'and',
42
+ 'NilClass' => 'and',
43
+ 'Set' => 'intersection' },
44
+ '|' => {'Bignum' => 'bit_or',
45
+ 'Fixnum' => 'bit_or',
46
+ 'Array' => 'union',
47
+ 'TrueClass' => 'or',
48
+ 'FalseClass' => 'or',
49
+ 'NilClass' => 'or',
50
+ 'Set' => 'union' },
51
+ '^' => {'Bignum' => 'bit_xor',
52
+ 'Fixnum' => 'bit_xor',
53
+ 'TrueClass' => 'xor',
54
+ 'FalseClass' => 'xor',
55
+ 'NilClass' => 'xor',
56
+ 'Set' => 'exclusion'},
57
+ }
58
+
59
+ EXCLUDED = %w[
60
+ MSpecScript
61
+ MkSpec
62
+ DTracer
63
+ NameMap
64
+ OptionParser
65
+ YAML
66
+ ]
67
+
68
+ def initialize(filter=false)
69
+ @seen = {}
70
+ @filter = filter
71
+ end
72
+
73
+ def exception?(name)
74
+ return false unless c = class_or_module(name)
75
+ c == Errno or c.ancestors.include? Exception
76
+ end
77
+
78
+ def class_or_module(c)
79
+ const = const_lookup(c)
80
+ filtered = @filter && EXCLUDED.include?(const.name)
81
+ return const if Module === const and not filtered
82
+ rescue NameError
83
+ end
84
+
85
+ def namespace(mod, const)
86
+ return const.to_s if mod.nil? or %w[Object Class Module].include? mod
87
+ "#{mod}::#{const}"
88
+ end
89
+
90
+ def map(hash, constants, mod=nil)
91
+ @seen = {} unless mod
92
+
93
+ constants.each do |const|
94
+ name = namespace mod, const
95
+ m = class_or_module name
96
+ next unless m and not @seen[m]
97
+ @seen[m] = true
98
+
99
+ ms = m.methods false
100
+ hash["#{name}."] = ms.sort unless ms.empty?
101
+
102
+ ms = m.public_instance_methods(false) +
103
+ m.protected_instance_methods(false)
104
+ hash["#{name}#"] = ms.sort unless ms.empty?
105
+
106
+ map hash, m.constants, name
107
+ end
108
+
109
+ hash
110
+ end
111
+
112
+ def dir_name(c, base)
113
+ return File.join(base, 'exception') if exception? c
114
+
115
+ c.split('::').inject(base) do |dir, name|
116
+ name.gsub!(/Class/, '') unless name == 'Class'
117
+ File.join dir, name.downcase
118
+ end
119
+ end
120
+
121
+ def file_name(m, c)
122
+ if MAP.key?(m)
123
+ name = MAP[m].is_a?(Hash) ? MAP[m][c.split('::').last] || MAP[m][:default] : MAP[m]
124
+ else
125
+ name = m.gsub(/[?!=]/, '')
126
+ end
127
+ "#{name}_spec.rb"
128
+ end
129
+ end
@@ -0,0 +1,441 @@
1
+ require 'mspec/version'
2
+
3
+ class MSpecOption
4
+ attr_reader :short, :long, :arg, :description, :block
5
+
6
+ def initialize(short, long, arg, description, block)
7
+ @short = short
8
+ @long = long
9
+ @arg = arg
10
+ @description = description
11
+ @block = block
12
+ end
13
+
14
+ def arg?
15
+ @arg != nil
16
+ end
17
+
18
+ def match?(opt)
19
+ opt == @short or opt == @long
20
+ end
21
+ end
22
+
23
+ # MSpecOptions provides a parser for command line options. It also
24
+ # provides a composable set of options from which the runner scripts
25
+ # can select for their particular functionality.
26
+ class MSpecOptions
27
+ # Raised if incorrect or incomplete formats are passed to #on.
28
+ class OptionError < Exception; end
29
+
30
+ # Raised if an unrecognized option is encountered.
31
+ class ParseError < Exception; end
32
+
33
+ attr_accessor :config, :banner, :width, :options
34
+
35
+ def initialize(banner="", width=30, config=nil)
36
+ @banner = banner
37
+ @config = config
38
+ @width = width
39
+ @options = []
40
+ @doc = []
41
+ @extra = []
42
+ @on_extra = lambda { |x|
43
+ raise ParseError, "Unrecognized option: #{x}" if x[0] == ?-
44
+ @extra << x
45
+ }
46
+
47
+ yield self if block_given?
48
+ end
49
+
50
+ # Registers an option. Acceptable formats for arguments are:
51
+ #
52
+ # on "-a", "description"
53
+ # on "-a", "--abdc", "description"
54
+ # on "-a", "ARG", "description"
55
+ # on "--abdc", "ARG", "description"
56
+ # on "-a", "--abdc", "ARG", "description"
57
+ #
58
+ # If an block is passed, it will be invoked when the option is
59
+ # matched. Not passing a block is permitted, but nonsensical.
60
+ def on(*args, &block)
61
+ raise OptionError, "option and description are required" if args.size < 2
62
+
63
+ description = args.pop
64
+ short, long, argument = nil
65
+ args.each do |arg|
66
+ if arg[0] == ?-
67
+ if arg[1] == ?-
68
+ long = arg
69
+ else
70
+ short = arg
71
+ end
72
+ else
73
+ argument = arg
74
+ end
75
+ end
76
+
77
+ add short, long, argument, description, block
78
+ end
79
+
80
+ # Adds documentation text for an option and adds an +MSpecOption+
81
+ # instance to the list of registered options.
82
+ def add(short, long, arg, description, block)
83
+ s = short ? short.dup : " "
84
+ s << (short ? ", " : " ") if long
85
+ doc " #{s}#{long} #{arg}".ljust(@width-1) + " #{description}"
86
+ @options << MSpecOption.new(short, long, arg, description, block)
87
+ end
88
+
89
+ # Searches all registered options to find a match for +opt+. Returns
90
+ # +nil+ if no registered options match.
91
+ def match?(opt)
92
+ @options.find { |o| o.match? opt }
93
+ end
94
+
95
+ # Processes an option. Calles the #on_extra block (or default) for
96
+ # unrecognized options. For registered options, possibly fetches an
97
+ # argument and invokes the option's block if it is not nil.
98
+ def process(argv, entry, opt, arg)
99
+ unless option = match?(opt)
100
+ @on_extra[entry]
101
+ else
102
+ if option.arg?
103
+ arg = argv.shift if arg.nil?
104
+ raise ParseError, "No argument provided for #{opt}" unless arg
105
+ end
106
+ option.block[arg] if option.block
107
+ end
108
+ option
109
+ end
110
+
111
+ # Splits a string at +n+ characters into the +opt+ and the +rest+.
112
+ # The +arg+ is set to +nil+ if +rest+ is an empty string.
113
+ def split(str, n)
114
+ opt = str[0, n]
115
+ rest = str[n, str.size]
116
+ arg = rest == "" ? nil : rest
117
+ return opt, arg, rest
118
+ end
119
+
120
+ # Parses an array of command line entries, calling blocks for
121
+ # registered options.
122
+ def parse(argv=ARGV)
123
+ argv = Array(argv).dup
124
+
125
+ while entry = argv.shift
126
+ # collect everything that is not an option
127
+ if entry[0] != ?- or entry.size < 2
128
+ @on_extra[entry]
129
+ next
130
+ end
131
+
132
+ # this is a long option
133
+ if entry[1] == ?-
134
+ opt, arg = entry.split "="
135
+ process argv, entry, opt, arg
136
+ next
137
+ end
138
+
139
+ # disambiguate short option group from short option with argument
140
+ opt, arg, rest = split entry, 2
141
+
142
+ # process first option
143
+ option = process argv, entry, opt, arg
144
+ next unless option and not option.arg?
145
+
146
+ # process the rest of the options
147
+ while rest.size > 0
148
+ opt, arg, rest = split rest, 1
149
+ opt = "-" + opt
150
+ option = process argv, opt, opt, arg
151
+ break if option.arg?
152
+ end
153
+ end
154
+
155
+ @extra
156
+ rescue ParseError => e
157
+ puts self
158
+ puts e
159
+ exit 1
160
+ end
161
+
162
+ # Adds a string of documentation text inline in the text generated
163
+ # from the options. See #on and #add.
164
+ def doc(str)
165
+ @doc << str
166
+ end
167
+
168
+ # Convenience method for providing -v, --version options.
169
+ def version(version, &block)
170
+ show = block || lambda { puts "#{File.basename $0} #{version}"; exit }
171
+ on "-v", "--version", "Show version", &show
172
+ end
173
+
174
+ # Convenience method for providing -h, --help options.
175
+ def help(&block)
176
+ help = block || lambda { puts self; exit 1 }
177
+ on "-h", "--help", "Show this message", &help
178
+ end
179
+
180
+ # Stores a block that will be called with unrecognized options
181
+ def on_extra(&block)
182
+ @on_extra = block
183
+ end
184
+
185
+ # Returns a string representation of the options and doc strings.
186
+ def to_s
187
+ @banner + "\n\n" + @doc.join("\n") + "\n"
188
+ end
189
+
190
+ # The methods below provide groups of options that
191
+ # are composed by the particular runners to provide
192
+ # their functionality
193
+
194
+ def configure(&block)
195
+ on("-B", "--config", "FILE",
196
+ "Load FILE containing configuration options", &block)
197
+ end
198
+
199
+ def name
200
+ on("-n", "--name", "RUBY_NAME",
201
+ "Set the value of RUBY_NAME (used to determine the implementation)") do |n|
202
+ Object.const_set :RUBY_NAME, n
203
+ end
204
+ end
205
+
206
+ def targets
207
+ on("-t", "--target", "TARGET",
208
+ "Implementation to run the specs, where:") do |t|
209
+ case t
210
+ when 'r', 'ruby'
211
+ config[:target] = 'ruby'
212
+ when 'r19', 'ruby19'
213
+ config[:target] = 'ruby1.9'
214
+ when 'x', 'rubinius'
215
+ config[:target] = './bin/rbx'
216
+ when 'X', 'rbx'
217
+ config[:target] = 'rbx'
218
+ when 'j', 'jruby'
219
+ config[:target] = 'jruby'
220
+ when 'i','ironruby'
221
+ config[:target] = 'ir'
222
+ else
223
+ config[:target] = t
224
+ end
225
+ end
226
+
227
+ doc ""
228
+ doc " r or ruby invokes ruby in PATH"
229
+ doc " r19, ruby19 or ruby1.9 invokes ruby1.9 in PATH"
230
+ doc " x or rubinius invokes ./bin/rbx"
231
+ doc " X or rbx invokes rbx in PATH"
232
+ doc " j or jruby invokes jruby in PATH"
233
+ doc " i or ironruby invokes ir in PATH\n"
234
+
235
+ on("-T", "--target-opt", "OPT",
236
+ "Pass OPT as a flag to the target implementation") do |t|
237
+ config[:flags] << t
238
+ end
239
+ on("-I", "--include", "DIR",
240
+ "Pass DIR through as the -I option to the target") do |d|
241
+ config[:includes] << "-I#{d}"
242
+ end
243
+ on("-r", "--require", "LIBRARY",
244
+ "Pass LIBRARY through as the -r option to the target") do |f|
245
+ config[:requires] << "-r#{f}"
246
+ end
247
+ end
248
+
249
+ def formatters
250
+ on("-f", "--format", "FORMAT",
251
+ "Formatter for reporting, where FORMAT is one of:") do |o|
252
+ case o
253
+ when 's', 'spec', 'specdoc'
254
+ config[:formatter] = SpecdocFormatter
255
+ when 'h', 'html'
256
+ config[:formatter] = HtmlFormatter
257
+ when 'd', 'dot', 'dotted'
258
+ config[:formatter] = DottedFormatter
259
+ when 'b', 'describe'
260
+ config[:formatter] = DescribeFormatter
261
+ when 'f', 'file'
262
+ config[:formatter] = FileFormatter
263
+ when 'u', 'unit', 'unitdiff'
264
+ config[:formatter] = UnitdiffFormatter
265
+ when 'm', 'summary'
266
+ config[:formatter] = SummaryFormatter
267
+ when 'a', '*', 'spin'
268
+ config[:formatter] = SpinnerFormatter
269
+ when 't', 'method'
270
+ config[:formatter] = MethodFormatter
271
+ when 'y', 'yaml'
272
+ config[:formatter] = YamlFormatter
273
+ else
274
+ puts "Unknown format: #{o}"
275
+ puts @parser
276
+ exit
277
+ end
278
+ end
279
+
280
+ doc ""
281
+ doc " s, spec, specdoc SpecdocFormatter"
282
+ doc " h, html, HtmlFormatter"
283
+ doc " d, dot, dotted DottedFormatter"
284
+ doc " f, file FileFormatter"
285
+ doc " u, unit, unitdiff UnitdiffFormatter"
286
+ doc " m, summary SummaryFormatter"
287
+ doc " a, *, spin SpinnerFormatter"
288
+ doc " t, method MethodFormatter"
289
+ doc " y, yaml YamlFormatter\n"
290
+
291
+ on("-o", "--output", "FILE",
292
+ "Write formatter output to FILE") do |f|
293
+ config[:output] = f
294
+ end
295
+ end
296
+
297
+ def filters
298
+ on("-e", "--example", "STR",
299
+ "Run examples with descriptions matching STR") do |o|
300
+ config[:includes] << o
301
+ end
302
+ on("-E", "--exclude", "STR",
303
+ "Exclude examples with descriptions matching STR") do |o|
304
+ config[:excludes] << o
305
+ end
306
+ on("-p", "--pattern", "PATTERN",
307
+ "Run examples with descriptions matching PATTERN") do |o|
308
+ config[:patterns] << Regexp.new(o)
309
+ end
310
+ on("-P", "--excl-pattern", "PATTERN",
311
+ "Exclude examples with descriptions matching PATTERN") do |o|
312
+ config[:xpatterns] << Regexp.new(o)
313
+ end
314
+ on("-g", "--tag", "TAG",
315
+ "Run examples with descriptions matching ones tagged with TAG") do |o|
316
+ config[:tags] << o
317
+ end
318
+ on("-G", "--excl-tag", "TAG",
319
+ "Exclude examples with descriptions matching ones tagged with TAG") do |o|
320
+ config[:xtags] << o
321
+ end
322
+ on("-w", "--profile", "FILE",
323
+ "Run examples for methods listed in the profile FILE") do |f|
324
+ config[:profiles] << f
325
+ end
326
+ on("-W", "--excl-profile", "FILE",
327
+ "Exclude examples for methods listed in the profile FILE") do |f|
328
+ config[:xprofiles] << f
329
+ end
330
+ end
331
+
332
+ def chdir
333
+ on("-C", "--chdir", "DIR",
334
+ "Change the working directory to DIR before running specs") do |d|
335
+ Dir.chdir d
336
+ end
337
+ end
338
+
339
+ def prefix
340
+ on("--prefix", "STR", "Prepend STR when resolving spec file names") do |p|
341
+ config[:prefix] = p
342
+ end
343
+ end
344
+
345
+ def pretend
346
+ on("-Z", "--dry-run",
347
+ "Invoke formatters and other actions, but don't execute the specs") do
348
+ MSpec.register_mode :pretend
349
+ end
350
+ end
351
+
352
+ def background
353
+ on("--background",
354
+ "Enable guard for specs that may hang in background processes") do
355
+ MSpec.register_mode :background
356
+ end
357
+ end
358
+
359
+ def unguarded
360
+ on("--unguarded", "Turn off all guards") do
361
+ MSpec.register_mode :unguarded
362
+ end
363
+ on("--no-ruby_bug", "Turn off the ruby_bug guard") do
364
+ MSpec.register_mode :no_ruby_bug
365
+ end
366
+ end
367
+
368
+ def randomize
369
+ on("-H", "--random",
370
+ "Randomize the list of spec files") do
371
+ MSpec.randomize
372
+ end
373
+ end
374
+
375
+ def verbose
376
+ on("-V", "--verbose", "Output the name of each file processed") do
377
+ obj = Object.new
378
+ def obj.start
379
+ @width = MSpec.retrieve(:files).inject(0) { |max, f| f.size > max ? f.size : max }
380
+ end
381
+ def obj.load
382
+ file = MSpec.retrieve :file
383
+ print "\n#{file.ljust(@width)}"
384
+ end
385
+ MSpec.register :start, obj
386
+ MSpec.register :load, obj
387
+ end
388
+
389
+ on("-m", "--marker", "MARKER",
390
+ "Output MARKER for each file processed") do |o|
391
+ obj = Object.new
392
+ obj.instance_variable_set :@marker, o
393
+ def obj.load
394
+ print @marker
395
+ end
396
+ MSpec.register :load, obj
397
+ end
398
+ end
399
+
400
+ def interrupt
401
+ on("--int-spec", "Control-C interupts the current spec only") do
402
+ config[:abort] = false
403
+ end
404
+ end
405
+
406
+ def verify
407
+ on("--report-on", "GUARD", "Report specs guarded by GUARD") do |g|
408
+ MSpec.register_mode :report_on
409
+ SpecGuard.guards << g.to_sym
410
+ end
411
+ on("-O", "--report", "Report guarded specs") do
412
+ MSpec.register_mode :report
413
+ end
414
+ on("-Y", "--verify",
415
+ "Verify that guarded specs pass and fail as expected") do
416
+ MSpec.register_mode :verify
417
+ end
418
+ end
419
+
420
+ def action_filters
421
+ on("-K", "--action-tag", "TAG",
422
+ "Spec descriptions marked with TAG will trigger the specified action") do |o|
423
+ config[:atags] << o
424
+ end
425
+ on("-S", "--action-string", "STR",
426
+ "Spec descriptions matching STR will trigger the specified action") do |o|
427
+ config[:astrings] << o
428
+ end
429
+ end
430
+
431
+ def actions
432
+ on("--spec-debug",
433
+ "Invoke the debugger when a spec description matches (see -K, -S)") do
434
+ config[:debugger] = true
435
+ end
436
+ on("--spec-gdb",
437
+ "Invoke Gdb when a spec description matches (see -K, -S)") do
438
+ config[:gdb] = true
439
+ end
440
+ end
441
+ end