rspec 0.7.5.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/CHANGES +60 -1
  2. data/EXAMPLES.rd +38 -19
  3. data/MIT-LICENSE +1 -1
  4. data/README +24 -17
  5. data/RELEASE-PLAN +117 -0
  6. data/Rakefile +24 -18
  7. data/TODO.0.8.0 +5 -0
  8. data/examples/auto_spec_name_generation_example.rb +18 -0
  9. data/examples/custom_expectation_matchers.rb +53 -0
  10. data/examples/dynamic_spec.rb +9 -0
  11. data/examples/io_processor_spec.rb +2 -2
  12. data/examples/mocking_example.rb +4 -4
  13. data/examples/partial_mock_example.rb +2 -2
  14. data/examples/predicate_example.rb +2 -2
  15. data/examples/stack_spec.rb +32 -36
  16. data/examples/stubbing_example.rb +19 -19
  17. data/examples/test_case_spec.rb +6 -6
  18. data/lib/spec.rb +3 -0
  19. data/lib/spec/callback.rb +8 -0
  20. data/lib/spec/callback/extensions/object.rb +4 -0
  21. data/lib/spec/deprecated.rb +3 -0
  22. data/lib/spec/expectations.rb +44 -17
  23. data/lib/spec/expectations/extensions.rb +1 -2
  24. data/lib/spec/expectations/extensions/object.rb +78 -130
  25. data/lib/spec/expectations/extensions/string_and_symbol.rb +17 -0
  26. data/lib/spec/expectations/handler.rb +47 -0
  27. data/lib/spec/expectations/should/base.rb +32 -29
  28. data/lib/spec/expectations/should/change.rb +1 -1
  29. data/lib/spec/expectations/should/have.rb +9 -17
  30. data/lib/spec/expectations/should/not.rb +54 -56
  31. data/lib/spec/expectations/should/should.rb +59 -65
  32. data/lib/spec/expectations/sugar.rb +27 -4
  33. data/lib/spec/matchers.rb +160 -0
  34. data/lib/spec/matchers/be.rb +161 -0
  35. data/lib/spec/matchers/be_close.rb +37 -0
  36. data/lib/spec/matchers/change.rb +120 -0
  37. data/lib/spec/matchers/eql.rb +43 -0
  38. data/lib/spec/matchers/equal.rb +43 -0
  39. data/lib/spec/matchers/has.rb +44 -0
  40. data/lib/spec/matchers/have.rb +140 -0
  41. data/lib/spec/matchers/include.rb +50 -0
  42. data/lib/spec/matchers/match.rb +41 -0
  43. data/lib/spec/matchers/raise_error.rb +100 -0
  44. data/lib/spec/matchers/respond_to.rb +35 -0
  45. data/lib/spec/matchers/satisfy.rb +47 -0
  46. data/lib/spec/matchers/throw_symbol.rb +75 -0
  47. data/lib/spec/mocks.rb +224 -1
  48. data/lib/spec/mocks/argument_expectation.rb +16 -2
  49. data/lib/spec/mocks/error_generator.rb +5 -3
  50. data/lib/spec/mocks/errors.rb +2 -2
  51. data/lib/spec/mocks/extensions/object.rb +1 -1
  52. data/lib/spec/mocks/message_expectation.rb +29 -19
  53. data/lib/spec/mocks/{mock_methods.rb → methods.rb} +5 -5
  54. data/lib/spec/mocks/mock.rb +2 -2
  55. data/lib/spec/mocks/mock_handler.rb +81 -68
  56. data/lib/spec/rake/spectask.rb +7 -12
  57. data/lib/spec/rake/verify_rcov.rb +1 -1
  58. data/lib/spec/runner.rb +117 -0
  59. data/lib/spec/runner/command_line.rb +8 -5
  60. data/lib/spec/runner/context.rb +13 -37
  61. data/lib/spec/runner/context_eval.rb +4 -3
  62. data/lib/spec/runner/context_runner.rb +7 -4
  63. data/lib/spec/runner/drb_command_line.rb +1 -1
  64. data/lib/spec/runner/execution_context.rb +3 -11
  65. data/lib/spec/runner/extensions/kernel.rb +7 -5
  66. data/lib/spec/runner/extensions/object.rb +4 -1
  67. data/lib/spec/runner/formatter/base_text_formatter.rb +11 -3
  68. data/lib/spec/runner/formatter/html_formatter.rb +21 -10
  69. data/lib/spec/runner/heckle_runner.rb +24 -8
  70. data/lib/spec/runner/heckle_runner_win.rb +10 -0
  71. data/lib/spec/runner/option_parser.rb +58 -13
  72. data/lib/spec/runner/spec_matcher.rb +22 -29
  73. data/lib/spec/runner/spec_parser.rb +1 -0
  74. data/lib/spec/runner/specification.rb +36 -22
  75. data/lib/spec/translator.rb +87 -0
  76. data/lib/spec/version.rb +16 -7
  77. data/spec/spec/callback/callback_container_spec.rb +27 -0
  78. data/spec/spec/callback/module_spec.rb +37 -0
  79. data/spec/spec/callback/object_spec.rb +90 -0
  80. data/spec/spec/callback/object_with_class_callback_spec.rb +19 -0
  81. data/spec/spec/expectations/differs/default_spec.rb +107 -0
  82. data/spec/spec/expectations/extensions/object_spec.rb +46 -0
  83. data/spec/spec/expectations/fail_with_spec.rb +71 -0
  84. data/spec/spec/expectations/should/should_==_spec.rb +19 -0
  85. data/spec/spec/expectations/should/should_=~_spec.rb +13 -0
  86. data/spec/spec/expectations/should/should_be_a_kind_of_spec.rb +21 -0
  87. data/spec/spec/expectations/should/should_be_an_instance_of_spec.rb +30 -0
  88. data/spec/spec/expectations/should/should_be_arbitrary_predicate_spec.rb +81 -0
  89. data/spec/spec/expectations/should/should_be_close_spec.rb +18 -0
  90. data/spec/spec/expectations/should/should_be_comparison_operator_spec.rb +44 -0
  91. data/spec/spec/expectations/should/should_be_false_spec.rb +39 -0
  92. data/spec/spec/expectations/should/should_be_spec.rb +11 -0
  93. data/spec/spec/expectations/should/should_be_true_spec.rb +27 -0
  94. data/spec/spec/expectations/should/should_change_spec.rb +184 -0
  95. data/spec/spec/expectations/should/should_eql_spec.rb +11 -0
  96. data/spec/spec/expectations/should/should_equal_spec.rb +11 -0
  97. data/spec/spec/expectations/should/should_have_at_least_spec.rb +53 -0
  98. data/spec/spec/expectations/should/should_have_at_most_spec.rb +45 -0
  99. data/spec/spec/expectations/should/should_have_key_spec.rb +21 -0
  100. data/spec/spec/expectations/should/should_have_spec.rb +64 -0
  101. data/spec/spec/expectations/should/should_include_spec.rb +59 -0
  102. data/spec/spec/expectations/should/should_match_spec.rb +25 -0
  103. data/spec/spec/expectations/should/should_not_==_spec.rb +15 -0
  104. data/spec/spec/expectations/should/should_not_be_a_kind_of_spec.rb +21 -0
  105. data/spec/spec/expectations/should/should_not_be_an_instance_of_spec.rb +11 -0
  106. data/spec/spec/expectations/should/should_not_be_arbitrary_predicate_spec.rb +68 -0
  107. data/spec/spec/expectations/should/should_not_be_spec.rb +11 -0
  108. data/spec/spec/expectations/should/should_not_change_spec.rb +24 -0
  109. data/spec/spec/expectations/should/should_not_eql_spec.rb +11 -0
  110. data/spec/spec/expectations/should/should_not_equal_spec.rb +11 -0
  111. data/spec/spec/expectations/should/should_not_have_key_spec.rb +15 -0
  112. data/spec/spec/expectations/should/should_not_include_spec.rb +58 -0
  113. data/spec/spec/expectations/should/should_not_match_spec.rb +11 -0
  114. data/spec/spec/expectations/should/should_not_raise_spec.rb +75 -0
  115. data/spec/spec/expectations/should/should_not_respond_to_spec.rb +15 -0
  116. data/spec/spec/expectations/should/should_not_throw_spec.rb +35 -0
  117. data/spec/spec/expectations/should/should_raise_spec.rb +66 -0
  118. data/spec/spec/expectations/should/should_respond_to_spec.rb +15 -0
  119. data/spec/spec/expectations/should/should_satisfy_spec.rb +35 -0
  120. data/spec/spec/expectations/should/should_throw_spec.rb +27 -0
  121. data/spec/spec/matchers/be_close_spec.rb +33 -0
  122. data/spec/spec/matchers/be_spec.rb +182 -0
  123. data/spec/spec/matchers/change_spec.rb +232 -0
  124. data/spec/spec/matchers/description_generation_spec.rb +147 -0
  125. data/spec/spec/matchers/eql_spec.rb +41 -0
  126. data/spec/spec/matchers/equal_spec.rb +41 -0
  127. data/spec/spec/matchers/handler_spec.rb +75 -0
  128. data/spec/spec/matchers/has_spec.rb +37 -0
  129. data/spec/spec/matchers/have_spec.rb +259 -0
  130. data/spec/spec/matchers/include_spec.rb +33 -0
  131. data/spec/spec/matchers/match_spec.rb +37 -0
  132. data/spec/spec/matchers/matcher_methods_spec.rb +85 -0
  133. data/spec/spec/matchers/raise_error_spec.rb +147 -0
  134. data/spec/spec/matchers/respond_to_spec.rb +30 -0
  135. data/spec/spec/matchers/satisfy_spec.rb +36 -0
  136. data/spec/spec/matchers/throw_symbol_spec.rb +59 -0
  137. data/spec/spec/mocks/any_number_of_times_spec.rb +34 -0
  138. data/spec/spec/mocks/at_least_spec.rb +97 -0
  139. data/spec/spec/mocks/at_most_spec.rb +97 -0
  140. data/spec/spec/mocks/bug_report_7611_spec.rb +19 -0
  141. data/spec/spec/mocks/bug_report_7805_spec.rb +22 -0
  142. data/spec/spec/mocks/bug_report_8165_spec.rb +31 -0
  143. data/spec/spec/mocks/bug_report_8302_spec.rb +26 -0
  144. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +74 -0
  145. data/spec/spec/mocks/mock_ordering_spec.rb +80 -0
  146. data/spec/spec/mocks/mock_spec.rb +407 -0
  147. data/spec/spec/mocks/multiple_return_value_spec.rb +113 -0
  148. data/spec/spec/mocks/null_object_mock_spec.rb +40 -0
  149. data/spec/spec/mocks/once_counts_spec.rb +56 -0
  150. data/spec/spec/mocks/options_hash_spec.rb +31 -0
  151. data/spec/spec/mocks/partial_mock_spec.rb +52 -0
  152. data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +64 -0
  153. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +92 -0
  154. data/spec/spec/mocks/precise_counts_spec.rb +56 -0
  155. data/spec/spec/mocks/record_messages_spec.rb +26 -0
  156. data/spec/spec/mocks/stub_spec.rb +159 -0
  157. data/spec/spec/mocks/twice_counts_spec.rb +67 -0
  158. data/spec/spec/runner/command_line_spec.rb +32 -0
  159. data/spec/spec/runner/context_matching_spec.rb +28 -0
  160. data/spec/spec/runner/context_runner_spec.rb +100 -0
  161. data/spec/spec/runner/context_spec.rb +405 -0
  162. data/spec/spec/runner/drb_command_line_spec.rb +74 -0
  163. data/spec/spec/runner/execution_context_spec.rb +52 -0
  164. data/spec/spec/runner/formatter/html_formatter_spec.rb +40 -0
  165. data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +21 -0
  166. data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +36 -0
  167. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +78 -0
  168. data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +18 -0
  169. data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +41 -0
  170. data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +21 -0
  171. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +46 -0
  172. data/spec/spec/runner/heckle_runner_spec.rb +63 -0
  173. data/spec/spec/runner/heckler_spec.rb +14 -0
  174. data/spec/spec/runner/kernel_ext_spec.rb +16 -0
  175. data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +45 -0
  176. data/spec/spec/runner/object_ext_spec.rb +11 -0
  177. data/spec/spec/runner/option_parser_spec.rb +269 -0
  178. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +47 -0
  179. data/spec/spec/runner/reporter_spec.rb +126 -0
  180. data/spec/spec/runner/spec_matcher_spec.rb +107 -0
  181. data/spec/spec/runner/spec_name_generation_spec.rb +102 -0
  182. data/spec/spec/runner/spec_parser_spec.rb +37 -0
  183. data/spec/spec/runner/specification_class_spec.rb +72 -0
  184. data/spec/spec/runner/specification_instance_spec.rb +160 -0
  185. data/spec/spec/runner/specification_should_raise_spec.rb +136 -0
  186. data/spec/spec/spec_classes.rb +102 -0
  187. data/spec/spec/translator_spec.rb +79 -0
  188. data/spec/spec_helper.rb +35 -0
  189. metadata +141 -9
  190. data/bin/drbspec +0 -3
  191. data/lib/spec/expectations/diff.rb +0 -28
  192. data/lib/spec/expectations/extensions/numeric.rb +0 -19
  193. data/lib/spec/expectations/extensions/string.rb +0 -22
  194. data/lib/spec/expectations/message_builder.rb +0 -13
