rspec 0.5.12 → 0.5.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/CHANGES +9 -1
  2. data/README +2 -2
  3. data/Rakefile +13 -5
  4. data/examples/custom_formatter.rb +2 -2
  5. data/examples/file_accessor.rb +18 -0
  6. data/examples/file_accessor_spec.rb +38 -0
  7. data/examples/io_processor.rb +8 -0
  8. data/examples/io_processor_spec.rb +21 -0
  9. data/lib/spec/api/exceptions.rb +3 -0
  10. data/lib/spec/api/mocks/message_expectation.rb +45 -29
  11. data/lib/spec/api/mocks/mock.rb +1 -1
  12. data/lib/spec/api/mocks/order_group.rb +1 -1
  13. data/lib/spec/runner.rb +1 -5
  14. data/lib/spec/runner/formatter.rb +5 -0
  15. data/lib/spec/runner/formatter/base_text_formatter.rb +79 -0
  16. data/lib/spec/runner/formatter/html_formatter.rb +156 -0
  17. data/lib/spec/runner/formatter/progress_bar_formatter.rb +27 -0
  18. data/lib/spec/runner/formatter/rdoc_formatter.rb +22 -0
  19. data/lib/spec/runner/formatter/specdoc_formatter.rb +22 -0
  20. data/lib/spec/runner/option_parser.rb +17 -17
  21. data/lib/spec/runner/reporter.rb +1 -1
  22. data/lib/spec/version.rb +1 -1
  23. data/test/spec/api/helper/arbitrary_predicate_test.rb +38 -38
  24. data/test/spec/api/helper/diff_test.rb +1 -1
  25. data/test/spec/api/helper/identity_test.rb +17 -10
  26. data/test/spec/api/helper/{equality_test.rb → object_equality_test.rb} +15 -29
  27. data/test/spec/api/helper/regex_matching_test.rb +7 -9
  28. data/test/spec/api/helper/throwing_test.rb +11 -12
  29. data/test/spec/api/helper/true_false_special_case_test.rb +15 -17
  30. data/test/spec/api/helper/typing_test.rb +27 -26
  31. data/test/spec/api/mocks/mock_arg_constraints_test.rb +1 -1
  32. data/test/spec/api/mocks/mock_test.rb +45 -11
  33. data/test/spec/api/mocks/null_object_test.rb +3 -3
  34. data/test/spec/runner/context_matching_test.rb +2 -2
  35. data/test/spec/runner/formatter/failure_dump_test.rb +94 -0
  36. data/test/spec/runner/formatter/html_formatter_test.rb +48 -0
  37. data/test/spec/runner/formatter/progress_bar_formatter_test.rb +56 -0
  38. data/test/spec/runner/formatter/rdoc_formatter_test.rb +51 -0
  39. data/test/spec/runner/formatter/specdoc_formatter_test.rb +57 -0
  40. data/test/spec/runner/kernel_ext_test.rb +1 -1
  41. data/test/spec/runner/option_parser_test.rb +22 -12
  42. data/test/spec/runner/reporter_test.rb +1 -1
  43. data/test/test_classes.rb +7 -7
  44. metadata +19 -14
  45. data/lib/spec/runner/base_text_formatter.rb +0 -77
  46. data/lib/spec/runner/html_formatter.rb +0 -153
  47. data/lib/spec/runner/progress_bar_formatter.rb +0 -25
  48. data/lib/spec/runner/rdoc_formatter.rb +0 -20
  49. data/lib/spec/runner/specdoc_formatter.rb +0 -20
  50. data/test/spec/runner/failure_dump_test.rb +0 -92
  51. data/test/spec/runner/html_formatter_test.rb +0 -47
  52. data/test/spec/runner/progress_bar_formatter_test.rb +0 -54
  53. data/test/spec/runner/rdoc_formatter_test.rb +0 -50
  54. data/test/spec/runner/specdoc_formatter_test.rb +0 -55
@@ -16,14 +16,14 @@ module Spec
16
16
  assert !@context.matches?("context with spec", @matcher)
17
17
  end
18
18
 
19
- def test_run_single_spec_should_trim_specs_when_spec_is_specified
19
+ def test_should_only_run_specified_specs_when_specified
20
20
  @context.specify("spec1") {}
21
21
  @context.specify("spec2") {}
22
22
  @context.run_single_spec "context spec1"
