rspec 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. data/CHANGES +125 -9
  2. data/EXAMPLES.rd +50 -27
  3. data/README +14 -1
  4. data/Rakefile +95 -42
  5. data/UPGRADE +31 -0
  6. data/bin/spec +0 -1
  7. data/bin/spec_translator +6 -0
  8. data/examples/auto_spec_description_example.rb +19 -0
  9. data/examples/{setup_teardown_example.rb → before_and_after_example.rb} +6 -6
  10. data/examples/behave_as_example.rb +45 -0
  11. data/examples/custom_expectation_matchers.rb +13 -12
  12. data/examples/dynamic_spec.rb +2 -2
  13. data/examples/file_accessor_spec.rb +2 -2
  14. data/examples/greeter_spec.rb +3 -3
  15. data/examples/helper_method_example.rb +2 -2
  16. data/examples/io_processor_spec.rb +4 -4
  17. data/examples/legacy_spec.rb +10 -0
  18. data/examples/mocking_example.rb +5 -5
  19. data/examples/multi_threaded_behaviour_runner.rb +25 -0
  20. data/examples/partial_mock_example.rb +4 -4
  21. data/examples/predicate_example.rb +4 -4
  22. data/examples/priority.txt +1 -0
  23. data/examples/shared_behaviours_example.rb +31 -0
  24. data/examples/stack_spec.rb +52 -69
  25. data/examples/stubbing_example.rb +10 -10
  26. data/examples/test_case_adapter_example.rb +26 -0
  27. data/examples/test_case_spec.rb +6 -6
  28. data/lib/spec.rb +9 -4
  29. data/lib/spec/dsl.rb +10 -0
  30. data/lib/spec/dsl/behaviour.rb +189 -0
  31. data/lib/spec/dsl/behaviour_callbacks.rb +43 -0
  32. data/lib/spec/dsl/behaviour_eval.rb +170 -0
  33. data/lib/spec/dsl/behaviour_factory.rb +32 -0
  34. data/lib/spec/dsl/composite_proc_builder.rb +28 -0
  35. data/lib/spec/dsl/configuration.rb +38 -0
  36. data/lib/spec/dsl/description.rb +34 -0
  37. data/lib/spec/dsl/example.rb +114 -0
  38. data/lib/spec/dsl/example_matcher.rb +28 -0
  39. data/lib/spec/{runner/spec_should_raise_handler.rb → dsl/example_should_raise_handler.rb} +4 -4
  40. data/lib/spec/expectations.rb +0 -3
  41. data/lib/spec/expectations/differs/default.rb +0 -1
  42. data/lib/spec/expectations/extensions.rb +0 -1
  43. data/lib/spec/expectations/extensions/object.rb +10 -53
  44. data/lib/spec/expectations/handler.rb +14 -18
  45. data/lib/spec/extensions.rb +1 -0
  46. data/lib/spec/extensions/object.rb +6 -0
  47. data/lib/spec/matchers.rb +19 -21
  48. data/lib/spec/matchers/be.rb +40 -11
  49. data/lib/spec/matchers/be_close.rb +2 -2
  50. data/lib/spec/matchers/operator_matcher.rb +52 -0
  51. data/lib/spec/matchers/respond_to.rb +21 -11
  52. data/lib/spec/mocks.rb +5 -28
  53. data/lib/spec/mocks/argument_constraint_matchers.rb +12 -0
  54. data/lib/spec/mocks/argument_expectation.rb +7 -4
  55. data/lib/spec/mocks/methods.rb +11 -16
  56. data/lib/spec/mocks/mock.rb +6 -3
  57. data/lib/spec/mocks/{mock_handler.rb → proxy.rb} +4 -7
  58. data/lib/spec/mocks/space.rb +28 -0
  59. data/lib/spec/mocks/spec_methods.rb +30 -0
  60. data/lib/spec/rake/spectask.rb +23 -21
  61. data/lib/spec/rake/verify_rcov.rb +1 -0
  62. data/lib/spec/runner.rb +88 -35
  63. data/lib/spec/runner/backtrace_tweaker.rb +2 -1
  64. data/lib/spec/runner/behaviour_runner.rb +102 -0
  65. data/lib/spec/runner/command_line.rb +5 -17
  66. data/lib/spec/runner/drb_command_line.rb +2 -2
  67. data/lib/spec/runner/extensions/kernel.rb +22 -9
  68. data/lib/spec/runner/formatter.rb +4 -0
  69. data/lib/spec/runner/formatter/base_formatter.rb +63 -0
  70. data/lib/spec/runner/formatter/base_text_formatter.rb +22 -52
  71. data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +25 -0
  72. data/lib/spec/runner/formatter/failing_examples_formatter.rb +22 -0
  73. data/lib/spec/runner/formatter/html_formatter.rb +74 -29
  74. data/lib/spec/runner/formatter/progress_bar_formatter.rb +6 -8
  75. data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
  76. data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
  77. data/lib/spec/runner/formatter/specdoc_formatter.rb +6 -6
  78. data/lib/spec/runner/heckle_runner.rb +8 -7
  79. data/lib/spec/runner/option_parser.rb +136 -55
  80. data/lib/spec/runner/options.rb +26 -0
  81. data/lib/spec/runner/reporter.rb +38 -31
  82. data/lib/spec/runner/spec_parser.rb +22 -13
  83. data/lib/spec/test_case_adapter.rb +10 -0
  84. data/lib/spec/translator.rb +103 -86
  85. data/lib/spec/version.rb +7 -15
  86. data/plugins/mock_frameworks/flexmock.rb +27 -0
  87. data/plugins/mock_frameworks/mocha.rb +21 -0
  88. data/plugins/mock_frameworks/rspec.rb +18 -0
  89. data/spec/spec/dsl/behaviour_eval_spec.rb +49 -0
  90. data/spec/spec/dsl/behaviour_factory_spec.rb +30 -0
  91. data/spec/spec/dsl/behaviour_spec.rb +508 -0
  92. data/spec/spec/dsl/composite_proc_builder_spec.rb +57 -0
  93. data/spec/spec/dsl/configuration_spec.rb +43 -0
  94. data/spec/spec/dsl/description_spec.rb +51 -0
  95. data/spec/spec/dsl/example_class_spec.rb +24 -0
  96. data/spec/spec/dsl/example_instance_spec.rb +140 -0
  97. data/spec/spec/dsl/example_should_raise_spec.rb +137 -0
  98. data/spec/spec/dsl/predicate_matcher_spec.rb +21 -0
  99. data/spec/spec/dsl/shared_behaviour_spec.rb +186 -0
  100. data/spec/spec/expectations/differs/default_spec.rb +12 -12
  101. data/spec/spec/expectations/extensions/object_spec.rb +10 -10
  102. data/spec/spec/expectations/fail_with_spec.rb +20 -20
  103. data/spec/spec/matchers/be_close_spec.rb +37 -31
  104. data/spec/spec/matchers/be_spec.rb +50 -41
  105. data/spec/spec/matchers/change_spec.rb +54 -54
  106. data/spec/spec/matchers/description_generation_spec.rb +43 -31
  107. data/spec/spec/matchers/eql_spec.rb +24 -37
  108. data/spec/spec/matchers/equal_spec.rb +24 -37
  109. data/spec/spec/matchers/exist_spec.rb +48 -0
  110. data/spec/spec/matchers/handler_spec.rb +36 -23
  111. data/spec/spec/matchers/has_spec.rb +8 -8
  112. data/spec/spec/matchers/have_spec.rb +38 -38
  113. data/spec/spec/matchers/include_spec.rb +6 -6
  114. data/spec/spec/matchers/match_spec.rb +8 -8
  115. data/spec/spec/matchers/matcher_methods_spec.rb +24 -31
  116. data/spec/spec/matchers/raise_error_spec.rb +34 -34
  117. data/spec/spec/matchers/respond_to_spec.rb +32 -8
  118. data/spec/spec/matchers/satisfy_spec.rb +6 -6
  119. data/spec/spec/matchers/should_===_spec.rb +38 -0
  120. data/spec/spec/matchers/should_==_spec.rb +37 -0
  121. data/spec/spec/matchers/should_=~_spec.rb +36 -0
  122. data/spec/spec/matchers/throw_symbol_spec.rb +47 -55
  123. data/spec/spec/mocks/any_number_of_times_spec.rb +16 -21
  124. data/spec/spec/mocks/argument_expectation_spec.rb +3 -3
  125. data/spec/spec/mocks/at_least_spec.rb +30 -30
  126. data/spec/spec/mocks/at_most_spec.rb +53 -57
  127. data/spec/spec/mocks/bug_report_10260_spec.rb +8 -0
  128. data/spec/spec/mocks/bug_report_7611_spec.rb +3 -3
  129. data/spec/spec/mocks/bug_report_7805_spec.rb +3 -3
  130. data/spec/spec/mocks/bug_report_8165_spec.rb +5 -5
  131. data/spec/spec/mocks/bug_report_8302_spec.rb +5 -5
  132. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +26 -27
  133. data/spec/spec/mocks/mock_ordering_spec.rb +19 -15
  134. data/spec/spec/mocks/mock_space_spec.rb +54 -0
  135. data/spec/spec/mocks/mock_spec.rb +111 -141
  136. data/spec/spec/mocks/multiple_return_value_spec.rb +48 -48
  137. data/spec/spec/mocks/null_object_mock_spec.rb +10 -10
  138. data/spec/spec/mocks/once_counts_spec.rb +32 -35
  139. data/spec/spec/mocks/options_hash_spec.rb +12 -10
  140. data/spec/spec/mocks/partial_mock_spec.rb +15 -15
  141. data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +24 -22
  142. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +19 -19
  143. data/spec/spec/mocks/precise_counts_spec.rb +28 -32
  144. data/spec/spec/mocks/record_messages_spec.rb +10 -10
  145. data/spec/spec/mocks/stub_spec.rb +45 -45
  146. data/spec/spec/mocks/twice_counts_spec.rb +21 -21
  147. data/spec/spec/package/bin_spec_spec.rb +12 -0
  148. data/spec/spec/runner/behaviour_runner_spec.rb +114 -0
  149. data/spec/spec/runner/command_line_spec.rb +8 -8
  150. data/spec/spec/runner/context_matching_spec.rb +14 -15
  151. data/spec/spec/runner/drb_command_line_spec.rb +12 -12
  152. data/spec/spec/runner/execution_context_spec.rb +8 -29
  153. data/spec/spec/runner/extensions/kernel_spec.rb +36 -0
  154. data/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb +27 -0
  155. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +28 -0
  156. data/spec/spec/runner/formatter/html_formatter_spec.rb +9 -8
  157. data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +6 -6
  158. data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +10 -10
  159. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +22 -27
  160. data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +6 -5
  161. data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +17 -17
  162. data/spec/spec/runner/formatter/snippet_extractor_spec.rb +11 -0
  163. data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +6 -6
  164. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +17 -17
  165. data/spec/spec/runner/heckle_runner_spec.rb +21 -21
  166. data/spec/spec/runner/heckler_spec.rb +5 -5
  167. data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +12 -12
  168. data/spec/spec/runner/object_ext_spec.rb +3 -3
  169. data/spec/spec/runner/option_parser_spec.rb +171 -102
  170. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +21 -12
  171. data/spec/spec/runner/reporter_spec.rb +106 -97
  172. data/spec/spec/runner/spec_matcher_spec.rb +46 -51
  173. data/spec/spec/runner/spec_parser_spec.rb +72 -16
  174. data/spec/spec/spec_classes.rb +12 -3
  175. data/spec/spec/translator_spec.rb +165 -36
  176. metadata +66 -76
  177. data/RELEASE-PLAN +0 -117
  178. data/examples/auto_spec_name_generation_example.rb +0 -18
  179. data/lib/spec/callback.rb +0 -11
  180. data/lib/spec/callback/callback_container.rb +0 -60
  181. data/lib/spec/callback/extensions/module.rb +0 -24
  182. data/lib/spec/callback/extensions/object.rb +0 -37
  183. data/lib/spec/deprecated.rb +0 -3
  184. data/lib/spec/expectations/extensions/proc.rb +0 -57
  185. data/lib/spec/expectations/should.rb +0 -5
  186. data/lib/spec/expectations/should/base.rb +0 -64
  187. data/lib/spec/expectations/should/change.rb +0 -69
  188. data/lib/spec/expectations/should/have.rb +0 -128
  189. data/lib/spec/expectations/should/not.rb +0 -74
  190. data/lib/spec/expectations/should/should.rb +0 -81
  191. data/lib/spec/expectations/sugar.rb +0 -47
  192. data/lib/spec/runner/context.rb +0 -154
  193. data/lib/spec/runner/context_eval.rb +0 -142
  194. data/lib/spec/runner/context_runner.rb +0 -55
  195. data/lib/spec/runner/execution_context.rb +0 -17
  196. data/lib/spec/runner/spec_matcher.rb +0 -25
  197. data/lib/spec/runner/specification.rb +0 -114
  198. data/spec/spec/callback/callback_container_spec.rb +0 -27
  199. data/spec/spec/callback/module_spec.rb +0 -37
  200. data/spec/spec/callback/object_spec.rb +0 -90
  201. data/spec/spec/callback/object_with_class_callback_spec.rb +0 -19
  202. data/spec/spec/expectations/should/should_==_spec.rb +0 -19
  203. data/spec/spec/expectations/should/should_=~_spec.rb +0 -13
  204. data/spec/spec/expectations/should/should_be_a_kind_of_spec.rb +0 -21
  205. data/spec/spec/expectations/should/should_be_an_instance_of_spec.rb +0 -30
  206. data/spec/spec/expectations/should/should_be_arbitrary_predicate_spec.rb +0 -81
  207. data/spec/spec/expectations/should/should_be_close_spec.rb +0 -18
  208. data/spec/spec/expectations/should/should_be_comparison_operator_spec.rb +0 -44
  209. data/spec/spec/expectations/should/should_be_false_spec.rb +0 -39
  210. data/spec/spec/expectations/should/should_be_spec.rb +0 -11
  211. data/spec/spec/expectations/should/should_be_true_spec.rb +0 -27
  212. data/spec/spec/expectations/should/should_change_spec.rb +0 -184
  213. data/spec/spec/expectations/should/should_eql_spec.rb +0 -11
  214. data/spec/spec/expectations/should/should_equal_spec.rb +0 -11
  215. data/spec/spec/expectations/should/should_have_at_least_spec.rb +0 -53
  216. data/spec/spec/expectations/should/should_have_at_most_spec.rb +0 -45
  217. data/spec/spec/expectations/should/should_have_key_spec.rb +0 -21
  218. data/spec/spec/expectations/should/should_have_spec.rb +0 -64
  219. data/spec/spec/expectations/should/should_include_spec.rb +0 -59
  220. data/spec/spec/expectations/should/should_match_spec.rb +0 -25
  221. data/spec/spec/expectations/should/should_not_==_spec.rb +0 -15
  222. data/spec/spec/expectations/should/should_not_be_a_kind_of_spec.rb +0 -21
  223. data/spec/spec/expectations/should/should_not_be_an_instance_of_spec.rb +0 -11
  224. data/spec/spec/expectations/should/should_not_be_arbitrary_predicate_spec.rb +0 -68
  225. data/spec/spec/expectations/should/should_not_be_spec.rb +0 -11
  226. data/spec/spec/expectations/should/should_not_change_spec.rb +0 -24
  227. data/spec/spec/expectations/should/should_not_eql_spec.rb +0 -11
  228. data/spec/spec/expectations/should/should_not_equal_spec.rb +0 -11
  229. data/spec/spec/expectations/should/should_not_have_key_spec.rb +0 -15
  230. data/spec/spec/expectations/should/should_not_include_spec.rb +0 -58
  231. data/spec/spec/expectations/should/should_not_match_spec.rb +0 -11
  232. data/spec/spec/expectations/should/should_not_raise_spec.rb +0 -75
  233. data/spec/spec/expectations/should/should_not_respond_to_spec.rb +0 -15
  234. data/spec/spec/expectations/should/should_not_throw_spec.rb +0 -35
  235. data/spec/spec/expectations/should/should_raise_spec.rb +0 -66
  236. data/spec/spec/expectations/should/should_respond_to_spec.rb +0 -15
  237. data/spec/spec/expectations/should/should_satisfy_spec.rb +0 -35
  238. data/spec/spec/expectations/should/should_throw_spec.rb +0 -27
  239. data/spec/spec/runner/context_runner_spec.rb +0 -100
  240. data/spec/spec/runner/context_spec.rb +0 -405
  241. data/spec/spec/runner/kernel_ext_spec.rb +0 -16
  242. data/spec/spec/runner/spec_name_generation_spec.rb +0 -102
  243. data/spec/spec/runner/specification_class_spec.rb +0 -72
  244. data/spec/spec/runner/specification_instance_spec.rb +0 -160
  245. data/spec/spec/runner/specification_should_raise_spec.rb +0 -136
