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
@@ -2,9 +2,9 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  module Spec
4
4
  module Runner
5
- context "ObjectExt" do
6
- specify "should add copy_instance_variables_from to object" do
7
- Object.new.should_respond_to :copy_instance_variables_from
5
+ describe "ObjectExt" do
6
+ it "should add copy_instance_variables_from to object" do
7
+ Object.new.should respond_to(:copy_instance_variables_from)
8
8
  end
9
9
  end
10
10
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
- context "OptionParser" do
4
- setup do
3
+ describe "OptionParser" do
4
+ before(:each) do
5
5
  @out = StringIO.new
6
6
  @err = StringIO.new
7
7
  @parser = Spec::Runner::OptionParser.new
@@ -11,170 +11,195 @@ context "OptionParser" do
11
11
  @parser.parse(args, @err, @out, true)
12
12
  end
13
13
 
14
- specify "should accept dry run option" do
14
+ def behaviour_runner(args)
15
+ @parser.create_behaviour_runner(args, @err, @out, true)
16
+ end
17
+
18
+ it "should accept dry run option" do
15
19
  options = parse(["--dry-run"])
16
- options.dry_run.should_be(true)
20
+ options.dry_run.should be_true
17
21
  end
18
22
 
19
- specify "should eval and use custom formatter when none of the builtins" do
23
+ it "should eval and use custom formatter when none of the builtins" do
20
24
  options = parse(["--format", "Custom::Formatter"])
21
- options.formatter_type.should equal(Custom::Formatter)
25
+ options.formatters[0].class.should be(Custom::Formatter)
22
26
  end
23
-
24
- specify "should not be verbose by default" do
27
+
28
+ it "should support formatters with relative and absolute paths, even on windows" do
29
+ options = parse([
30
+ "--format", "Custom::Formatter:C:\\foo\\bar",
31
+ "--format", "Custom::Formatter:foo/bar",
32
+ "--format", "Custom::Formatter:foo\\bar",
33
+ "--format", "Custom::Formatter:/foo/bar"
34
+ ])
35
+ options.formatters[0].where.should eql("C:\\foo\\bar")
36
+ options.formatters[1].where.should eql("foo/bar")
37
+ options.formatters[2].where.should eql("foo\\bar")
38
+ options.formatters[3].where.should eql("/foo/bar")
39
+ end
40
+
41
+ it "should not be verbose by default" do
25
42
  options = parse([])
26
- options.verbose.should_be(nil)
43
+ options.verbose.should be_nil
27
44
  end
28
45
 
29
- specify "should not use colour by default" do
46
+ it "should not use colour by default" do
30
47
  options = parse([])
31
- options.colour.should_be(nil)
48
+ options.colour.should be_nil
32
49
  end
33
50
 
34
- specify "should print help to stdout" do
51
+ it "should print help to stdout" do
35
52
  options = parse(["--help"])
36
53
  @out.rewind
37
- @out.read.should_match(/Usage: spec \[options\] \(FILE\|DIRECTORY\|GLOB\)\+/n)
54
+ @out.read.should match(/Usage: spec \(FILE\|DIRECTORY\|GLOB\)\+ \[options\]/m)
38
55
  end
39
56
 
40
- specify "should print instructions about how to fix bad formatter" do
57
+ it "should print instructions about how to fix bad formatter" do
41
58
  options = parse(["--format", "Custom::BadFormatter"])