23
23
  assert_equal 1, @context.number_of_specs
24
24
  end
25
25
 
26
- def test_run_single_spec_should_not_trim_specs_when_spec_is_not_specified
26
+ def test_run_all_specs_when_spec_is_not_specified
27
27
  @context.specify("spec1") {}
28
28
  @context.specify("spec2") {}
29
29
  @context.run_single_spec "context"
@@ -0,0 +1,94 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Spec
4
+ module Runner
5
+ module Formatter
6
+ class ProgressBarFormatterFailureDumpTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @io = StringIO.new
10
+ @reporter = Reporter.new(ProgressBarFormatter.new(@io), QuietBacktraceTweaker.new)
11
+ @reporter.add_context "context"
12
+ end
13
+
14
+ def set_backtrace error
15
+ error.set_backtrace ["/a/b/c/d/e.rb:34:in `__instance_exec'"]
16
+ end
17
+
18
+ def test_should_add_spacing_between_sections
19
+ error = Spec::Api::ExpectationNotMetError.new "message"
20
+ set_backtrace error
21
+ @reporter.spec_finished "spec", error, "spec"
22
+ @reporter.dump
23
+ assert_match(/\nF\n\n1\)\nSpec::Api::ExpectationNotMetError in 'context spec'\nmessage\n\/a\/b\/c\/d\/e.rb:34:in `spec'\n\nFinished in /, @io.string)
24
+ end
25
+
26
+ def test_should_end_with_line_break
27
+ error = Spec::Api::ExpectationNotMetError.new "message"
28
+ set_backtrace error
29
+ @reporter.spec_finished "spec", error, "spec"
30
+ @reporter.dump
31
+ assert_match(/\n\z/, @io.string)
32
+ end
33
+
34
+ def test_should_include_informational_header
35
+ error = Spec::Api::ExpectationNotMetError.new "message"
36
+ set_backtrace error
37
+ @reporter.spec_finished "spec", error, "spec"
38
+ @reporter.dump
39
+ assert_match(/^Spec::Api::ExpectationNotMetError in 'context spec'/, @io.string)
40
+ end
41
+
42
+ def test_should_include_context_and_spec_name_in_backtrace_if_error_in_spec
43
+ error = RuntimeError.new "message"
44
+ set_backtrace error
45
+ @reporter.spec_finished "spec", error, "spec"
46
+ @reporter.dump
47
+ assert_match(/RuntimeError in 'context spec'/, @io.string)
48
+ assert_match(/:in `spec'/, @io.string)
49
+ end
50
+
51
+ def test_should_include_context_and_setup_in_backtrace_if_error_in_setup
52
+ error = RuntimeError.new
53
+ set_backtrace error
54
+ @reporter.spec_finished "spec", error, "setup"
55
+ @reporter.dump
56
+ assert_match(/RuntimeError in 'context spec'/, @io.string)
57
+ assert_match(/in `setup'/, @io.string)
58
+ end
59
+
60
+ def test_should_include_context_and_teardown_in_backtrace_if_error_in_teardown
61
+ error = RuntimeError.new
62
+ set_backtrace error
63
+ @reporter.spec_finished "spec", error, "teardown"
64
+ @reporter.dump
65
+ assert_match(/RuntimeError in 'context spec'/, @io.string)
66
+ assert_match(/in `teardown'/, @io.string)
67
+ end
68
+
69
+ end
70
+
71
+ class SpecdocFormatterFailureDumpTest < Test::Unit::TestCase
72
+
73
+ def setup
74
+ @io = StringIO.new
75
+ @reporter = Reporter.new(SpecdocFormatter.new(@io), QuietBacktraceTweaker.new)
76
+ @reporter.add_context "context"
77
+ end
78
+
79
+ def set_backtrace error
80
+ error.set_backtrace ["/a/b/c/d/e.rb:34:in `__instance_exec'"]
81
+ end
82
+
83
+ def test_spacing_between_sections
84
+ error = Spec::Api::ExpectationNotMetError.new "message"
85
+ set_backtrace error
86
+ @reporter.spec_finished "spec", error, "spec"
87
+ @reporter.dump
88
+ assert_match(/\ncontext\n- spec \(FAILED - 1\)\n\n1\)\nSpec::Api::ExpectationNotMetError in 'context spec'\nmessage\n\/a\/b\/c\/d\/e.rb:34:in `spec'\n\nFinished in /, @io.string)
89
+ end
90
+
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+ module Spec
3
+ module Runner
4
+ module Formatter
5
+ class HtmlFormatterTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @io = StringIO.new
9
+ @formatter = HtmlFormatter.new(@io)
10
+ end
11
+
12
+ def test_should_push_header_on_start
13
+ @formatter.start(5)
14
+ assert_equal(HtmlFormatter::HEADER, @io.string)
15
+ end
16
+
17
+ def test_should_push_context_name
18
+ @formatter.add_context("fruit", true)
19
+ assert_equal("<div class=\"context\">\n <div>fruit</div>\n <ul>\n", @io.string)
20
+ end
21
+
22
+ def test_should_push_div_with_spec_passed_class
23
+ @formatter.spec_started("spec")
24
+ @formatter.spec_passed("spec")
25
+ assert_equal("<li class=\"spec passed\">spec</li>\n", @io.string)
26
+ end
27
+
28
+ def test_should_push_div_with_spec_failed_class
29
+ exception = StandardError.new("boo")
30
+ failure = Reporter::Failure.new("context_name", "spec_name", exception)
31
+ @formatter.spec_started("spec_name")
32
+ @formatter.spec_failed("spec_name", 98, failure)
33
+ assert_match(/<li class="spec failed"/, @io.string)
34
+ end
35
+
36
+ def test_should_close_html_on_dump_summary
37
+ @formatter.dump_summary(3,2,1)
38
+ assert_equal("</body></html>", @io.string)
39
+ end
40
+
41
+ def test_should_push_div_on_start_dump
42
+ @formatter.start_dump
43
+ assert_equal("</div>", @io.string.split.last)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+ module Spec
3
+ module Runner
4
+ module Formatter
5
+ class ProgressBarFormatterTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @io = StringIO.new
9
+ @formatter = ProgressBarFormatter.new(@io)
10
+ end
11
+
12
+ def test_should_push_nothing_on_start
13
+ @formatter.start(4)
14
+ assert_equal("", @io.string)
15
+ end
16
+
17
+ def test_should_push_line_break_for_context
18
+ @formatter.add_context("context", :ignored)
19
+ assert_equal("\n", @io.string)
20
+ end
21
+
22
+ def test_should_push_dot_for_passing_spec
23
+ @formatter.spec_passed("spec")
24
+ assert_equal(".", @io.string)
25
+ end
26
+
27
+ def test_should_push_F_for_failing_spec
28
+ @formatter.spec_failed("spec", 98, nil)
29
+ assert_equal("F", @io.string)
30
+ end
31
+
32
+ def test_should_produce_standard_summary
33
+ @formatter.dump_summary(3,2,1)
34
+ assert_equal("\nFinished in 3 seconds\n\n2 specifications, 1 failure\n", @io.string)
35
+ end
36
+
37
+ def test_should_produce_line_break_on_start_dump
38
+ @formatter.start_dump
39
+ assert_equal("\n", @io.string)
40
+ end
41
+ end
42
+
43
+ class ProgressBarFormatterDryRunTest < Test::Unit::TestCase
44
+ def setup
45
+ @io = StringIO.new
46
+ @formatter = ProgressBarFormatter.new(@io, true)
47
+ end
48
+
49
+ def test_should_not_produce_summary_on_dry_run
50
+ @formatter.dump_summary(3,2,1)
51
+ assert_equal("", @io.string)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+ module Spec
3
+ module Runner
4
+ module Formatter
5
+ class RdocFormatterTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @io = StringIO.new
9
+ @formatter = RdocFormatter.new(@io, true)
10
+ end
11
+
12
+ def test_should_push_out_context
13
+ @formatter.add_context("context", :ignored)
14
+ assert_equal("# context\n", @io.string)
15
+ end
16
+
17
+ def test_should_push_out_spec
18
+ @formatter.spec_passed("spec")
19
+ assert_equal("# * spec\n", @io.string)
20
+ end
21
+
22
+ def test_should_push_out_failed_spec
23
+ @formatter.spec_failed("spec", 98, nil)
24
+ assert_equal("# * spec [98 - FAILED]\n", @io.string)
25
+ end
26
+
27
+ def test_should_produce_no_summary
28
+ @formatter.dump_summary(nil,nil,nil)
29
+ assert(@io.string.empty?)
30
+ end
31
+
32
+ def test_should_produce_nothing_on_start_dump
33
+ @formatter.start_dump
34
+ assert(@io.string.empty?)
35
+ end
36
+
37
+ end
38
+ class RdocFormatterDryRunTest < Test::Unit::TestCase
39
+ def setup
40
+ @io = StringIO.new
41
+ @formatter = RdocFormatter.new(@io, true)
42
+ end
43
+
44
+ def test_should_not_produce_summary_on_dry_run
45
+ @formatter.dump_summary(3,2,1)
46
+ assert_equal("", @io.string)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+ module Spec
3
+ module Runner
4
+ module Formatter
5
+ class SpecdocFormatterTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @io = StringIO.new
9
+ @formatter = SpecdocFormatter.new(@io)
10
+ end
11
+
12
+ def test_should_push_context_name
13
+ @formatter.add_context("context", :ignored)
14
+ assert_equal("\ncontext\n", @io.string)
15
+ end
16
+
17
+ def test_should_push_passing_spec_name
18
+ @formatter.spec_passed("spec")
19
+ assert_equal("- spec\n", @io.string)
20
+ end
21
+
22
+ def test_should_push_failing_spec_name_and_failure_number
23
+ @formatter.spec_failed("spec", 98, nil)
24
+ assert_equal("- spec (FAILED - 98)\n", @io.string)
25
+ end
26
+
27
+ def test_should_produce_standard_summary
28
+ @formatter.dump_summary(3,2,1)
29
+ assert_equal("\nFinished in 3 seconds\n\n2 specifications, 1 failure\n", @io.string)
30
+ end
31
+
32
+ def test_should_push_nothing_on_start
33
+ @formatter.start(5)
34
+ assert_equal("", @io.string)
35
+ end
36
+
37
+ def test_should_push_nothing_on_start_dump
38
+ @formatter.start_dump
39
+ assert_equal("", @io.string)
40
+ end
41
+
42
+ end
43
+
44
+ class SpecdocFormatterDryRunTest < Test::Unit::TestCase
45
+ def setup
46
+ @io = StringIO.new
47
+ @formatter = SpecdocFormatter.new(@io, true)
48
+ end
49
+
50
+ def test_should_not_produce_summary_on_dry_run
51
+ @formatter.dump_summary(3,2,1)
52
+ assert_equal("", @io.string)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../test_helper'
3
3
  module Spec
4
4
  module Runner
5
5
  class KernelExtTest < Test::Unit::TestCase
6
- def test_create_context
6
+ def test_should_add_context_method_to_kernel
7
7
  assert_nothing_raised do
8
8
  context("") {}
9
9
  end
@@ -21,39 +21,49 @@ module Spec
21
21
  assert_match(/Usage: spec \[options\] \(FILE\|DIRECTORY\|GLOB\)\+/n, @out.read)
22
22
  end
23
23
 
24
- def test_verbose_should_be_false_by_default
24
+ def test_should_not_be_verbose_by_default
25
25
  options = OptionParser.parse([], false, @err, @out)
26
26
  assert(!options.verbose)
27
27
  end
28
28
 
29
- def test_dry_run_should_be_settable
29
+ def test_should_accept_dry_run_option
30
30
  options = OptionParser.parse(["--dry-run"], false, @err, @out)
31
31
  assert(options.dry_run)
32
32
  end
33
33
 
34
34
  def test_should_use_progress_bar_formatter_by_default
35
35
  options = OptionParser.parse([], false, @err, @out)
36
- assert_equal(ProgressBarFormatter, options.formatter_type)
36
+ assert_equal(Formatter::ProgressBarFormatter, options.formatter_type)
37
37
  end
38
38
 
39
39
  def test_should_use_specdoc_formatter_when_format_is_specdoc
40
40
  options = OptionParser.parse(["--format","specdoc"], false, @err, @out)
41
- assert_equal(SpecdocFormatter, options.formatter_type)
41
+ assert_equal(Formatter::SpecdocFormatter, options.formatter_type)
42
42
  end
43
43
 
44
44
  def test_should_use_specdoc_formatter_when_format_is_s
45
45
  options = OptionParser.parse(["--format","s"], false, @err, @out)
46
- assert_equal(SpecdocFormatter, options.formatter_type)
46
+ assert_equal(Formatter::SpecdocFormatter, options.formatter_type)
47
47
  end
48
48
 
49
49
  def test_should_use_rdoc_formatter_when_format_is_rdoc
50
50
  options = OptionParser.parse(["--format","rdoc"], false, @err, @out)
51
- assert_equal(RdocFormatter, options.formatter_type)
51
+ assert_equal(Formatter::RdocFormatter, options.formatter_type)
52
52
  end
53
53
 
54
54
  def test_should_use_rdoc_formatter_when_format_is_r
55
55
  options = OptionParser.parse(["--format","r"], false, @err, @out)
56
- assert_equal(RdocFormatter, options.formatter_type)
56
+ assert_equal(Formatter::RdocFormatter, options.formatter_type)
57
+ end
58
+
59
+ def test_should_use_html_formatter_when_format_is_html
60
+ options = OptionParser.parse(["--format","html"], false, @err, @out)
61
+ assert_equal(Formatter::HtmlFormatter, options.formatter_type)
62
+ end
63
+
64
+ def test_should_use_html_formatter_when_format_is_h
65
+ options = OptionParser.parse(["--format","h"], false, @err, @out)
66
+ assert_equal(Formatter::HtmlFormatter, options.formatter_type)
57
67
  end
58
68
 
59
69
  def test_should_select_dry_run_for_rdoc_formatter
@@ -82,27 +92,27 @@ module Spec
82
92
  assert_match(/Usage: spec/, @err.string)
83
93
  end
84
94
 
85
- def test_backtrace_tweaker_should_be_quiet_by_default
95
+ def test_should_use_quiet_backtrace_tweaker_by_default
86
96
  options = OptionParser.parse([], false, @err, @out)
87
97
  assert options.backtrace_tweaker.instance_of?(QuietBacktraceTweaker)
88
98
  end
89
99
 
90
- def test_backtrace_tweaker_should_be_noisy_with_b
100
+ def test_should_use_noisy_backtrace_tweaker_with_b_option
91
101
  options = OptionParser.parse(["-b"], false, @err, @out)
92
102
  assert options.backtrace_tweaker.instance_of?(NoisyBacktraceTweaker)
93
103
  end
94
104
 
95
- def test_backtrace_tweaker_should_be_noisy_with_backtrace
105
+ def test_should_use_noisy_backtrace_tweaker_with_backtrace_option
96
106
  options = OptionParser.parse(["--backtrace"], false, @err, @out)
97
107
  assert options.backtrace_tweaker.instance_of?(NoisyBacktraceTweaker)
98
108
  end
99
109
 
100
- def test_should_support_single_spec_with_spec
110
+ def test_should_support_single_spec_with_spec_option
101
111
  options = OptionParser.parse(["--spec","something or other"], false, @err, @out)
102
112
  assert_equal "something or other", options.spec_name
103
113
  end
104
114
 
105
- def test_should_support_single_spec_with_s
115
+ def test_should_support_single_spec_with_s_option
106
116
  options = OptionParser.parse(["-s","something or other"], false, @err, @out)
107
117
  assert_equal "something or other", options.spec_name
108
118
  end
@@ -62,7 +62,7 @@ module Spec
62
62
  @reporter.dump
63
63
  end
64
64
 
65
- def test_should_handle_multiple_contexts_same_name
65
+ def test_should_handle_multiple_contexts_with_same_name
66
66
  @formatter.should_receive(:add_context).exactly(3).times
67
67
  @formatter.should.receive(:spec_started).exactly(3).times
68
68
  @formatter.should.receive(:spec_passed).exactly(3).times
@@ -39,27 +39,27 @@ module Spec
39
39
  end
40
40
  end
41
41
 
42
- class XxxMock
42
+ class HandCodedMock
43
43
  def initialize(return_val)
44
44
  @return_val = return_val
45
- @xxx_called = false
45
+ @funny_called = false
46
46
  end
47
47
 
48
- def xxx?
49
- @xxx_called = true
48
+ def funny?
49
+ @funny_called = true
50
50
  @return_val
51
51
  end
52
52
 
53
- def yyy?(a, b, c)
53
+ def hungry?(a, b, c)
54
54
  a.should.be 1
55
55
  b.should.be 2
56
56
  c.should.be 3
57
- @xxx_called = true
57
+ @funny_called = true
58
58
  @return_val
59
59
  end
60
60
 
61
61
  def __verify
62
- @xxx_called.should.be true
62
+ @funny_called.should.be true
63
63
  end
64
64
  end
65
65
  end