@@ -0,0 +1,26 @@
1
+ module Spec
2
+ module Runner
3
+ class Options
4
+ attr_accessor(
5
+ :backtrace_tweaker,
6
+ :colour,
7
+ :context_lines,
8
+ :diff_format,
9
+ :differ_class,
10
+ :dry_run,
11
+ :examples,
12
+ :failure_file,
13
+ :formatters,
14
+ :generate,
15
+ :heckle_runner,
16
+ :line_number,
17
+ :loadby,
18
+ :reporter,
19
+ :reverse,
20
+ :runner_type,
21
+ :timeout,
22
+ :verbose
23
+ )
24
+ end
25
+ end
26
+ end
@@ -2,36 +2,38 @@ module Spec
2
2
  module Runner
3
3
  class Reporter
4
4
 
5
- def initialize(formatter, backtrace_tweaker)
6
- @formatter = formatter
5
+ def initialize(formatters, backtrace_tweaker)
6
+ @formatters = formatters
7
7
  @backtrace_tweaker = backtrace_tweaker
8
8
  clear!
9
9
  end
10
10
 
11
- def add_context(name)
12
- #TODO - @context_names.empty? tells the formatter whether this is the first context or not - that's a little slippery
13
- @formatter.add_context(name, @context_names.empty?)
14
- @context_names << name
11
+ def add_behaviour(name)
12
+ @formatters.each{|f| f.add_behaviour(name)}
13
+ @behaviour_names << name
14
+ STDOUT.flush
15
15
  end
