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,35 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Runner
5
- class ContextMatchingTest < Test::Unit::TestCase
6
-
7
- def setup
8
- @formatter = Spec::Mocks::Mock.new "formatter"
9
- @context = Context.new("context") {}
10
- @matcher = Spec::Mocks::Mock.new("matcher")
11
- end
12
-
13
- def test_should_use_spec_matcher
14
- @matcher.should_receive(:matches?).with("submitted spec")
15
- @context.specify("submitted spec") {}
16
- assert !@context.matches?("context with spec", @matcher)
17
- end
18
-
19
- def test_should_only_run_specified_specs_when_specified
20
- @context.specify("spec1") {}
21
- @context.specify("spec2") {}
22
- @context.run_single_spec "context spec1"
23
- assert_equal 1, @context.number_of_specs
24
- end
25
-
26
- def test_run_all_specs_when_spec_is_not_specified
27
- @context.specify("spec1") {}
28
- @context.specify("spec2") {}
29
- @context.run_single_spec "context"
30
- assert_equal 2, @context.number_of_specs
31
- end
32
-
33
- end
34
- end
35
- end
@@ -1,62 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Runner
5
- class ContextRunnerTest < Test::Unit::TestCase
6
-
7
- def test_should_call_run_on_context
8
- context1 = Spec::Mocks::Mock.new "context1", :null_object=>true
9
- context2 = Spec::Mocks::Mock.new "context2", :null_object=>true
10
- context1.should_receive(:run)
11
- context1.should_receive(:number_of_specs).and_return(0)
12
- context2.should_receive(:run)
13
- context2.should_receive(:number_of_specs).and_return(0)
14
-
15
- reporter = Spec::Mocks::Mock.new 'reporter'
16
- reporter.should_receive(:start).with(0)
17
- reporter.should_receive(:end)
18
- reporter.should_receive(:dump)
19
-
20
- runner = ContextRunner.new(reporter, false, false)
21
- runner.add_context context1
22
- runner.add_context context2
23
-
24
- runner.run(false)
25
-
26
- context1.__verify
27
- context2.__verify
28
- reporter.__verify
29
- end
30
-
31
- def test_should_support_single_spec
32
- desired_context = Spec::Mocks::Mock.new "desired context"
33
- desired_context.should_receive(:matches?).at_least(:once).and_return(true)
34
- desired_context.should_receive(:run)
35
- desired_context.should_receive(:run_single_spec)
36
- desired_context.should_receive(:number_of_specs).and_return(1)
37
-
38
- other_context = Spec::Mocks::Mock.new "other context"
39
- other_context.should_receive(:matches?).and_return(false)
40
- other_context.should_receive(:run).never
41
- other_context.should_receive(:number_of_specs).never
42
-
43
- reporter = Spec::Mocks::Mock.new 'reporter'
44
-
45
- runner = ContextRunner.new(reporter, false, false, "desired context legal spec")
46
- runner.add_context desired_context
47
- runner.add_context other_context
48
-
49
- reporter.should_receive(:start)
50
- reporter.should_receive(:end)
51
- reporter.should_receive(:dump)
52
-
53
- runner.run(false)
54
-
55
- desired_context.__verify
56
- other_context.__verify
57
- reporter.__verify
58
- end
59
-
60
- end
61
- end
62
- end
@@ -1,191 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Runner
5
- class ContextTest < Test::Unit::TestCase
6
-
7
- def setup
8
- @formatter = Spec::Mocks::Mock.new "formatter"
9
- @context = Context.new("context") {}
10
- end
11
-
12
- def teardown
13
- @formatter.__verify
14
- end
15
-
16
- def test_should_add_itself_to_formatter_on_run
17
- @formatter.should_receive(:add_context).with "context"
18
- @context.run(@formatter)
19
- end
20
-
21
- def test_should_run_spec
22
- @formatter.should_receive(:add_context).with :any_args
23
- @formatter.should_receive(:spec_started).with "test"
24
- @formatter.should_receive(:spec_finished).with "test", :anything, :anything
25
- $spec_ran = false
26
- @context.specify("test") {$spec_ran = true}
27
- @context.run(@formatter)
28
- assert $spec_ran
29
- end
30
-
31
- def test_should_run_spec_dry
32
- @formatter.should_receive(:add_context).with :any_args
33
- @formatter.should_receive(:spec_started).with "test"
34
- @formatter.should_receive(:spec_finished).with "test"
35
- $spec_ran = false
36
- @context.specify("test") {$spec_ran = true}
37
- @context.run(@formatter, true)
38
- assert !$spec_ran
39
- end
40
-
41
- def test_setup
42
- @formatter.should_receive(:add_context).with :any_args
43
- @formatter.should_receive(:spec_started).with "test"
44
- @formatter.should_receive(:spec_finished).with :any_args
45
-
46
- super_class_setup_ran = false
47
- super_class = Class.new do
48
- define_method :setup do
49
- super_class_setup_ran = true
50
- end
51
- end
52
- @context.inherit super_class
53
-
54
- setup_ran = false
55
- @context.setup {setup_ran = true}
56
- @context.specify("test") {true}
57
- @context.run(@formatter)
58
- assert super_class_setup_ran
59
- assert setup_ran
60
- end
61
-
62
- def test_setup__should_allow_method_definitions
63
- @formatter.should_receive(:add_context).with :any_args
64
- @formatter.should_receive(:spec_started).with "test"
65
- @formatter.should_receive(:spec_finished).with :any_args
66
-
67
- $method_in_setup_called = false
68
- @context.setup do
69
- def method_in_setup
70
- $method_in_setup_called = true
71
- end
72
- end
73
-
74
- @context.specify("test") {method_in_setup}
75
- @context.run(@formatter)
76
-
77
- assert $method_in_setup_called
78
- end
79
-
80
- def test_teardown
81
- @formatter.should_receive(:add_context).with :any_args
82
- @formatter.should_receive(:spec_started).with "test"
83
- @formatter.should_receive(:spec_finished).with :any_args
84
-
85
- super_class_teardown_ran = false
86
- super_class = Class.new do
87
- define_method :teardown do
88
- super_class_teardown_ran = true
89
- end
90
- end
91
- @context.inherit super_class
92
-
93
- teardown_ran = false
94
- @context.teardown {teardown_ran = true}
95
- @context.specify("test") {true}
96
- @context.run(@formatter)
97
- assert super_class_teardown_ran
98
- assert teardown_ran
99
- @formatter.__verify
100
- end
101
-
102
- def test_inherit__superclass_methods_should_be_accessible
103
- @formatter.should_receive(:add_context).with :any_args
104
- @formatter.should_receive(:spec_started).with "test"
105
- @formatter.should_receive(:spec_finished).with :any_args
106
-
107
- helper_method_ran = false
108
- super_class = Class.new do
109
- define_method :helper_method do
110
- helper_method_ran = true
111
- end
112
- end
113
- @context.inherit super_class
114
-
115
- @context.specify("test") {helper_method}
116
- @context.run(@formatter)
117
- assert helper_method_ran
118
- end
119
-
120
- def test_inherit__class_methods_should_work
121
- class_method_ran = false
122
- super_class = Class.new
123
- (class << super_class; self; end).class_eval do
124
- define_method :class_method do
125
- class_method_ran = true
126
- end
127
- end
128
- @context.inherit super_class
129
- @context.class_method
130
- assert class_method_ran
131
-
132
- assert_raise(NoMethodError) {@context.foobar}
133
- end
134
-
135
- def test_methods__should_include_inherited_class_methods
136
- class_method_ran = false
137
- super_class = Class.new
138
- class << super_class
139
- def super_class_class_method; end
140
- end
141
- @context.inherit super_class
142
-
143
- assert @context.methods.include?("super_class_class_method")
144
- end
145
-
146
- def test_include
147
- @formatter.should_receive(:add_context).with :any_args
148
- @formatter.should_receive(:spec_started).with "test"
149
- @formatter.should_receive(:spec_finished).with :any_args
150
-
151
- mod1_method_called = false
152
- mod1 = Module.new do
153
- define_method :mod1_method do
154
- mod1_method_called = true
155
- end
156
- end
157
-
158
- mod2_method_called = false
159
- mod2 = Module.new do
160
- define_method :mod2_method do
161
- mod2_method_called = true
162
- end
163
- end
164
-
165
- @context.include mod1
166
- @context.include mod2
167
-
168
- @context.specify("test") do
169
- mod1_method
170
- mod2_method
171
- end
172
- @context.run(@formatter)
173
- assert mod1_method_called
174
- assert mod2_method_called
175
- end
176
-
177
- def test_spec_count_1
178
- @context.specify("test") {}
179
- assert_equal(1, @context.number_of_specs)
180
- end
181
-
182
- def test_spec_count_4
183
- @context.specify("one") {}
184
- @context.specify("two") {}
185
- @context.specify("three") {}
186
- @context.specify("four") {}
187
- assert_equal(4, @context.number_of_specs)
188
- end
189
- end
190
- end
191
- end
@@ -1,45 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- module Spec
4
- module Runner
5
- class ExecutionContextTest < Test::Unit::TestCase
6
-
7
- def test_should_add_new_mock_to_spec_when_mock_message_received
8
- spec = Spec::Mocks::Mock.new "spec"
9
- spec.should_receive(:add_mock) {|mock| mock.instance_of? Spec::Mocks::Mock}
10
- ec = ExecutionContext.new spec
11
- mock = ec.mock("a mock", :null_object=>true)
12
- end
13
-
14
- def test_stub__should_stub_object_with_a_method
15
- spec = Spec::Mocks::Mock.new "spec"
16
- stub_space = Spec::Mocks::Mock.new "stub_space"
17
- spec.should_receive(:stub_space) {stub_space}
18
- target = Object.new
19
- name = "foobar"
20
- expected_stub = Object.new
21
- stub_space.
22
- should_receive(:create_stub).
23
- once.
24
- with(target, name).
25
- and_return {expected_stub}
26
- ec = ExecutionContext.new spec
27
- stub = ec.stub(target, name)
28
- assert_equal expected_stub, stub
29
- end
30
-
31
- def test_violated
32
- assert_raise(Spec::Expectations::ExpectationNotMetError) do
33
- ExecutionContext.new(nil).violated
34
- end
35
- end
36
-
37
- def test_duck_type
38
- ec = ExecutionContext.new(Spec::Mocks::Mock.new("spec", :null_object => true))
39
- duck_type = ec.duck_type(:length)
40
- assert duck_type.is_a?(Spec::Mocks::DuckTypeArgConstraint)
41
- assert duck_type.matches?([])
42
- end
43
- end
44
- end
45
- end
@@ -1,94 +0,0 @@
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::Expectations::ExpectationNotMetError.new "message"
20
- set_backtrace error
21
- @reporter.spec_finished "spec", error, "spec"
22
- @reporter.dump
23
- assert_match(/\nF\n\n1\)\nSpec::Expectations::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::Expectations::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::Expectations::ExpectationNotMetError.new "message"
36
- set_backtrace error
37
- @reporter.spec_finished "spec", error, "spec"
38
- @reporter.dump
39
- assert_match(/^Spec::Expectations::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::Expectations::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::Expectations::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
@@ -1,48 +0,0 @@
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