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,34 @@
1
+ class EqualUtf16Matcher
2
+ def initialize(expected)
3
+ @expected = expected
4
+ end
5
+
6
+ def matches?(actual)
7
+ @actual = actual
8
+ @actual == @expected || @actual == expected_swapped
9
+ end
10
+
11
+ def expected_swapped
12
+ if @expected.respond_to?(:to_str)
13
+ @expected_swapped ||= @expected.to_str.gsub(/(.)(.)/, '\2\1')
14
+ else
15
+ @expected_swapped ||= @expected.collect { |s| s.to_str.gsub(/(.)(.)/, '\2\1') }
16
+ end
17
+ end
18
+
19
+ def failure_message
20
+ ["Expected #{@actual.pretty_inspect}",
21
+ "to equal #{@expected.pretty_inspect} or #{expected_swapped.pretty_inspect}"]
22
+ end
23
+
24
+ def negative_failure_message
25
+ ["Expected #{@actual.pretty_inspect}",
26
+ "not to equal #{@expected.pretty_inspect} nor #{expected_swapped.pretty_inspect}"]
27
+ end
28
+ end
29
+
30
+ class Object
31
+ def equal_utf16(expected)
32
+ EqualUtf16Matcher.new(expected)
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ require 'mspec/matchers/stringsymboladapter'
2
+
3
+ class HaveConstantMatcher
4
+ include StringSymbolAdapter
5
+
6
+ def initialize(name)
7
+ @name = convert_name name
8
+ end
9
+
10
+ def matches?(mod)
11
+ @mod = mod
12
+ @mod.constants.include? @name
13
+ end
14
+
15
+ def failure_message
16
+ ["Expected #{@mod} to have constant '#{@name.to_s}'",
17
+ "but it does not"]
18
+ end
19
+
20
+ def negative_failure_message
21
+ ["Expected #{@mod} NOT to have constant '#{@name.to_s}'",
22
+ "but it does"]
23
+ end
24
+ end
25
+
26
+ class Object
27
+ def have_constant(name)
28
+ HaveConstantMatcher.new name
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ require 'mspec/matchers/method'
2
+
3
+ class HaveInstanceMethodMatcher < MethodMatcher
4
+ def matches?(mod)
5
+ @mod = mod
6
+ mod.instance_methods(@include_super).include? @method
7
+ end
8
+
9
+ def failure_message
10
+ ["Expected #{@mod} to have instance method '#{@method.to_s}'",
11
+ "but it does not"]
12
+ end
13
+
14
+ def negative_failure_message
15
+ ["Expected #{@mod} NOT to have instance method '#{@method.to_s}'",
16
+ "but it does"]
17
+ end
18
+ end
19
+
20
+ class Object
21
+ def have_instance_method(method, include_super=true)
22
+ HaveInstanceMethodMatcher.new method, include_super
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'mspec/matchers/method'
2
+
3
+ class HaveMethodMatcher < MethodMatcher
4
+ def matches?(mod)
5
+ @mod = mod
6
+ @mod.methods(@include_super).include? @method
7
+ end
8
+
9
+ def failure_message
10
+ ["Expected #{@mod} to have method '#{@method.to_s}'",
11
+ "but it does not"]
12
+ end
13
+
14
+ def negative_failure_message
15
+ ["Expected #{@mod} NOT to have method '#{@method.to_s}'",
16
+ "but it does"]
17
+ end
18
+ end
19
+
20
+ class Object
21
+ def have_method(method, include_super=true)
22
+ HaveMethodMatcher.new method, include_super
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'mspec/matchers/method'
2
+
3
+ class HavePrivateInstanceMethodMatcher < MethodMatcher
4
+ def matches?(mod)
5
+ @mod = mod
6
+ mod.private_instance_methods(@include_super).include? @method
7
+ end
8
+
9
+ def failure_message
10
+ ["Expected #{@mod} to have private instance method '#{@method.to_s}'",
11
+ "but it does not"]
12
+ end
13
+
14
+ def negative_failure_message
15
+ ["Expected #{@mod} NOT to have private instance method '#{@method.to_s}'",
16
+ "but it does"]
17
+ end
18
+ end
19
+
20
+ class Object
21
+ def have_private_instance_method(method, include_super=true)
22
+ HavePrivateInstanceMethodMatcher.new method, include_super
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ class IncludeMatcher
2
+ def initialize(*expected)
3
+ @expected = expected
4
+ end
5
+
6
+ def matches?(actual)
7
+ @actual = actual
8
+ @expected.each do |e|
9
+ @element = e
10
+ unless @actual.include?(e)
11
+ return false
12
+ end
13
+ end
14
+ return true
15
+ end
16
+
17
+ def failure_message
18
+ ["Expected #{@actual.inspect}", "to include #{@element.inspect}"]
19
+ end
20
+
21
+ def negative_failure_message
22
+ ["Expected #{@actual.inspect}", "not to include #{@element.inspect}"]
23
+ end
24
+ end
25
+
26
+ # Cannot override #include at the toplevel in MRI
27
+ module MSpec
28
+ def include(*expected)
29
+ IncludeMatcher.new(*expected)
30
+ end
31
+ module_function :include
32
+ end
@@ -0,0 +1,47 @@
1
+ class MatchYAMLMatcher
2
+
3
+ def initialize(expected)
4
+ if valid_yaml?(expected)
5
+ @expected = expected
6
+ else
7
+ @expected = expected.to_yaml
8
+ end
9
+ end
10
+
11
+ def matches?(actual)
12
+ @actual = actual
13
+ clean_yaml(@actual) == @expected
14
+ end
15
+
16
+ def failure_message
17
+ ["Expected #{@actual.inspect}", " to match #{@expected.inspect}"]
18
+ end
19
+
20
+ def negative_failure_message
21
+ ["Expected #{@actual.inspect}", " to match #{@expected.inspect}"]
22
+ end
23
+
24
+ protected
25
+
26
+ def clean_yaml(yaml)
27
+ yaml.gsub(/([^-])\s+\n/, "\\1\n")
28
+ end
29
+
30
+ def valid_yaml?(obj)
31
+ require 'yaml'
32
+ begin
33
+ YAML.load(obj)
34
+ rescue
35
+ false
36
+ else
37
+ true
38
+ end
39
+ end
40
+ end
41
+
42
+ class Object
43
+ def match_yaml(expected)
44
+ MatchYAMLMatcher.new(expected)
45
+ end
46
+ end
47
+
@@ -0,0 +1,14 @@
1
+ require 'mspec/matchers/stringsymboladapter'
2
+
3
+ class MethodMatcher
4
+ include StringSymbolAdapter
5
+
6
+ def initialize(method, include_super=true)
7
+ @include_super = include_super
8
+ @method = convert_name method
9
+ end
10
+
11
+ def matches?(mod)
12
+ raise Exception, "define #matches? in the subclass"
13
+ end
14
+ end
@@ -0,0 +1,67 @@
1
+ require 'mspec/helpers/io'
2
+
3
+ class OutputMatcher
4
+ def initialize(stdout, stderr)
5
+ @out = stdout
6
+ @err = stderr
7
+ end
8
+
9
+ def matches?(proc)
10
+ @saved_out = $stdout
11
+ @saved_err = $stderr
12
+ @stdout = $stdout = IOStub.new
13
+ @stderr = $stderr = IOStub.new
14
+
15
+ proc.call
16
+
17
+ unless @out.nil?
18
+ case @out
19
+ when Regexp
20
+ return false unless $stdout =~ @out
21
+ else
22
+ return false unless $stdout == @out
23
+ end
24
+ end
25
+
26
+ unless @err.nil?
27
+ case @err
28
+ when Regexp
29
+ return false unless $stderr =~ @err
30
+ else
31
+ return false unless $stderr == @err
32
+ end
33
+ end
34
+
35
+ return true
36
+ ensure
37
+ $stdout = @saved_out
38
+ $stderr = @saved_err
39
+ end
40
+
41
+ def failure_message
42
+ expected_out = "\n"
43
+ actual_out = "\n"
44
+ unless @out.nil?
45
+ expected_out << " $stdout: #{@out.inspect}\n"
46
+ actual_out << " $stdout: #{@stdout.chomp.inspect}\n"
47
+ end
48
+ unless @err.nil?
49
+ expected_out << " $stderr: #{@err.inspect}\n"
50
+ actual_out << " $stderr: #{@stderr.chomp.inspect}\n"
51
+ end
52
+ ["Expected:#{expected_out}", " got:#{actual_out}"]
53
+ end
54
+
55
+ def negative_failure_message
56
+ out = ""
57
+ out << " $stdout: #{@stdout.chomp.dump}\n" unless @out.nil?
58
+ out << " $stderr: #{@stderr.chomp.dump}\n" unless @err.nil?
59
+ ["Expected output not to be:\n", out]
60
+ end
61
+ end
62
+
63
+ class Object
64
+ def output(stdout=nil, stderr=nil)
65
+ OutputMatcher.new(stdout, stderr)
66
+ end
67
+ end
@@ -0,0 +1,71 @@
1
+ # require 'mspec/helpers/tmp'
2
+ # require 'fileutils'
3
+ #
4
+ # # Lower-level output speccing mechanism for a single
5
+ # # output stream. Unlike OutputMatcher which provides
6
+ # # methods to capture the output, we actually replace
7
+ # # the FD itself so that there is no reliance on a
8
+ # # certain method being used.
9
+ # class OutputToFDMatcher
10
+ # def initialize(expected, to)
11
+ # @to, @expected = to, expected
12
+ #
13
+ # case @to
14
+ # when STDOUT
15
+ # @to_name = "STDOUT"
16
+ # when STDERR
17
+ # @to_name = "STDERR"
18
+ # when IO
19
+ # @to_name = @to.object_id.to_s
20
+ # else
21
+ # raise ArgumentError, "#{@to.inspect} is not a supported output target"
22
+ # end
23
+ # end
24
+ #
25
+ # def matches?(block)
26
+ # old_to = @to.dup
27
+ # out = File.open(tmp("mspec_output_to_#{$$}_#{Time.now.to_i}"), 'w+')
28
+ #
29
+ # # Replacing with a file handle so that Readline etc. work
30
+ # @to.reopen out
31
+ #
32
+ # block.call
33
+ #
34
+ # ensure
35
+ # begin
36
+ # @to.reopen old_to
37
+ #
38
+ # out.rewind
39
+ # @actual = out.read
40
+ #
41
+ # case @expected
42
+ # when Regexp
43
+ # return !(@actual =~ @expected).nil?
44
+ # else
45
+ # return @actual == @expected
46
+ # end
47
+ #
48
+ # # Clean up
49
+ # ensure
50
+ # out.close unless out.closed?
51
+ # FileUtils.rm out.path
52
+ # end
53
+ #
54
+ # return true
55
+ # end
56
+ #
57
+ # def failure_message()
58
+ # ["Expected (#{@to_name}): #{@expected.inspect}\n",
59
+ # "#{'but got'.rjust(@to_name.length + 10)}: #{@actual.inspect}\nBacktrace"]
60
+ # end
61
+ #
62
+ # def negative_failure_message()
63
+ # ["Expected output (#{@to_name}) to NOT be:\n", @actual.inspect]
64
+ # end
65
+ # end
66
+ #
67
+ # class Object
68
+ # def output_to_fd(what, where = STDOUT)
69
+ # OutputToFDMatcher.new what, where
70
+ # end
71
+ # end
@@ -0,0 +1,48 @@
1
+ class RaiseErrorMatcher
2
+ def initialize(exception, message, &block)
3
+ @exception = exception
4
+ @message = message
5
+ @block = block
6
+ end
7
+
8
+ def matches?(proc)
9
+ proc.call
10
+ return false
11
+ rescue Exception => @actual
12
+ return false unless @exception === @actual
13
+ if @message then
14
+ case @message
15
+ when String then
16
+ return false if @message != @actual.message
17
+ when Regexp then
18
+ return false if @message !~ @actual.message
19
+ end
20
+ end
21
+
22
+ @block[@actual] if @block
23
+
24
+ return true
25
+ end
26
+
27
+ def failure_message
28
+ message = ["Expected #{@exception}#{%[ (#{@message})] if @message}"]
29
+
30
+ if @actual then
31
+ message << "but got #{@actual.class}#{%[ (#{@actual.message})] if @actual.message}"
32
+ else
33
+ message << "but no exception was raised"
34
+ end
35
+
36
+ message
37
+ end
38
+
39
+ def negative_failure_message
40
+ ["Expected to not get #{@exception}#{%[ (#{@message})] if @message}", ""]
41
+ end
42
+ end
43
+
44
+ class Object
45
+ def raise_error(exception=Exception, message=nil, &block)
46
+ RaiseErrorMatcher.new(exception, message, &block)
47
+ end
48
+ end
@@ -0,0 +1,24 @@
1
+ class RespondToMatcher
2
+ def initialize(expected)
3
+ @expected = expected
4
+ end
5
+
6
+ def matches?(actual)
7
+ @actual = actual
8
+ @actual.respond_to?(@expected)
9
+ end
10
+
11
+ def failure_message
12
+ ["Expected #{@actual.inspect} (#{@actual.class})", "to respond to #{@expected}"]
13
+ end
14
+
15
+ def negative_failure_message
16
+ ["Expected #{@actual.inspect} (#{@actual.class})", "not to respond to #{@expected}"]
17
+ end
18
+ end
19
+
20
+ class Object
21
+ def respond_to(expected)
22
+ RespondToMatcher.new(expected)
23
+ end
24
+ end