16
16
 
17
- def spec_started(name)
18
- @spec_names << name
19
- @formatter.spec_started(name)
17
+ def example_started(name)
18
+ @formatters.each{|f| f.example_started(name)}
19
+ STDOUT.flush
20
20
  end
21
21
 
22
- def spec_finished(name, error=nil, failure_location=nil)
22
+ def example_finished(name, error=nil, failure_location=nil)
23
+ @example_names << name
23
24
  if error.nil?
24
- spec_passed(name)
25
+ example_passed(name)
25
26
  else
26
- @backtrace_tweaker.tweak_backtrace(error, failure_location)
27
- spec_failed(name, Failure.new(@context_names.last, name, error))
27
+ example_failed(name, error, failure_location)
28
28
  end
29
+ STDOUT.flush
29
30
  end
30
31
 
31
- def start(number_of_specs)
32
+ def start(number_of_examples)
32
33
  clear!
33
34
  @start_time = Time.new
34
- @formatter.start(number_of_specs)
35
+ @formatters.each{|f| f.start(number_of_examples)}
36
+ STDOUT.flush
35
37
  end
36
38
 
37
39
  def end
@@ -40,18 +42,19 @@ module Spec
40
42
 
41
43
  # Dumps the summary and returns the total number of failures
42
44
  def dump