42
- @err.string.should_match(/Couldn't find formatter class Custom::BadFormatter/n)
59
+ @err.string.should match(/Couldn't find formatter class Custom::BadFormatter/n)
43
60
  end
44
61
 
45
- specify "should print usage to err if no dir specified" do
62
+ it "should print usage to err if no dir specified" do
46
63
  options = parse([])
47
- @err.string.should_match(/Usage: spec/)
64
+ @err.string.should match(/Usage: spec/)
48
65
  end
49
66
 
50
- specify "should print version to stdout" do
67
+ it "should print version to stdout" do
51
68
  options = parse(["--version"])
52
69
  @out.rewind
53
- @out.read.should_match(/RSpec-\d+\.\d+\.\d+ \(r\d+\) - BDD for Ruby\nhttp:\/\/rspec.rubyforge.org\/\n/n)
70
+ @out.read.should match(/RSpec-\d+\.\d+\.\d+.*\(r\d+\) - BDD for Ruby\nhttp:\/\/rspec.rubyforge.org\/\n/n)
54
71
  end
55
72
 
56
- specify "should accept -o option" do
57
- options = parse(["-o", "#{File.expand_path(File.dirname(__FILE__))}/output_file.txt"])
58
- options.out.should_be_an_instance_of File
59
- options.out.path.should == "#{File.expand_path(File.dirname(__FILE__))}/output_file.txt"
60
- File.delete(options.out.path) rescue nil
61
- end
62
-
63
- specify "should require file when require specified" do
73
+ it "should require file when require specified" do
64
74
  lambda do
65
75
  parse(["--require", "whatever"])
66
- end.should_raise(LoadError)
67
- end
68
-
69
- specify "should select dry run for rdoc formatter" do
70
- options = parse(["--format", "rdoc"])
71
- options.dry_run.should_be(true)
76
+ end.should raise_error(LoadError)
72
77
  end
73
78
 
74
- specify "should support c option" do
79
+ it "should support c option" do
75
80
  options = parse(["-c"])
76
- options.colour.should_be(true)
81
+ options.colour.should be_true
77
82
  end
78
83
 
79
- specify "should support queens colour option" do
84
+ it "should support queens colour option" do
80
85
  options = parse(["--colour"])
81
- options.colour.should_be(true)
86
+ options.colour.should be_true
82
87
  end
83
88
 
84
- specify "should support us color option" do
89
+ it "should support us color option" do
85
90
  options = parse(["--color"])
86
- options.colour.should_be(true)
91
+ options.colour.should be_true
87
92
  end
88
93
 
89
- specify "should support single spec with s option" do
94
+ it "should support single example with -e option" do
95
+ options = parse(["-e", "something or other"])
96
+ options.examples.should eql(["something or other"])
97
+ end
98
+
99
+ it "should support single example with -s option (will be removed when autotest supports -e)" do
90
100
  options = parse(["-s", "something or other"])
91
- options.spec_name.should_eql("something or other")
101
+ options.examples.should eql(["something or other"])
102
+ end
103
+
104
+ it "should support single example with --example option" do
105
+ options = parse(["--example", "something or other"])
106
+ options.examples.should eql(["something or other"])
92
107
  end
93
108
 
94
- specify "should support single spec with spec option" do
95
- options = parse(["--spec", "something or other"])
96
- options.spec_name.should_eql("something or other")
109
+ it "should read several example names from file if --example is given an existing file name" do
110
+ options = parse(["--example", File.dirname(__FILE__) + '/examples.txt'])
111
+ options.examples.should eql([
112
+ "Sir, if you were my husband, I would poison your drink.",
113
+ "Madam, if you were my wife, I would drink it."])
97
114
  end
98
115
 
99
- specify "should use html formatter when format is h" do
116
+ it "should use html formatter when format is h" do
100
117
  options = parse(["--format", "h"])
101
- options.formatter_type.should equal(Spec::Runner::Formatter::HtmlFormatter)
118
+ options.formatters[0].class.should equal(Spec::Runner::Formatter::HtmlFormatter)
102
119
  end
103
120
 
104
- specify "should use html formatter when format is html" do
121
+ it "should use html formatter when format is html" do
105
122
  options = parse(["--format", "html"])
106
- options.formatter_type.should equal(Spec::Runner::Formatter::HtmlFormatter)
123
+ options.formatters[0].class.should equal(Spec::Runner::Formatter::HtmlFormatter)
107
124
  end
108
125
 
109
- specify "should use noisy backtrace tweaker with b option" do
126
+ it "should use html formatter with explicit output when format is html:test.html" do
127
+ FileUtils.rm 'test.html' if File.exist?('test.html')
128
+ options = parse(["--format", "html:test.html"])
129
+ File.should be_exist('test.html')
130
+ options.formatters[0].class.should equal(Spec::Runner::Formatter::HtmlFormatter)
131
+ FileUtils.rm 'test.html'
132
+ end
133
+
134
+ it "should use noisy backtrace tweaker with b option" do
110
135
  options = parse(["-b"])
111
- options.backtrace_tweaker.should_be_instance_of(Spec::Runner::NoisyBacktraceTweaker)
136
+ options.backtrace_tweaker.should be_instance_of(Spec::Runner::NoisyBacktraceTweaker)
112
137
  end
113
138
 
114
- specify "should use noisy backtrace tweaker with backtrace option" do
139
+ it "should use noisy backtrace tweaker with backtrace option" do
115
140
  options = parse(["--backtrace"])
116
- options.backtrace_tweaker.should_be_instance_of(Spec::Runner::NoisyBacktraceTweaker)
141
+ options.backtrace_tweaker.should be_instance_of(Spec::Runner::NoisyBacktraceTweaker)
117
142
  end
118
143
 
119
- specify "should use quiet backtrace tweaker by default" do
144
+ it "should use quiet backtrace tweaker by default" do
120
145
  options = parse([])
121
- options.backtrace_tweaker.should_be_instance_of(Spec::Runner::QuietBacktraceTweaker)
146
+ options.backtrace_tweaker.should be_instance_of(Spec::Runner::QuietBacktraceTweaker)
122
147
  end
123
148
 
124
- specify "should use progress bar formatter by default" do
149
+ it "should use progress bar formatter by default" do
125
150
  options = parse([])
126
- options.formatter_type.should equal(Spec::Runner::Formatter::ProgressBarFormatter)
151
+ options.formatters[0].class.should equal(Spec::Runner::Formatter::ProgressBarFormatter)
127
152
  end
128
153
 
129
- specify "should use rdoc formatter when format is r" do
154
+ it "should use rdoc formatter when format is r" do
130
155
  options = parse(["--format", "r"])
131
- options.formatter_type.should equal(Spec::Runner::Formatter::RdocFormatter)
156
+ options.formatters[0].class.should equal(Spec::Runner::Formatter::RdocFormatter)
132
157
  end
133
158
 
134
- specify "should use rdoc formatter when format is rdoc" do
159
+ it "should use rdoc formatter when format is rdoc" do
135
160
  options = parse(["--format", "rdoc"])
136
- options.formatter_type.should equal(Spec::Runner::Formatter::RdocFormatter)
161
+ options.formatters[0].class.should equal(Spec::Runner::Formatter::RdocFormatter)
137
162
  end
138
163
 
139
- specify "should use specdoc formatter when format is s" do
164
+ it "should use specdoc formatter when format is s" do
140
165
  options = parse(["--format", "s"])
141
- options.formatter_type.should equal(Spec::Runner::Formatter::SpecdocFormatter)
166
+ options.formatters[0].class.should equal(Spec::Runner::Formatter::SpecdocFormatter)
142
167
  end
143
168
 
144
- specify "should use specdoc formatter when format is specdoc" do
169
+ it "should use specdoc formatter when format is specdoc" do
145
170
  options = parse(["--format", "specdoc"])
146
- options.formatter_type.should equal(Spec::Runner::Formatter::SpecdocFormatter)
171
+ options.formatters[0].class.should equal(Spec::Runner::Formatter::SpecdocFormatter)
147
172
  end
148
173
 
149
- specify "should support diff option when format is not specified" do
174
+ it "should support diff option when format is not specified" do
150
175
  options = parse(["--diff"])
151
- options.diff_format.should_be :unified
176
+ options.diff_format.should == :unified
152
177
  end
153
178
 
154
- specify "should use unified diff format option when format is unified" do
179
+ it "should use unified diff format option when format is unified" do
155
180
  options = parse(["--diff", "unified"])
156
- options.diff_format.should_be :unified
157
- options.differ_class.should_be Spec::Expectations::Differs::Default
181
+ options.diff_format.should == :unified
182
+ options.differ_class.should equal(Spec::Expectations::Differs::Default)
158
183
  end
159
184
 
160
- specify "should use context diff format option when format is context" do
185
+ it "should use context diff format option when format is context" do
161
186
  options = parse(["--diff", "context"])
162
- options.diff_format.should eql(:context)
163
- options.differ_class.should_eql Spec::Expectations::Differs::Default
187
+ options.diff_format.should == :context
188
+ options.differ_class.should == Spec::Expectations::Differs::Default
164
189
  end
165
190
 
166
- specify "should use custom diff format option when format is a custom format" do
191
+ it "should use custom diff format option when format is a custom format" do
167
192
  options = parse(["--diff", "Custom::Formatter"])
168
- options.diff_format.should_be :custom
169
- options.differ_class.should_eql Custom::Formatter
193
+ options.diff_format.should == :custom
194
+ options.differ_class.should == Custom::Formatter
170
195
  end
171
196
 
172
- specify "should print instructions about how to fix bad differ" do
197
+ it "should print instructions about how to fix bad differ" do
173
198
  options = parse(["--diff", "Custom::BadFormatter"])
174
- @err.string.should_match(/Couldn't find differ class Custom::BadFormatter/n)
199
+ @err.string.should match(/Couldn't find differ class Custom::BadFormatter/n)
175
200
  end
176
201
 
177
- specify "should support --line to identify spec" do
202
+ it "should support --line to identify spec" do
178
203
  spec_parser = mock("spec_parser")
179
204
  @parser.instance_variable_set('@spec_parser', spec_parser)
180
205
 
@@ -186,11 +211,11 @@ context "OptionParser" do
186
211
  spec_parser.should_receive(:spec_name_for).with("fake_io", 169).and_return("some spec")
187
212
 
188
213
  options = parse(["some file", "--line", "169"])
189
- options.spec_name.should_eql("some spec")
190
- File.__verify
214
+ options.examples.should eql(["some spec"])
215
+ File.rspec_verify
191
216
  end
192
217
 
193
- specify "should fail with error message if file is dir along with --line" do
218
+ it "should fail with error message if file is dir along with --line" do
194
219
  spec_parser = mock("spec_parser")
195
220
  @parser.instance_variable_set('@spec_parser', spec_parser)
196
221
 
@@ -200,10 +225,10 @@ context "OptionParser" do
200
225
  @parser.instance_variable_set('@file_factory', file_factory)
201
226
 
202
227
  options = parse(["some file", "--line", "169"])
203
- @err.string.should_match(/You must specify one file, not a directory when using the --line option/n)
228
+ @err.string.should match(/You must specify one file, not a directory when using the --line option/n)
204
229
  end
205
230
 
206
- specify "should fail with error message if file is dir along with --line" do
231
+ it "should fail with error message if file is dir along with --line" do
207
232
  spec_parser = mock("spec_parser")
208
233
  @parser.instance_variable_set('@spec_parser', spec_parser)
209
234
 
@@ -213,57 +238,101 @@ context "OptionParser" do
213
238
  @parser.instance_variable_set('@file_factory', file_factory)
214
239
 
215
240
  options = parse(["some file", "--line", "169"])
216
- @err.string.should_match(/some file does not exist/n)
241
+ @err.string.should match(/some file does not exist/n)
217
242
  end
218
243
 
219
- specify "should fail with error message if more than one files are specified along with --line" do
244
+ it "should fail with error message if more than one files are specified along with --line" do
220
245
  spec_parser = mock("spec_parser")
221
246
  @parser.instance_variable_set('@spec_parser', spec_parser)
222
247
 
223
248
  options = parse(["some file", "some other file", "--line", "169"])
224
- @err.string.should_match(/Only one file can be specified when using the --line option/n)
249
+ @err.string.should match(/Only one file can be specified when using the --line option/n)
225
250
  end
226
251
 
227
- specify "should fail with error message if --spec and --line are used simultaneously" do
252
+ it "should fail with error message if --example and --line are used simultaneously" do
228
253
  spec_parser = mock("spec_parser")
229
254
  @parser.instance_variable_set('@spec_parser', spec_parser)
230
255
 
231
- options = parse(["some file", "--spec", "some spec", "--line", "169"])
232
- @err.string.should_match(/You cannot use both --line and --spec/n)
256
+ options = parse(["some file", "--example", "some example", "--line", "169"])
257
+ @err.string.should match(/You cannot use both --line and --example/n)
233
258
  end
234
259
 
235
260
  if(PLATFORM != "i386-mswin32")
236
- specify "should heckle when --heckle is specified (and platform is not windows)" do
261
+ it "should heckle when --heckle is specified (and platform is not windows)" do
237
262
  options = parse(["--heckle", "Spec"])
238
- options.heckle_runner.should_be_instance_of(Spec::Runner::HeckleRunner)
263
+ options.heckle_runner.should be_instance_of(Spec::Runner::HeckleRunner)
239
264
  end
240
265
  else
241
- specify "should barf when --heckle is specified (and platform is windows)" do
266
+ it "should barf when --heckle is specified (and platform is windows)" do
242
267
  lambda do
243
268
  options = parse(["--heckle", "Spec"])
244
- end.should_raise(StandardError, "Heckle not supported on Windows")
269
+ end.should raise_error(StandardError, "Heckle not supported on Windows")
245
270
  end
246
271
  end
247
-
248
- specify "should read options from file when --options is specified" do
272
+
273
+ it "should read options from file when --options is specified" do
249
274
  Spec::Runner::CommandLine.should_receive(:run).with(["--diff", "--colour"], @err, @out, true, true)
250
275
  options = parse(["--options", File.dirname(__FILE__) + "/spec.opts"])
251
276
  end
252
277
 
253
- specify "should append options from file when --options is specified" do
278
+ it "should append options from file when --options is specified" do
254
279
  Spec::Runner::CommandLine.should_receive(:run).with(["some/spec.rb", "--diff", "--colour"], @err, @out, true, true)
255
280
  options = parse(["some/spec.rb", "--options", File.dirname(__FILE__) + "/spec.opts"])
256
281
  end
282
+
283
+ it "should read spaced and multi-line options from file when --options is specified" do
284
+ Spec::Runner::CommandLine.should_receive(:run).with(["--diff", "--colour", "--format", "s"], @err, @out, true, true)
285
+ options = parse(["--options", File.dirname(__FILE__) + "/spec_spaced.opts"])
286
+ end
257
287
 
258
- specify "should save config to file when --generate-options is specified" do
259
- FileUtils.rm 'spec.opts' rescue nil
260
- options = parse(["--colour", "--generate-options", "spec.opts", "--diff"])
261
- File.open('spec.opts').read.should == "--colour\n--diff\n"
262
- FileUtils.rm 'spec.opts' rescue nil
288
+ it "should save config to file when --generate-options is specified" do
289
+ FileUtils.rm 'test.spec.opts' rescue nil
290
+ options = parse(["--colour", "--generate-options", "test.spec.opts", "--diff"])
291
+ File.open('test.spec.opts').read.should == "--colour\n--diff\n"
292
+ FileUtils.rm 'test.spec.opts' rescue nil
263
293
  end
264
294
 
265
- specify "should call DrbCommandLine when --drb is specified" do
295
+ it "should call DrbCommandLine when --drb is specified" do
266
296
  Spec::Runner::DrbCommandLine.should_receive(:run).with(["some/spec.rb", "--diff", "--colour"], @err, @out, true, true)
267
297
  options = parse(["some/spec.rb", "--diff", "--drb", "--colour"])
268
298
  end
299
+
300
+ it "should reverse spec order when --reverse is specified" do
301
+ options = parse(["some/spec.rb", "--reverse"])
302
+ end
303
+
304
+ it "should set an mtime comparator when --loadby mtime" do
305
+ behaviour_runner = behaviour_runner(["--loadby", 'mtime'])
306
+ Dir.chdir(File.dirname(__FILE__)) do
307
+ FileUtils.touch "most_recent_spec.rb"
308
+ all_files = ['command_line_spec.rb', 'most_recent_spec.rb']
309
+ sorted_files = behaviour_runner.sort_paths(all_files)
310
+ sorted_files.should == ["most_recent_spec.rb", "command_line_spec.rb"]
311
+ FileUtils.rm "most_recent_spec.rb"
312
+ end
313
+ end
314
+
315
+ it "should not use a runner by default" do
316
+ options = parse([])
317
+ options.runner_type.should be_nil
318
+ end
319
+
320
+ it "should use a custom runner when given" do
321
+ options = parse(["--runner", "Custom::BehaviourRunner"])
322
+ options.runner_type.should equal(Custom::BehaviourRunner)
323
+ end
324
+
325
+ it "should fail when custom runner not found" do
326
+ parse(["--runner", "whatever"])
327
+ @err.string.should match(/Couldn't find behaviour runner class/)
328
+ end
329
+
330
+ it "should return the correct default behaviour runner" do
331
+ @parser.create_behaviour_runner([], @err, @out, true).should be_instance_of(Spec::Runner::BehaviourRunner)
332
+ end
333
+
334
+ it "should return the correct default behaviour runner" do
335
+ @parser.create_behaviour_runner(["--runner", "Custom::BehaviourRunner"], @err, @out, true).should be_instance_of(Custom::BehaviourRunner)
336
+ end
337
+
269
338
  end
@@ -2,26 +2,26 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  module Spec
4
4
  module Runner
5
- context "QuietBacktraceTweaker" do
6
- setup do
5
+ describe "QuietBacktraceTweaker" do
6
+ before(:each) do
7
7
  @error = RuntimeError.new
8
8
  @tweaker = QuietBacktraceTweaker.new
9
9
  end
10
10
 
11
- specify "should not barf on nil backtrace" do
11
+ it "should not barf on nil backtrace" do
12
12
  lambda do
13
13
  @tweaker.tweak_backtrace(@error, "spec name")
14
- end.should_not_raise
14
+ end.should_not raise_error
15
15
  end
16
16
 
17
- specify "should remove anything from textmate ruby bundle" do
17
+ it "should remove anything from textmate ruby bundle" do
18
18
  @error.set_backtrace(["/Applications/TextMate.app/Contents/SharedSupport/Bundles/Ruby.tmbundle/Support/tmruby.rb:147"])
19
19
  @tweaker.tweak_backtrace(@error, "spec name")
20
- @error.backtrace.should_be_empty
20
+ @error.backtrace.should be_empty
21
21
  end
22
22
 
23
- specify "should remove anything in lib spec dir" do
24
- ["expectations", "mocks", "runner", "callback"].each do |child|
23
+ it "should remove anything in lib spec dir" do
24
+ ["expectations", "mocks", "runner"].each do |child|
25
25
  element="/lib/spec/#{child}/anything.rb"
26
26
  @error.set_backtrace([element])
27
27
  @tweaker.tweak_backtrace(@error, "spec name")
@@ -31,16 +31,25 @@ module Spec
31
31
  end
32
32
  end
33
33
 
34
- specify "should remove bin spec" do
34
+ it "should remove mock_frameworks/rspec" do
35
+ element = "mock_frameworks/rspec"
36
+ @error.set_backtrace([element])
37
+ @tweaker.tweak_backtrace(@error, "spec name")
38
+ unless (@error.backtrace.empty?)
39
+ raise("Should have tweaked away '#{element}'")
40
+ end
41
+ end
42
+
43
+ it "should remove bin spec" do
35
44
  @error.set_backtrace(["bin/spec:"])
36
45
  @tweaker.tweak_backtrace(@error, "spec name")
37
- @error.backtrace.should_be_empty
46
+ @error.backtrace.should be_empty
38
47
  end
39
48
 
40
- specify "should clean up double slashes" do
49
+ it "should clean up double slashes" do
41
50
  @error.set_backtrace(["/a//b/c//d.rb"])
42
51
  @tweaker.tweak_backtrace(@error, "spec name")
43
- @error.backtrace.should_include "/a/b/c/d.rb"
52
+ @error.backtrace.should include("/a/b/c/d.rb")
44
53
  end
45
54
  end
46
55
  end