@@ -0,0 +1,161 @@
1
+ module Spec
2
+ module Matchers
3
+
4
+ class Be #:nodoc:
5
+ def initialize(expected=nil, *args)
6
+ @expected = parse_expected(expected)
7
+ @args = args
8
+ @comparison = ""
9
+ end
10
+
11
+ def matches?(actual)
12
+ @actual = actual
13
+ return true if match_or_compare unless handling_predicate?
14
+ if handling_predicate?
15
+ begin
16
+ return @result = actual.__send__(predicate, *@args)
17
+ rescue => predicate_error
18
+ # This clause should be empty, but rcov will not report it as covered
19
+ # unless something (anything) is executed within the clause
20
+ rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
21
+ end
22
+
23
+ # This supports should_exist > target.exists? in the old world.
24
+ # We should consider deprecating that ability as in the new world
25
+ # you can't write "should exist" unless you have your own custom matcher.
26
+ begin
27
+ return @result = actual.__send__(present_tense_predicate, *@args)
28
+ rescue
29
+ raise predicate_error
30
+ end
31
+ end
32
+ return false
33
+ end
34
+
35
+ def failure_message
36
+ return "expected #{@comparison}#{expected}, got #{@actual.inspect}" unless handling_predicate?
37
+ return "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
38
+ end
39
+
40
+ def negative_failure_message
41
+ return "expected not #{expected}, got #{@actual.inspect}" unless handling_predicate?
42
+ return "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
43
+ end
44
+
45
+ def expected
46
+ return true if @expected == :true
47
+ return false if @expected == :false
48
+ return "nil" if @expected == :nil
49
+ return @expected.inspect
50
+ end
51
+
52
+ def match_or_compare
53
+ return @actual == true if @expected == :true
54
+ return @actual == false if @expected == :false
55
+ return @actual.nil? if @expected == :nil
56
+ return @actual < @expected if @less_than
57
+ return @actual <= @expected if @less_than_or_equal
58
+ return @actual >= @expected if @greater_than_or_equal
59
+ return @actual > @expected if @greater_than
60
+ return @actual.equal?(@expected)
61
+ end
62
+
63
+ def <(expected)
64
+ @less_than = true
65
+ @comparison = "< "
66
+ @expected = expected
67
+ self
68
+ end
69
+
70
+ def <=(expected)
71
+ @less_than_or_equal = true
72
+ @comparison = "<= "
73
+ @expected = expected
74
+ self
75
+ end
76
+
77
+ def >=(expected)
78
+ @greater_than_or_equal = true
79
+ @comparison = ">= "
80
+ @expected = expected
81
+ self
82
+ end
83
+
84
+ def >(expected)
85
+ @greater_than = true
86
+ @comparison = "> "
87
+ @expected = expected
88
+ self
89
+ end
90
+
91
+ def description
92
+ "be #{@comparison}#{@expected}"
93
+ end
94
+
95
+ private
96
+ def parse_expected(expected)
97
+ if Symbol === expected
98
+ ["be_an_","be_a_","be_"].each do |prefix|
99
+ @handling_predicate = true
100
+ return "#{expected.to_s.sub(prefix,"")}".to_sym if expected.starts_with?(prefix)
101
+ end
102
+ end
103
+ return expected
104
+ end
105
+
106
+ def predicate
107
+ "#{@expected.to_s}?".to_sym
108
+ end
109
+
110
+ def present_tense_predicate
111
+ "#{@expected.to_s}s?".to_sym
112
+ end
113
+
114
+ def args_to_s
115
+ return "" if @args.empty?
116
+ transformed_args = @args.collect{|a| a.inspect}
117
+ return "(#{transformed_args.join(', ')})"
118
+ end
119
+
120
+ def handling_predicate?
121
+ return false if [:true, :false, :nil].include?(@expected)
122
+ return @handling_predicate
123
+ end
124
+ end
125
+
126
+ # :call-seq:
127
+ # should be_true
128
+ # should be_false
129
+ # should be_nil
130
+ # should be_arbitrary_predicate(*args)
131
+ # should_not be_nil
132
+ # should_not be_arbitrary_predicate(*args)
133
+ #
134
+ # Given true, false, or nil, will pass if actual is
135
+ # true, false or nil (respectively).
136
+ #
137
+ # Predicates are any Ruby method that ends in a "?" and returns true or false.
138
+ # Given be_ followed by arbitrary_predicate (without the "?"), RSpec will match
139
+ # convert that into a query against the target object.
140
+ #
141
+ # The arbitrary_predicate feature will handle any predicate
142
+ # prefixed with "be_an_" (e.g. be_an_instance_of), "be_a_" (e.g. be_a_kind_of)
143
+ # or "be_" (e.g. be_empty), letting you choose the prefix that best suits the predicate.
144
+ #
145
+ # == Examples
146
+ #
147
+ # target.should be_true
148
+ # target.should be_false
149
+ # target.should be_nil
150
+ # target.should_not be_nil
151
+ #
152
+ # collection.should be_empty #passes if target.empty?
153
+ # "this string".should be_an_intance_of(String)
154
+ #
155
+ # target.should_not be_empty #passes unless target.empty?
156
+ # target.should_not be_old_enough(16) #passes unless target.old_enough?(16)
157
+ def be(*args)
158
+ Matchers::Be.new(*args)
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,37 @@
1
+ module Spec
2
+ module Matchers
3
+
4
+ class BeClose #:nodoc:
5
+ def initialize(expected, delta)
6
+ @expected = expected
7
+ @delta = delta
8
+ end
9
+
10
+ def matches?(actual)
11
+ @actual = actual
12
+ (@actual - @expected).abs < @delta
13
+ end
14
+
15
+ def failure_message
16
+ "expected #{@expected} +/- (<#{@delta}), got #{@actual}"
17
+ end
18
+
19
+ def description
20
+ "be close to #{@expected} (+- #{@delta})"
21
+ end
22
+ end
23
+
24
+ # :call-seq:
25
+ # should be_close(expected, delta)
26
+ # should_not be_close(expected, delta)
27
+ #
28
+ # Passes if actual == expected +/- delta
29
+ #
30
+ # == Example
31
+ #
32
+ # result.should be_close(3.0, 0.5)
33
+ def be_close(expected, delta)
34
+ Matchers::BeClose.new(expected, delta)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,120 @@
1
+ module Spec
2
+ module Matchers
3
+
4
+ #Based on patch from Wilson Bilkovich
5
+ class Change #:nodoc:
6
+ def initialize(receiver=nil, message=nil, &block)
7
+ @receiver = receiver
8
+ @message = message
9
+ @block = block
10
+ end
11
+
12
+ def matches?(target, &block)
13
+ if block
14
+ raise MatcherError.new(<<-EOF
15
+ block passed to should or should_not change must use {} instead of do/end
16
+ EOF
17
+ )
18
+ end
19
+ @target = target
20
+ execute_change
21
+ return false if @from && (@from != @before)
22
+ return false if @to && (@to != @after)
23
+ return (@before + @amount == @after) if @amount
24
+ return @before != @after
25
+ end
26
+
27
+ def execute_change
28
+ @before = @block.nil? ? @receiver.send(@message) : @block.call
29
+ @target.call
30
+ @after = @block.nil? ? @receiver.send(@message) : @block.call
31
+ end
32
+
33
+ def failure_message
34
+ if @to
35
+ "#{result} should have been changed to #{@to.inspect}, but is now #{@after.inspect}"
36
+ elsif @from
37
+ "#{result} should have initially been #{@from.inspect}, but was #{@before.inspect}"
38
+ elsif @amount
39
+ "#{result} should have been changed by #{@amount.inspect}, but was changed by #{actual_delta.inspect}"
40
+ else
41
+ "#{result} should have changed, but is still #{@before.inspect}"
42
+ end
43
+ end
44
+
45
+ def result
46
+ @message || "result"
47
+ end
48
+
49
+ def actual_delta
50
+ @after - @before
51
+ end
52
+
53
+ def negative_failure_message
54
+ "#{result} should not have changed, but did change from #{@before.inspect} to #{@after.inspect}"
55
+ end
56
+
57
+ def by(amount)
58
+ @amount = amount
59
+ self
60
+ end
61
+
62
+ def to(to)
63
+ @to = to
64
+ self
65
+ end
66
+
67
+ def from (from)
68
+ @from = from
69
+ self
70
+ end
71
+ end
72
+
73
+ # :call-seq:
74
+ # should change(receiver, message, &block)
75
+ # should change(receiver, message, &block).by(value)
76
+ # should change(receiver, message, &block).from(old).to(new)
77
+ # should_not change(receiver, message, &block)
78
+ #
79
+ # Allows you to specify that a Proc will cause some value to change.
80
+ #
81
+ # == Examples
82
+ #
83
+ # lambda {
84
+ # team.add_player(player)
85
+ # }.should change(roster, :count)
86
+ #
87
+ # lambda {
88
+ # team.add_player(player)
89
+ # }.should change(roster, :count).by(1)
90
+ #
91
+ # string = "string"
92
+ # lambda {
93
+ # string.reverse
94
+ # }.should change { string }.from("string").to("gnirts")
95
+ #
96
+ # lambda {
97
+ # person.happy_birthday
98
+ # }.should change(person, :birthday).from(32).to(33)
99
+ #
100
+ # lambda {
101
+ # employee.develop_great_new_social_networking_app
102
+ # }.should change(employee, :title).from("Mail Clerk").to("CEO")
103
+ #
104
+ # Evaluates +receiver.message+ or +block+ before and
105
+ # after it evaluates the c object (generated by the lambdas in the examples above).
106
+ #
107
+ # Then compares the values before and after the +receiver.message+ and
108
+ # evaluates the difference compared to the expected difference.
109
+ #
110
+ # == Warning
111
+ # +should_not+ +change+ only supports the form with no subsequent calls to
112
+ # +be+, +to+ or +from+.
113
+ #
114
+ # blocks passed to +should+ +change+ and +should_not+ +change+
115
+ # must use the <tt>{}</tt> form (<tt>do/end</tt> is not supported)
116
+ def change(target=nil, message=nil, &block)
117
+ Matchers::Change.new(target, message, &block)
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,43 @@
1
+ module Spec
2
+ module Matchers
3
+
4
+ class Eql #:nodoc:
5
+ def initialize(expected)
6
+ @expected = expected
7
+ end
8
+
9
+ def matches?(actual)
10
+ @actual = actual
11
+ @actual.eql?(@expected)
12
+ end
13
+
14
+ def failure_message
15
+ return "expected #{@expected.inspect}, got #{@actual.inspect} (using .eql?)", @expected, @actual
16
+ end
17
+
18
+ def negative_failure_message
19
+ return "expected #{@actual.inspect} not to equal #{@expected.inspect} (using .eql?)", @expected, @actual
20
+ end
21
+
22
+ def description
23
+ "eql #{@expected.inspect}"
24
+ end
25
+ end
26
+
27
+ # :call-seq:
28
+ # should eql(expected)
29
+ # should_not eql(expected)
30
+ #
31
+ # Passes if actual and expected are of equal value, but not necessarily the same object.
32
+ #
33
+ # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
34
+ #
35
+ # == Examples
36
+ #
37
+ # 5.should eql(5)
38
+ # 5.should_not eql(3)
39
+ def eql(expected)
40
+ Matchers::Eql.new(expected)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ module Spec
2
+ module Matchers
3
+
4
+ class Equal #:nodoc:
5
+ def initialize(expected)
6
+ @expected = expected
7
+ end
8
+
9
+ def matches?(actual)
10
+ @actual = actual
11
+ @actual.equal?(@expected)
12
+ end
13
+
14
+ def failure_message
15
+ return "expected #{@expected.inspect}, got #{@actual.inspect} (using .equal?)", @expected, @actual
16
+ end
17
+
18
+ def negative_failure_message
19
+ return "expected #{@actual.inspect} not to equal #{@expected.inspect} (using .equal?)", @expected, @actual
20
+ end
21
+
22
+ def description
23
+ "equal #{@expected.inspect}"
24
+ end
25
+ end
26
+
27
+ # :call-seq:
28
+ # should equal(expected)
29
+ # should_not equal(expected)
30
+ #
31
+ # Passes if actual and expected are the same object (object identity).
32
+ #
33
+ # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
34
+ #
35
+ # == Examples
36
+ #
37
+ # 5.should equal(5) #Fixnums are equal
38
+ # "5".should_not equal("5") #Strings that look the same are not the same object
39
+ def equal(expected)
40
+ Matchers::Equal.new(expected)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ module Spec
2
+ module Matchers
3
+
4
+ class Has #:nodoc:
5
+ def initialize(sym, *args)
6
+ @sym = sym
7
+ @args = args
8
+ end
9
+
10
+ def matches?(target)
11
+ @target = target
12
+ begin
13
+ return target.send(predicate, *@args)
14
+ rescue => @error
15
+ # This clause should be empty, but rcov will not report it as covered
16
+ # unless something (anything) is executed within the clause
17
+ rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
18
+ end
19
+ return false
20
+ end
21
+
22
+ def failure_message
23
+ raise @error if @error
24
+ "expected ##{predicate}(#{@args[0].inspect}) to return true, got false"
25
+ end
26
+
27
+ def negative_failure_message
28
+ raise @error if @error
29
+ "expected ##{predicate}(#{@args[0].inspect}) to return false, got true"
30
+ end
31
+
32
+ def description
33
+ "have key #{@args[0].inspect}"
34
+ end
35
+
36
+ private
37
+ def predicate
38
+ "#{@sym.to_s.sub("have_","has_")}?".to_sym
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end