43
- @formatter.start_dump
45
+ @formatters.each{|f| f.start_dump}
44
46
  dump_failures
45
- @formatter.dump_summary(duration, @spec_names.length, @failures.length)
47
+ @formatters.each{|f| f.dump_summary(duration, @example_names.length, @failures.length)}
48
+ STDOUT.flush
46
49
  @failures.length
47
50
  end
48
51
 
49
- private
52
+ private
50
53
 
51
54
  def clear!
52
- @context_names = []
55
+ @behaviour_names = []
53
56
  @failures = []
54
- @spec_names = []
57
+ @example_names = []
55
58
  @start_time = nil
56
59
  @end_time = nil
57
60
  end
@@ -59,7 +62,7 @@ module Spec
59
62
  def dump_failures
60
63
  return if @failures.empty?
61
64
  @failures.inject(1) do |index, failure|
62
- @formatter.dump_failure(index, failure)
65
+ @formatters.each{|f| f.dump_failure(index, failure)}
63
66
  index + 1
64
67
  end
65
68
  end
@@ -69,29 +72,33 @@ module Spec
69
72
  return "0.0"
70
73
  end
71
74
 
72
- def spec_passed(name)
73
- @formatter.spec_passed(name)
75
+ def example_passed(name)
76
+ @formatters.each{|f| f.example_passed(name)}
74
77
  end
