rspec 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/CHANGES +90 -1
  2. data/EXAMPLES.rd +28 -6
  3. data/MIT-LICENSE +20 -0
  4. data/README +18 -12
  5. data/Rakefile +60 -54
  6. data/examples/custom_formatter.rb +4 -4
  7. data/examples/helper_method_example.rb +11 -0
  8. data/examples/mocking_example.rb +19 -2
  9. data/examples/partial_mock_example.rb +28 -0
  10. data/examples/stack_spec.rb +8 -8
  11. data/examples/stubbing_example.rb +50 -9
  12. data/examples/test_case_spec.rb +6 -6
  13. data/lib/spec.rb +1 -2
  14. data/lib/spec/callback.rb +0 -0
  15. data/lib/spec/expectations.rb +3 -6
  16. data/lib/spec/expectations/diff.rb +23 -47
  17. data/lib/spec/expectations/differs/default.rb +62 -0
  18. data/lib/spec/expectations/{exceptions.rb → errors.rb} +0 -0
  19. data/lib/spec/expectations/extensions.rb +4 -0
  20. data/lib/spec/expectations/extensions/inspect_for_expectation_not_met_error.rb +14 -0
  21. data/lib/spec/expectations/extensions/numeric.rb +5 -0
  22. data/lib/spec/expectations/{expectations.rb → extensions/object.rb} +3 -6
  23. data/lib/spec/expectations/extensions/symbol.rb +5 -0
  24. data/lib/spec/expectations/should.rb +4 -0
  25. data/lib/spec/expectations/should/base.rb +42 -0
  26. data/lib/spec/expectations/should/have.rb +79 -0
  27. data/lib/spec/expectations/should/not.rb +72 -0
  28. data/lib/spec/expectations/should/should.rb +83 -0
  29. data/lib/spec/expectations/sugar.rb +6 -25
  30. data/lib/spec/mocks.rb +5 -1
  31. data/lib/spec/mocks/argument_expectation.rb +15 -1
  32. data/lib/spec/mocks/error_generator.rb +72 -0
  33. data/lib/spec/mocks/{exceptions.rb → errors.rb} +0 -0
  34. data/lib/spec/mocks/extensions/object.rb +3 -0
  35. data/lib/spec/mocks/message_expectation.rb +80 -73
  36. data/lib/spec/mocks/mock.rb +4 -69
  37. data/lib/spec/mocks/mock_handler.rb +158 -0
  38. data/lib/spec/mocks/mock_methods.rb +44 -0
  39. data/lib/spec/mocks/order_group.rb +10 -2
  40. data/lib/spec/rake/spectask.rb +20 -18
  41. data/lib/spec/rake/{rcov_verify.rb → verify_rcov.rb} +2 -2
  42. data/lib/spec/runner.rb +3 -1
  43. data/lib/spec/runner/backtrace_tweaker.rb +2 -1
  44. data/lib/spec/runner/context.rb +10 -16
  45. data/lib/spec/runner/context_eval.rb +40 -40
  46. data/lib/spec/runner/execution_context.rb +1 -12
  47. data/lib/spec/runner/{kernel_ext.rb → extensions/kernel.rb} +2 -2
  48. data/lib/spec/runner/{instance_exec.rb → extensions/object.rb} +0 -0
  49. data/lib/spec/runner/formatter/base_text_formatter.rb +25 -18
  50. data/lib/spec/runner/formatter/html_formatter.rb +81 -101
  51. data/lib/spec/runner/formatter/progress_bar_formatter.rb +9 -9
  52. data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
  53. data/lib/spec/runner/formatter/specdoc_formatter.rb +7 -6
  54. data/lib/spec/runner/option_parser.rb +41 -5
  55. data/lib/spec/runner/reporter.rb +3 -15
  56. data/lib/spec/runner/spec_should_raise_handler.rb +74 -0
  57. data/lib/spec/runner/specification.rb +33 -14
  58. data/lib/spec/version.rb +6 -3
  59. data/vendor/watir/README.txt +1 -1
  60. metadata +34 -68
  61. data/bin/test2spec +0 -112
  62. data/examples/helper_method_spec.rb +0 -12
  63. data/lib/spec/expectations/have_helper.rb +0 -41
  64. data/lib/spec/expectations/helper.rb +0 -4
  65. data/lib/spec/expectations/should_base.rb +0 -52
  66. data/lib/spec/expectations/should_helper.rb +0 -93
  67. data/lib/spec/expectations/should_negator.rb +0 -71
  68. data/lib/spec/test_to_spec/ruby2ruby.rb +0 -492
  69. data/lib/spec/test_to_spec/sexp_transformer.rb +0 -196
  70. data/lib/spec/test_to_spec/test_case_ext.rb +0 -22
  71. data/lib/spec/test_to_spec/translation_test_runner.rb +0 -147
  72. data/test/spec/expectations/arbitrary_operator_test.rb +0 -55
  73. data/test/spec/expectations/arbitrary_predicate_test.rb +0 -163
  74. data/test/spec/expectations/containment_test.rb +0 -129
  75. data/test/spec/expectations/diff_test.rb +0 -62
  76. data/test/spec/expectations/identity_test.rb +0 -75
  77. data/test/spec/expectations/object_equality_test.rb +0 -65
  78. data/test/spec/expectations/raising_test.rb +0 -106
  79. data/test/spec/expectations/regex_matching_test.rb +0 -36
  80. data/test/spec/expectations/should_have_test.rb +0 -169
  81. data/test/spec/expectations/should_satisfy_test.rb +0 -37
  82. data/test/spec/expectations/sugar_test.rb +0 -93
  83. data/test/spec/expectations/supported_symbols_test.rb +0 -33
  84. data/test/spec/expectations/throwing_test.rb +0 -55
  85. data/test/spec/expectations/true_false_special_case_test.rb +0 -85
  86. data/test/spec/expectations/typing_test.rb +0 -108
  87. data/test/spec/mocks/mock_arg_constraints_test.rb +0 -113
  88. data/test/spec/mocks/mock_counts_test.rb +0 -431
  89. data/test/spec/mocks/mock_ordering_test.rb +0 -109
  90. data/test/spec/mocks/mock_test.rb +0 -220
  91. data/test/spec/mocks/null_object_test.rb +0 -37
  92. data/test/spec/runner/backtrace_tweaker_test.rb +0 -90
  93. data/test/spec/runner/context_matching_test.rb +0 -35
  94. data/test/spec/runner/context_runner_test.rb +0 -62
  95. data/test/spec/runner/context_test.rb +0 -191
  96. data/test/spec/runner/execution_context_test.rb +0 -45
  97. data/test/spec/runner/formatter/failure_dump_test.rb +0 -94
  98. data/test/spec/runner/formatter/html_formatter_test.rb +0 -48
  99. data/test/spec/runner/formatter/progress_bar_formatter_test.rb +0 -56
  100. data/test/spec/runner/formatter/rdoc_formatter_test.rb +0 -51
  101. data/test/spec/runner/formatter/specdoc_formatter_test.rb +0 -57
  102. data/test/spec/runner/kernel_ext_test.rb +0 -13
  103. data/test/spec/runner/option_parser_test.rb +0 -141
  104. data/test/spec/runner/reporter_test.rb +0 -128
  105. data/test/spec/runner/spec_matcher_test.rb +0 -47
  106. data/test/spec/runner/specification_test.rb +0 -121
  107. data/test/spec/test_to_spec/ruby_to_ruby_test.rb +0 -79
  108. data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +0 -207
  109. data/test/spec/test_to_spec/sexp_transformer_test.rb +0 -303
  110. data/test/spec/test_to_spec/test_case_ext_test.rb +0 -25
  111. data/test/spec/test_to_spec/testfiles/test_unit_api_spec.rb +0 -75
  112. data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +0 -70
  113. data/test/test_classes.rb +0 -102
  114. data/test/test_helper.rb +0 -32
@@ -1,56 +0,0 @@
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
@@ -1,51 +0,0 @@
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
@@ -1,57 +0,0 @@
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
@@ -1,13 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Runner
5
- class KernelExtTest < Test::Unit::TestCase
6
- def test_should_add_context_method_to_kernel
7
- assert_nothing_raised do
8
- context("") {}
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,141 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Runner
5
- class OptionParserTest < Test::Unit::TestCase
6
-
7
- def setup
8
- @out = StringIO.new
9
- @err = StringIO.new
10
- end
11
-
12
- def test_should_print_version_to_stdout
13
- options = OptionParser.parse(["--version"], false, @err, @out)
14
- @out.rewind
15
- assert_match(/RSpec-\d+\.\d+\.\d+ - BDD for Ruby\nhttp:\/\/rspec.rubyforge.org\/\n/n, @out.read)
16
- end
17
-
18
- def test_should_print_help_to_stdout
19
- options = OptionParser.parse(["--help"], false, @err, @out)
20
- @out.rewind
21
- assert_match(/Usage: spec \[options\] \(FILE\|DIRECTORY\|GLOB\)\+/n, @out.read)
22
- end
23
-
24
- def test_should_not_be_verbose_by_default
25
- options = OptionParser.parse([], false, @err, @out)
26
- assert(!options.verbose)
27
- end
28
-
29
- def test_should_accept_dry_run_option
30
- options = OptionParser.parse(["--dry-run"], false, @err, @out)
31
- assert(options.dry_run)
32
- end
33
-
34
- def test_should_use_progress_bar_formatter_by_default
35
- options = OptionParser.parse([], false, @err, @out)
36
- assert_equal(Formatter::ProgressBarFormatter, options.formatter_type)
37
- end
38
-
39
- def test_should_use_specdoc_formatter_when_format_is_specdoc
40
- options = OptionParser.parse(["--format","specdoc"], false, @err, @out)
41
- assert_equal(Formatter::SpecdocFormatter, options.formatter_type)
42
- end
43
-
44
- def test_should_use_specdoc_formatter_when_format_is_s
45
- options = OptionParser.parse(["--format","s"], false, @err, @out)
46
- assert_equal(Formatter::SpecdocFormatter, options.formatter_type)
47
- end
48
-
49
- def test_should_use_rdoc_formatter_when_format_is_rdoc
50
- options = OptionParser.parse(["--format","rdoc"], false, @err, @out)
51
- assert_equal(Formatter::RdocFormatter, options.formatter_type)
52
- end
53
-
54
- def test_should_use_rdoc_formatter_when_format_is_r
55
- options = OptionParser.parse(["--format","r"], false, @err, @out)
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)
67
- end
68
-
69
- def test_should_select_dry_run_for_rdoc_formatter
70
- options = OptionParser.parse(["--format","rdoc"], false, @err, @out)
71
- assert(options.dry_run)
72
- end
73
-
74
- def test_should_eval_and_use_custom_formatter_when_none_of_the_builtins
75
- options = OptionParser.parse(["--format","Custom::Formatter"], false, @err, @out)
76
- assert_equal(Custom::Formatter, options.formatter_type)
77
- end
78
-
79
- def test_should_print_instructions_about_how_to_fix_bad_formatter
80
- options = OptionParser.parse(["--format","Custom::BadFormatter"], false, @err, @out)
81
- assert_match(/Couldn't find formatter class Custom::BadFormatter/n, @err.string)
82
- end
83
-
84
- def test_should_require_file_when_require_specified
85
- assert_raise(LoadError) do
86
- OptionParser.parse(["--require","whatever"], false, @err, @out)
87
- end
88
- end
89
-
90
- def test_should_print_usage_to_err_if_no_dir_specified
91
- options = OptionParser.parse([], false, @err, @out)
92
- assert_match(/Usage: spec/, @err.string)
93
- end
94
-
95
- def test_should_use_quiet_backtrace_tweaker_by_default
96
- options = OptionParser.parse([], false, @err, @out)
97
- assert options.backtrace_tweaker.instance_of?(QuietBacktraceTweaker)
98
- end
99
-
100
- def test_should_use_noisy_backtrace_tweaker_with_b_option
101
- options = OptionParser.parse(["-b"], false, @err, @out)
102
- assert options.backtrace_tweaker.instance_of?(NoisyBacktraceTweaker)
103
- end
104
-
105
- def test_should_use_noisy_backtrace_tweaker_with_backtrace_option
106
- options = OptionParser.parse(["--backtrace"], false, @err, @out)
107
- assert options.backtrace_tweaker.instance_of?(NoisyBacktraceTweaker)
108
- end
109
-
110
- def test_should_support_single_spec_with_spec_option
111
- options = OptionParser.parse(["--spec","something or other"], false, @err, @out)
112
- assert_equal "something or other", options.spec_name
113
- end
114
-
115
- def test_should_support_single_spec_with_s_option
116
- options = OptionParser.parse(["-s","something or other"], false, @err, @out)
117
- assert_equal "something or other", options.spec_name
118
- end
119
-
120
- def test_should_not_use_colour_by_default
121
- options = OptionParser.parse([], false, @err, @out)
122
- assert !options.colour
123
- end
124
-
125
- def test_should_support_queens_colour_option
126
- options = OptionParser.parse(["--colour"], false, @err, @out)
127
- assert options.colour
128
- end
129
-
130
- def test_should_support_us_color_option
131
- options = OptionParser.parse(["--color"], false, @err, @out)
132
- assert options.colour
133
- end
134
-
135
- def test_should_support_c_option
136
- options = OptionParser.parse(["-c"], false, @err, @out)
137
- assert options.colour
138
- end
139
- end
140
- end
141
- end
@@ -1,128 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Runner
5
- class ReporterTest < Test::Unit::TestCase
6
-
7
- def setup
8
- @io = StringIO.new
9
- @backtrace_tweaker = Spec::Mocks::Mock.new("backtrace tweaker")
10
- @formatter = Spec::Mocks::Mock.new("formatter")
11
- @reporter = Reporter.new(@formatter, @backtrace_tweaker)
12
- end
13
-
14
- def test_should_push_time_to_reporter
15
- @formatter.should_receive(:start).with(5)
16
- @formatter.should_receive(:start_dump)
17
- @formatter.should_receive(:dump_summary) do |time, a, b|
18
- assert_match(/[0-9].[0-9|e|-]+/, time.to_s)
19
- end
20
- @reporter.start(5)
21
- @reporter.end
22
- @reporter.dump
23
- end
24
-
25
- def test_should_push_stats_to_reporter_even_with_no_data
26
- @formatter.should_receive(:start_dump)
27
- @formatter.should_receive(:dump_summary).with(:anything, 0, 0)
28
- @reporter.dump
29
- end
30
-
31
- def test_should_push_context_to_formatter
32
- @formatter.should_receive(:add_context).never
33
- @reporter.add_context "context"
34
- end
35
-
36
- def test_should_account_for_context_in_stats
37
- @formatter.should_receive(:add_context).with("context", true)
38
- @reporter.add_context "context"
39
- end
40
-
41
- def test_should_account_for_spec_in_stats_for_pass
42
- @formatter.should_receive(:spec_started)
43
- @formatter.should_receive(:spec_passed)
44
- @formatter.should_receive(:start_dump)
45
- @formatter.should_receive(:dump_summary).with(:anything, 1, 0)
46
- @reporter.spec_started "spec"
47
- @reporter.spec_finished "spec"
48
- @reporter.dump
49
- end
50
-
51
- def test_should_account_for_spec_and_error_in_stats_for_pass
52
- @formatter.should_receive(:add_context)
53
- @formatter.should_receive(:spec_started).with("spec")
54
- @formatter.should_receive(:spec_failed).with("spec", 1, failure)
55
- @formatter.should_receive(:start_dump)
56
- @formatter.should_receive(:dump_failure).with(1, :anything)
57
- @formatter.should_receive(:dump_summary).with(:anything, 1, 1)
58
- @backtrace_tweaker.should_receive(:tweak_backtrace)
59
- @reporter.add_context "context"
60
- @reporter.spec_started "spec"
61
- @reporter.spec_finished "spec", RuntimeError.new
62
- @reporter.dump
63
- end
64
-
65
- def test_should_handle_multiple_contexts_with_same_name
66
- @formatter.should_receive(:add_context).exactly(3).times
67
- @formatter.should_receive(:spec_started).exactly(3).times
68
- @formatter.should_receive(:spec_passed).exactly(3).times
69
- @formatter.should_receive(:start_dump)
70
- @formatter.should_receive(:dump_summary).with(:anything, 3, 0)
71
- @reporter.add_context "context"
72
- @reporter.spec_started "spec 1"
73
- @reporter.spec_finished "spec 1"
74
- @reporter.add_context "context"
75
- @reporter.spec_started "spec 2"
76
- @reporter.spec_finished "spec 2"
77
- @reporter.add_context "context"
78
- @reporter.spec_started "spec 3"
79
- @reporter.spec_finished "spec 3"
80
- @reporter.dump
81
- end
82
-
83
- def test_should_handle_multiple_specs_same_name
84
- error = RuntimeError.new
85
- @formatter.should_receive(:add_context).exactly(2).times
86
- @formatter.should_receive(:spec_started).with("spec").exactly(4).times
87
- @formatter.should_receive(:spec_passed).with("spec").exactly(2).times
88
- @formatter.should_receive(:spec_failed).with("spec", 1, failure)
89
- @formatter.should_receive(:spec_failed).with("spec", 2, failure)
90
- @formatter.should_receive(:dump_failure).exactly(2).times
91
- @formatter.should_receive(:start_dump)
92
- @formatter.should_receive(:dump_summary).with(:anything, 4, 2)
93
- @backtrace_tweaker.should_receive(:tweak_backtrace)
94
- @reporter.add_context "context"
95
-
96
- @reporter.spec_started "spec"
97
- @reporter.spec_finished "spec"
98
-
99
- @reporter.spec_started "spec"
100
- @reporter.spec_finished "spec", error
101
-
102
- @reporter.add_context "context"
103
-
104
- @reporter.spec_started "spec"
105
- @reporter.spec_finished "spec"
106
-
107
- @reporter.spec_started "spec"
108
- @reporter.spec_finished "spec", error
109
-
110
- @reporter.dump
111
- end
112
-
113
- def test_should_delegate_to_backtrace_tweaker
114
- @formatter.should_receive(:add_context)
115
- @formatter.should_receive(:spec_failed)
116
- @backtrace_tweaker.should_receive(:tweak_backtrace)
117
- @reporter.add_context "context"
118
- @reporter.spec_finished "spec", RuntimeError.new
119
- @backtrace_tweaker.__verify
120
- end
121
-
122
- def failure
123
- Mocks::DuckTypeArgConstraint.new(:header, :message, :backtrace)
124
- end
125
-
126
- end
127
- end
128
- end