75
78
 
76
- def spec_failed(name, failure)
79
+ def example_failed(name, error, failure_location)
80
+ @backtrace_tweaker.tweak_backtrace(error, failure_location)
81
+ example_name = "#{@behaviour_names.last} #{name}"
82
+ @failure_io.puts(example_name) unless @failure_io.nil?
83
+ failure = Failure.new(example_name, error)
77
84
  @failures << failure
78
- @formatter.spec_failed(name, @failures.length, failure)
85
+ @formatters.each{|f| f.example_failed(name, @failures.length, failure)}
86
+ STDOUT.flush
79
87
  end
80
-
88
+
81
89
  class Failure
82
90
  attr_reader :exception
83
91
 
84
- def initialize(context_name, spec_name, exception)
85
- @context_name = context_name
86
- @spec_name = spec_name
92
+ def initialize(example_name, exception)
93
+ @example_name = example_name
87
94
  @exception = exception
88
95
  end
89
96
 
90
97
  def header
91
98
  if expectation_not_met?
92
- "'#{@context_name} #{@spec_name}' FAILED"
99
+ "'#{@example_name}' FAILED"
93
100
  else
94
- "#{@exception.class.name} in '#{@context_name} #{@spec_name}'"
101
+ "#{@exception.class.name} in '#{@example_name}'"
95
102
  end
96
103
  end
97
104
 
@@ -1,15 +1,15 @@
1
1
  module Spec
2
2
  module Runner
3
- # Parses a spec file and finds the nearest spec for a given line number.
3
+ # Parses a spec file and finds the nearest example for a given line number.
4
4
  class SpecParser
5
5
  def spec_name_for(io, line_number)
6
6
  source = io.read
7
- context = context_at_line(source, line_number)
8
- spec = spec_at_line(source, line_number)
9
- if context && spec
10
- "#{context} #{spec}"
11
- elsif context
12
- context
7
+ behaviour, behaviour_line = behaviour_at_line(source, line_number)
8
+ example, example_line = example_at_line(source, line_number)
9
+ if behaviour && example && (behaviour_line < example_line)
10
+ "#{behaviour} #{example}"
11
+ elsif behaviour
12
+ behaviour
13
13
  else
14
14
  nil
15
15
  end
@@ -17,17 +17,18 @@ module Spec
17
17
 
18
18
  protected
19
19
 
20
- def context_at_line(source, line_number)
21
- find_above(source, line_number, /^\s*context\s+['|"](.*)['|"]/)
20
+ def behaviour_at_line(source, line_number)
21
+ find_above(source, line_number, /^\s*(context|describe)\s+(.*)\s+do/)
22
22
  end
23
23
 
24
- def spec_at_line(source, line_number)
25
- find_above(source, line_number, /^\s*specify\s+['|"](.*)['|"]/)
24
+ def example_at_line(source, line_number)
25
+ find_above(source, line_number, /^\s*(specify|it)\s+(.*)\s+do/)
26
26
  end
27
27
 
28
+ # Returns the context/describe or specify/it name and the line number
28
29
  def find_above(source, line_number, pattern)
29
- lines_above_reversed(source, line_number).each do |line|
30
- return $1 if line =~ pattern
30
+ lines_above_reversed(source, line_number).each_with_index do |line, n|
31
+ return [parse_description($2), line_number-n] if line =~ pattern
31
32
  end
32
33
  nil
33
34
  end
@@ -36,6 +37,14 @@ module Spec
36
37
  lines = source.split("\n")
37
38
  lines[0...line_number].reverse
38
39
  end
40
+
41
+ def parse_description(str)
42
+ return str[1..-2] if str =~ /^['"].*['"]$/
43
+ if matches = /^(.*)\s*,\s*['"](.*)['"]$/.match(str)
44
+ return "#{matches[1]}#{matches[2]}"
45
+ end
46
+ return str
47
+ end
39
48
  end
40
49
  end
41
50
  end
@@ -0,0 +1,10 @@
1
+ require 'spec/expectations'
2
+ require 'spec/matchers'
3
+
4
+ module Test
5
+ module Unit
6
+ class TestCase
7
+ include Spec::Matchers
8
+ end
9
+ end
10
+ end
@@ -1,87 +1,104 @@
1
- require 'fileutils'
2
-
3
- module Spec
4
- class Translator
5
- def translate_dir(from, to)
6
- from = File.expand_path(from)
7
- to = File.expand_path(to)
8
- if File.directory?(from)
9
- FileUtils.mkdir_p(to) unless File.directory?(to)
10
- Dir["#{from}/*"].each do |sub_from|
11
- path = sub_from[from.length+1..-1]
12
- sub_to = File.join(to, path)
13
- translate_dir(sub_from, sub_to)
14
- end
15
- else
16
- translate_file(from, to)
17
- end
18
- end
19
-
20
- def translate_file(from, to)
21
- translation = ""
22
- File.open(from) do |io|
23
- io.each_line do |line|
24
- translation << translate(line)
25
- end
26
- end
27
- File.open(to, "w") do |io|
28
- io.write(translation)
29
- end
30
- end
31
-
32
- def translate(line)
33
- return line if line =~ /(should_not|should)_receive/
34
-
35
- if line =~ /(.*\.)(should_not|should)(?:_be)(?!_)(.*)/m
36
- pre = $1
37
- should = $2
38
- post = $3
39
- be_or_equal = post =~ /(<|>)/ ? "be" : "equal"
40
-
41
- return "#{pre}#{should} #{be_or_equal}#{post}"
42
- end
43
-
44
- if line =~ /(.*\.)(should_not|should)_(?!not)(.*)/m
45
- pre = $1
46
- should = $2
47
- post = $3
48
-
49
- post.gsub!(/^raise/, 'raise_error')
50
- post.gsub!(/^throw/, 'throw_symbol')
51
-
52
- unless standard_matcher?(post)
53
- post = "be_#{post}"
54
- end
55
-
56
- line = "#{pre}#{should} #{post}"
57
- end
58
-
59
- line
60
- end
61
-
62
- def standard_matcher?(matcher)
63
- patterns = [
64
- /^be/,
65
- /^be_close/,
66
- /^eql/,
67
- /^equal/,
68
- /^has/,
69
- /^have/,
70
- /^change/,
71
- /^include/,
72
- /^match/,
73
- /^raise_error/,
74
- /^respond_to/,
75
- /^satisfy/,
76
- /^throw_symbol/,
77
- # Extra ones that we use in spec_helper
78
- /^pass/,
79
- /^fail/,
80
- /^fail_with/,
81
- ]
82
- matched = patterns.detect{ |p| matcher =~ p }
83
- !matched.nil?
84
- end
85
-
86
- end
1
+ require 'fileutils'
2
+
3
+ module Spec
4
+ class Translator
5
+ def translate(from, to)
6
+ from = File.expand_path(from)
7
+ to = File.expand_path(to)
8
+ if File.directory?(from)
9
+ translate_dir(from, to)
10
+ elsif(from =~ /\.rb$/)
11
+ translate_file(from, to)
12
+ end
13
+ end
14
+
15
+ def translate_dir(from, to)
16
+ FileUtils.mkdir_p(to) unless File.directory?(to)
17
+ Dir["#{from}/*"].each do |sub_from|
18
+ path = sub_from[from.length+1..-1]
19
+ sub_to = File.join(to, path)
20
+ translate(sub_from, sub_to)
21
+ end
22
+ end
23
+
24
+ def translate_file(from, to)
25
+ translation = ""
26
+ File.open(from) do |io|
27
+ io.each_line do |line|
28
+ translation << translate_line(line)
29
+ end
30
+ end
31
+ File.open(to, "w") do |io|
32
+ io.write(translation)
33
+ end
34
+ end
35
+
36
+ def translate_line(line)
37
+ return line if line =~ /(should_not|should)_receive/
38
+
39
+ line.gsub!(/(^\s*)context([\s*|\(]['|"|A-Z])/, '\1describe\2')
40
+ line.gsub!(/(^\s*)specify([\s*|\(]['|"|A-Z])/, '\1it\2')
41
+ line.gsub!(/(^\s*)context_setup(\s*[do|\{])/, '\1before(:all)\2')
42
+ line.gsub!(/(^\s*)context_teardown(\s*[do|\{])/, '\1after(:all)\2')
43
+ line.gsub!(/(^\s*)setup(\s*[do|\{])/, '\1before(:each)\2')
44
+ line.gsub!(/(^\s*)teardown(\s*[do|\{])/, '\1after(:each)\2')
45
+
46
+ if line =~ /(.*\.)(should_not|should)(?:_be)(?!_)(.*)/m
47
+ pre = $1
48
+ should = $2
49
+ post = $3
50
+ be_or_equal = post =~ /(<|>)/ ? "be" : "equal"
51
+
52
+ return "#{pre}#{should} #{be_or_equal}#{post}"
53
+ end
54
+
55
+ if line =~ /(.*\.)(should_not|should)_(?!not)\s*(.*)/m
56
+ pre = $1
57
+ should = $2
58
+ post = $3
59
+
60
+ post.gsub!(/^raise/, 'raise_error')
61
+ post.gsub!(/^throw/, 'throw_symbol')
62
+
63
+ unless standard_matcher?(post)
64
+ post = "be_#{post}"
65
+ end
66
+
67
+ # Add parenthesis
68
+ post.gsub!(/^(\w+)\s+([\w|\.|\,|\(.*\)|\'|\"|\:|@| ]+)(\})/, '\1(\2)\3') # inside a block
69
+ post.gsub!(/^(\w+)\s+([\w|\.|\,|\(.*\)|\{.*\}|\'|\"|\:|@| ]+)/, '\1(\2)')
70
+ post.gsub!(/(\s+\))/, ')')
71
+ post.gsub!(/\)\}/, ') }')
72
+ post.gsub!(/^(\w+)\s+(\/.*\/)/, '\1(\2)') #regexps
73
+ line = "#{pre}#{should} #{post}"
74
+ end
75
+
76
+ line
77
+ end
78
+
79
+ def standard_matcher?(matcher)
80
+ patterns = [
81
+ /^be/,
82
+ /^be_close/,
83
+ /^eql/,
84
+ /^equal/,
85
+ /^has/,
86
+ /^have/,
87
+ /^change/,
88
+ /^include/,
89
+ /^match/,
90
+ /^raise_error/,
91
+ /^respond_to/,
92
+ /^satisfy/,
93
+ /^throw_symbol/,
94
+ # Extra ones that we use in spec_helper
95
+ /^pass/,
96
+ /^fail/,
97
+ /^fail_with/,
98
+ ]
99
+ matched = patterns.detect{ |p| matcher =~ p }
100
+ !matched.nil?
101
+ end
102
+
103
+ end
87
104
  end
@@ -1,25 +1,17 @@
1
1
  module Spec
2
2
  module VERSION
3
- def self.build_tag
4
- tag = "REL_" + [MAJOR, MINOR, TINY].join('_')
5
- if defined?(RELEASE_CANDIDATE)
6
- tag << "_" << RELEASE_CANDIDATE
7
- end
8
- tag
9
- end
10
-
11
3
  unless defined? MAJOR
12
4
  MAJOR = 0
13
- MINOR = 8
14
- TINY = 2
15
- # RELEASE_CANDIDATE = "RC1"
5
+ MINOR = 9
6
+ TINY = 0
7
+ RELEASE_CANDIDATE = nil # "beta-1"
16
8
 
17
- # RANDOM_TOKEN: 0.375509844656552
18
- REV = "$LastChangedRevision: 1560 $".match(/LastChangedRevision: (\d+)/)[1]
9
+ # RANDOM_TOKEN: 0.909189653221202
10
+ REV = "$LastChangedRevision: 1874 $".match(/LastChangedRevision: (\d+)/)[1]
19
11
 
20
12
  STRING = [MAJOR, MINOR, TINY].join('.')
21
- FULL_VERSION = "#{STRING} (r#{REV})"
22
- TAG = build_tag
13
+ TAG = "REL_#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('_')}".upcase.gsub(/\.|-/, '_')
14
+ FULL_VERSION = "#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('.')} (r#{REV})"
23
15
 
24
16
  NAME = "RSpec"
25
17
  URL = "http://rspec.rubyforge.org/"