rspec 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +78 -1
- data/EXAMPLES.rd +8 -5
- data/README +1 -0
- data/Rakefile +1 -1
- data/examples/pending_example.rb +20 -0
- data/lib/autotest/rspec.rb +46 -18
- data/lib/spec/dsl.rb +1 -0
- data/lib/spec/dsl/behaviour.rb +37 -27
- data/lib/spec/dsl/behaviour_callbacks.rb +4 -0
- data/lib/spec/dsl/behaviour_eval.rb +27 -16
- data/lib/spec/dsl/behaviour_factory.rb +2 -2
- data/lib/spec/dsl/composite_proc_builder.rb +9 -4
- data/lib/spec/dsl/configuration.rb +20 -4
- data/lib/spec/dsl/description.rb +7 -0
- data/lib/spec/dsl/errors.rb +9 -0
- data/lib/spec/dsl/example.rb +18 -10
- data/lib/spec/matchers/have.rb +10 -13
- data/lib/spec/matchers/operator_matcher.rb +3 -3
- data/lib/spec/matchers/raise_error.rb +8 -3
- data/lib/spec/mocks/error_generator.rb +1 -1
- data/lib/spec/mocks/message_expectation.rb +11 -0
- data/lib/spec/mocks/methods.rb +9 -5
- data/lib/spec/mocks/proxy.rb +13 -9
- data/lib/spec/rake/spectask.rb +80 -38
- data/lib/spec/runner/backtrace_tweaker.rb +2 -1
- data/lib/spec/runner/behaviour_runner.rb +37 -16
- data/lib/spec/runner/formatter/base_formatter.rb +23 -15
- data/lib/spec/runner/formatter/base_text_formatter.rb +39 -11
- data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +7 -3
- data/lib/spec/runner/formatter/failing_examples_formatter.rb +3 -3
- data/lib/spec/runner/formatter/html_formatter.rb +32 -25
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +6 -5
- data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
- data/lib/spec/runner/formatter/specdoc_formatter.rb +7 -6
- data/lib/spec/runner/option_parser.rb +6 -5
- data/lib/spec/runner/options.rb +60 -43
- data/lib/spec/runner/reporter.rb +17 -6
- data/lib/spec/runner/spec_parser.rb +1 -1
- data/lib/spec/translator.rb +8 -0
- data/lib/spec/version.rb +3 -3
- data/plugins/mock_frameworks/flexmock.rb +14 -18
- data/plugins/mock_frameworks/mocha.rb +0 -2
- data/plugins/mock_frameworks/rr.rb +21 -0
- data/spec/autotest/discover_spec.rb +19 -0
- data/spec/autotest/rspec_spec.rb +257 -0
- data/spec/autotest_helper.rb +4 -0
- data/spec/spec/dsl/behaviour_eval_spec.rb +30 -0
- data/spec/spec/dsl/behaviour_factory_spec.rb +18 -0
- data/spec/spec/dsl/behaviour_spec.rb +95 -58
- data/spec/spec/dsl/composite_proc_builder_spec.rb +0 -13
- data/spec/spec/dsl/configuration_spec.rb +6 -1
- data/spec/spec/dsl/description_spec.rb +9 -1
- data/spec/spec/dsl/example_class_spec.rb +3 -3
- data/spec/spec/dsl/example_instance_spec.rb +26 -28
- data/spec/spec/dsl/example_matcher_spec.rb +91 -0
- data/spec/spec/dsl/shared_behaviour_spec.rb +24 -0
- data/spec/spec/expectations/extensions/object_spec.rb +2 -2
- data/spec/spec/expectations/fail_with_spec.rb +2 -2
- data/spec/spec/matchers/have_spec.rb +1 -1
- data/spec/spec/matchers/operator_matcher_spec.rb +10 -10
- data/spec/spec/matchers/raise_error_spec.rb +38 -0
- data/spec/spec/mocks/argument_expectation_spec.rb +18 -14
- data/spec/spec/mocks/at_most_spec.rb +1 -1
- data/spec/spec/mocks/bug_report_11545_spec.rb +31 -0
- data/spec/spec/mocks/partial_mock_spec.rb +33 -1
- data/spec/spec/runner/behaviour_runner_spec.rb +72 -49
- data/spec/spec/runner/command_line_spec.rb +1 -1
- data/spec/spec/runner/context_matching_spec.rb +10 -10
- data/spec/spec/runner/drb_command_line_spec.rb +62 -59
- data/spec/spec/runner/extensions/bug_report_10577_spec.rb +35 -0
- data/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb +15 -2
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +3 -3
- data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -1
- data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +14 -15
- data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +1 -1
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +42 -9
- data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +40 -40
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +55 -49
- data/spec/spec/runner/option_parser_spec.rb +16 -15
- data/spec/spec/runner/options_spec.rb +64 -31
- data/spec/spec/runner/reporter_spec.rb +67 -15
- data/spec/spec/spec_classes.rb +9 -1
- data/spec/spec/translator_spec.rb +48 -0
- data/spec/spec_helper.rb +5 -2
- metadata +13 -6
- data/examples/not_yet_implemented_spec.rb +0 -12
- data/spec/spec/runner/example_matcher_spec.rb +0 -127
@@ -0,0 +1,257 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../autotest_helper"
|
2
|
+
|
3
|
+
class Autotest
|
4
|
+
|
5
|
+
module AutotestHelper
|
6
|
+
def rspec_output
|
7
|
+
<<-HERE
|
8
|
+
.............PPF
|
9
|
+
|
10
|
+
1)
|
11
|
+
'false should be false' FAILED
|
12
|
+
expected: true,
|
13
|
+
got: false (using ==)
|
14
|
+
./spec/autotest/rspec_spec.rb:203:
|
15
|
+
|
16
|
+
Finished in 0.158674 seconds
|
17
|
+
|
18
|
+
16 examples, 1 failure, 2 pending
|
19
|
+
|
20
|
+
Pending:
|
21
|
+
Autotest::Rspec handling failed results should return an array of failed examples and errors (TODO)
|
22
|
+
Autotest::Rspec tests/specs for a given file should find all the specs for a given file (TODO)
|
23
|
+
HERE
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def common_setup
|
28
|
+
@proc = mock Proc
|
29
|
+
@kernel = mock Kernel
|
30
|
+
@kernel.stub!(:proc).and_return @proc
|
31
|
+
|
32
|
+
File.stub!(:exists).and_return true
|
33
|
+
@windows_alt_separator = "\\"
|
34
|
+
@posix_separator = '/'
|
35
|
+
|
36
|
+
@rspec_output = rspec_output
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Rspec, "rspec_commands" do
|
41
|
+
it "should contain the various commands, ordered by preference" do
|
42
|
+
Rspec.new.spec_commands.should == ["bin/spec", "#{Config::CONFIG['bindir']}/spec"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe Rspec, "selection of rspec command" do
|
47
|
+
include AutotestHelper
|
48
|
+
|
49
|
+
before :each do
|
50
|
+
common_setup
|
51
|
+
@rspec_autotest = Rspec.new(@kernel)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should try to find the spec command if it exists in ./bin and use it above everything else" do
|
55
|
+
File.stub!(:exists?).and_return true
|
56
|
+
|
57
|
+
File.should_receive(:exists?).with("bin/spec").and_return true
|
58
|
+
@rspec_autotest.spec_command.should == "bin/spec"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should otherwise select the default spec command in gem_dir/bin/spec" do
|
62
|
+
@rspec_autotest.stub!(:spec_commands).and_return ["/opt/local/bin/spec"]
|
63
|
+
Config::CONFIG.stub!(:[]).and_return "/opt/local/bin"
|
64
|
+
|
65
|
+
@rspec_autotest.spec_command.should == "#{Config::CONFIG['bindir']}/spec"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should raise an error if no spec command is found at all" do
|
69
|
+
File.stub!(:exists?).and_return false
|
70
|
+
|
71
|
+
lambda {
|
72
|
+
@rspec_autotest.spec_command
|
73
|
+
}.should raise_error(RspecCommandError, "No spec command could be found!")
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
describe Rspec, "selection of rspec command (windows compatibility issues)" do
|
79
|
+
include AutotestHelper
|
80
|
+
|
81
|
+
before :each do
|
82
|
+
common_setup
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should use the ALT_SEPARATOR if it is non-nil" do
|
86
|
+
@rspec_autotest = Rspec.new(@kernel, @posix_separator, @windows_alt_separator)
|
87
|
+
@rspec_autotest.stub!(:spec_commands).and_return [File.join('bin', 'spec')]
|
88
|
+
@rspec_autotest.spec_command.should == "bin\\spec"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should not use the ALT_SEPATOR if it is nil" do
|
92
|
+
@windows_alt_separator = nil
|
93
|
+
@rspec_autotest = Rspec.new(@kernel, @posix_separator, @windows_alt_separator)
|
94
|
+
@rspec_autotest.stub!(:spec_commands).and_return [File.join('bin', 'spec')]
|
95
|
+
@rspec_autotest.spec_command.should == "bin/spec"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe Rspec, "adding spec.opts --options" do
|
100
|
+
before :each do
|
101
|
+
@rspec_autotest = Rspec.new
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should return the command line option to add spec.opts if the options file exists" do
|
105
|
+
File.stub!(:exist?).and_return true
|
106
|
+
@rspec_autotest.add_options_if_present.should == "-O spec/spec.opts "
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should return an empty string if no spec.opts exists" do
|
110
|
+
File.stub!(:exist?).and_return false
|
111
|
+
Rspec.new.add_options_if_present.should == ""
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe Rspec do
|
116
|
+
before :each do
|
117
|
+
@rspec_autotest = Rspec.new
|
118
|
+
@rspec_autotest.stub!(:ruby).and_return "ruby"
|
119
|
+
@rspec_autotest.stub!(:add_options_if_present).and_return "-O spec/spec.opts"
|
120
|
+
|
121
|
+
@ruby = @rspec_autotest.ruby
|
122
|
+
@spec_command = @rspec_autotest.spec_command
|
123
|
+
@options = @rspec_autotest.add_options_if_present
|
124
|
+
@files_to_test = {
|
125
|
+
:spec => ["file_one", "file_two"]
|
126
|
+
}
|
127
|
+
# this is not the inner representation of Autotest!
|
128
|
+
@rspec_autotest.stub!(:files_to_test).and_return @files_to_test
|
129
|
+
@files_to_test.stub!(:keys).and_return @files_to_test[:spec]
|
130
|
+
@to_test = @files_to_test.keys.flatten.join ' '
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should make the apropriate test command" do
|
134
|
+
@rspec_autotest.make_test_cmd(@files_to_test).should == "#{@ruby} -S #{@spec_command} #{@options} #{@to_test}"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe Rspec, "test mappings" do
|
139
|
+
before :each do
|
140
|
+
@proc = mock Proc
|
141
|
+
@kernel = mock Kernel
|
142
|
+
@kernel.stub!(:proc).and_return @proc
|
143
|
+
@rspec_autotest = Rspec.new(@kernel)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should map all filenames in spec/ which end in .rb" do
|
147
|
+
@rspec_autotest.test_mappings[%r%^spec/.*\.rb$%].should == @proc
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should map all names in lib which end in .rb to the corresponding ones in spec/" do
|
151
|
+
@rspec_autotest.test_mappings[%r%^lib/(.*)\.rb$%].should == @proc
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should find all files in spec/shares/* and the spec helper in spec/spec_helper" do
|
155
|
+
@rspec_autotest.test_mappings[%r%^spec/(spec_helper|shared/.*)\.rb$%].should == @proc
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe Rspec, "handling results" do
|
160
|
+
include AutotestHelper
|
161
|
+
|
162
|
+
before :each do
|
163
|
+
common_setup
|
164
|
+
@rspec_autotest = Rspec.new(@kernel, @posix_separator, @windows_alt_separator)
|
165
|
+
@rspec_autotest.stub!(:hook)
|
166
|
+
|
167
|
+
@results = mock String
|
168
|
+
@results.stub!(:scan).and_return ""
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should call hook(:red) if there are failures" do
|
172
|
+
@rspec_autotest.stub!(:consolidate_failures).and_return ["spec/some_spec.rb"]
|
173
|
+
|
174
|
+
@rspec_autotest.should_receive(:hook).with(:red)
|
175
|
+
@rspec_autotest.handle_results(@results)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should call hook(:green) if there are no failures" do
|
179
|
+
@rspec_autotest.stub!(:consolidate_failures).and_return []
|
180
|
+
@rspec_autotest.should_receive(:hook).with(:green)
|
181
|
+
@rspec_autotest.handle_results(@results)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe Rspec, "handling failed results" do
|
186
|
+
include AutotestHelper
|
187
|
+
|
188
|
+
before :each do
|
189
|
+
common_setup
|
190
|
+
end
|
191
|
+
|
192
|
+
it %(should scan the output into a multi-dimensional array,
|
193
|
+
consisting of the failing spec's name as the first element,
|
194
|
+
and the failure as the second) do
|
195
|
+
@rspec_autotest = Rspec.new
|
196
|
+
@rspec_autotest.failed_results(@rspec_output).should == [
|
197
|
+
[
|
198
|
+
"false should be false",
|
199
|
+
"expected: true,\n got: false (using ==)\n./spec/autotest/rspec_spec.rb:203:"
|
200
|
+
]
|
201
|
+
]
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe Rspec, "specs for a given file" do
|
206
|
+
before :each do
|
207
|
+
@lib_file = "lib/something.rb"
|
208
|
+
@spec_file = "spec/something_spec.rb"
|
209
|
+
@rspec_autotest = Rspec.new
|
210
|
+
|
211
|
+
@rspec_autotest.instance_variable_set("@files", {@lib_file => Time.now, @spec_file => Time.now})
|
212
|
+
@rspec_autotest.stub!(:find_files_to_test).and_return true
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should find the spec file for a given lib file" do
|
216
|
+
@rspec_autotest.specs_for_file(@lib_file).should == [@spec_file]
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should find the spec file if given a spec file" do
|
220
|
+
@rspec_autotest.specs_for_file(@spec_file).should == [@spec_file]
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should only find the file if the file is being tracked (in @file)" do
|
224
|
+
@other_file = "lib/some_non_tracked_file"
|
225
|
+
@rspec_autotest.specs_for_file(@other_file).should == []
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe Rspec, "consolidating failures" do
|
230
|
+
include AutotestHelper
|
231
|
+
|
232
|
+
before :each do
|
233
|
+
common_setup
|
234
|
+
@rspec_autotest = Rspec.new
|
235
|
+
|
236
|
+
@spec_file = "./spec/autotest/rspec_spec.rb"
|
237
|
+
@rspec_autotest.instance_variable_set("@files", {@spec_file => Time.now})
|
238
|
+
@rspec_autotest.stub!(:find_files_to_test).and_return true
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should return no failures if no failures were given in the output" do
|
242
|
+
@rspec_autotest.stub!(:failed_results).and_return [[]]
|
243
|
+
@rspec_autotest.consolidate_failures(@rspec_autotest.failed_results).should == {}
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should return a hash with the spec filename => spec name for each failure or error" do
|
247
|
+
@rspec_autotest.stub!(:failed_results).and_return([
|
248
|
+
[
|
249
|
+
"false should be false",
|
250
|
+
"expected: true,\n got: false (using ==)\n./spec/autotest/rspec_spec.rb:203:"
|
251
|
+
]
|
252
|
+
])
|
253
|
+
@rspec_autotest.consolidate_failures(@rspec_autotest.failed_results).should == {@spec_file => ["false should be false"]}
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
end
|
@@ -45,5 +45,35 @@ module Spec
|
|
45
45
|
count.should == 8
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
describe BehaviourEval, "instance methods" do
|
50
|
+
it "should support pending" do
|
51
|
+
lambda {
|
52
|
+
pending("something")
|
53
|
+
}.should raise_error(Spec::DSL::ExamplePendingError, "something")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should have #pending raise a Pending error when its block fails" do
|
57
|
+
block_ran = false
|
58
|
+
lambda {
|
59
|
+
pending("something") do
|
60
|
+
block_ran = true
|
61
|
+
raise "something wrong with my example"
|
62
|
+
end
|
63
|
+
}.should raise_error(Spec::DSL::ExamplePendingError, "something")
|
64
|
+
block_ran.should == true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have #pending raise Spec::DSL::PendingFixedError when its block does not fail" do
|
68
|
+
block_ran = false
|
69
|
+
lambda {
|
70
|
+
pending("something") do
|
71
|
+
block_ran = true
|
72
|
+
end
|
73
|
+
}.should raise_error(Spec::DSL::PendingFixedError, "Expected pending 'something' to fail. No Error was raised.")
|
74
|
+
block_ran.should == true
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
48
78
|
end
|
49
79
|
end
|
@@ -22,6 +22,24 @@ module Spec
|
|
22
22
|
}.should be_an_instance_of(behaviour_class)
|
23
23
|
end
|
24
24
|
|
25
|
+
it "should type indicated by spec_path" do
|
26
|
+
behaviour_class = Class.new do
|
27
|
+
def initialize(*args, &block); end
|
28
|
+
end
|
29
|
+
Spec::DSL::BehaviourFactory.add_behaviour_class(:something_other_than_default, behaviour_class)
|
30
|
+
Spec::DSL::BehaviourFactory.create("behaviour", :spec_path => "./spec/something_other_than_default/some_spec.rb") {
|
31
|
+
}.should be_an_instance_of(behaviour_class)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should type indicated by spec_path (with spec_path generated by caller on windows)" do
|
35
|
+
behaviour_class = Class.new do
|
36
|
+
def initialize(*args, &block); end
|
37
|
+
end
|
38
|
+
Spec::DSL::BehaviourFactory.add_behaviour_class(:something_other_than_default, behaviour_class)
|
39
|
+
Spec::DSL::BehaviourFactory.create("behaviour", :spec_path => "./spec\\something_other_than_default\\some_spec.rb") {
|
40
|
+
}.should be_an_instance_of(behaviour_class)
|
41
|
+
end
|
42
|
+
|
25
43
|
after(:each) do
|
26
44
|
Spec::DSL::BehaviourFactory.remove_behaviour_class(:something_other_than_default)
|
27
45
|
end
|
@@ -8,7 +8,7 @@ module Spec
|
|
8
8
|
@added_behaviour = description
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
describe Behaviour, "class methods" do
|
13
13
|
before :each do
|
14
14
|
@reporter = FakeReporter.new(mock("formatter", :null_object => true), mock("backtrace_tweaker", :null_object => true))
|
@@ -32,7 +32,7 @@ module Spec
|
|
32
32
|
|
33
33
|
it "should not run any example if before(:all) fails" do
|
34
34
|
spec_ran = false
|
35
|
-
Behaviour.before(:all) { raise
|
35
|
+
Behaviour.before(:all) { raise NonStandardError }
|
36
36
|
@behaviour.it("test") {spec_ran = true}
|
37
37
|
@behaviour.run(@reporter)
|
38
38
|
spec_ran.should be_false
|
@@ -40,7 +40,7 @@ module Spec
|
|
40
40
|
|
41
41
|
it "should run after(:all) if before(:all) fails" do
|
42
42
|
after_all_ran = false
|
43
|
-
Behaviour.before(:all) { raise }
|
43
|
+
Behaviour.before(:all) { raise NonStandardError }
|
44
44
|
Behaviour.after(:all) { after_all_ran = true }
|
45
45
|
@behaviour.run(@reporter)
|
46
46
|
after_all_ran.should be_true
|
@@ -48,7 +48,7 @@ module Spec
|
|
48
48
|
|
49
49
|
it "should run after(:all) if before(:each) fails" do
|
50
50
|
after_all_ran = false
|
51
|
-
Behaviour.before(:each) { raise }
|
51
|
+
Behaviour.before(:each) { raise NonStandardError }
|
52
52
|
Behaviour.after(:all) { after_all_ran = true }
|
53
53
|
@behaviour.run(@reporter)
|
54
54
|
after_all_ran.should be_true
|
@@ -56,32 +56,95 @@ module Spec
|
|
56
56
|
|
57
57
|
it "should run after(:all) if any example fails" do
|
58
58
|
after_all_ran = false
|
59
|
-
@behaviour.it("should") { raise
|
59
|
+
@behaviour.it("should") { raise NonStandardError }
|
60
60
|
Behaviour.after(:all) { after_all_ran = true }
|
61
61
|
@behaviour.run(@reporter)
|
62
62
|
after_all_ran.should be_true
|
63
63
|
end
|
64
64
|
|
65
|
+
|
66
|
+
it "should unregister a given after(:each) block" do
|
67
|
+
after_all_ran = false
|
68
|
+
@behaviour.it("example") {}
|
69
|
+
proc = Proc.new { after_all_ran = true }
|
70
|
+
Behaviour.after(:each, &proc)
|
71
|
+
@behaviour.run(@reporter)
|
72
|
+
after_all_ran.should be_true
|
73
|
+
|
74
|
+
after_all_ran = false
|
75
|
+
Behaviour.remove_after(:each, &proc)
|
76
|
+
@behaviour.run(@reporter)
|
77
|
+
after_all_ran.should be_false
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should run second after(:each) block even if the first one fails" do
|
81
|
+
example = @behaviour.it("example") {}
|
82
|
+
second_after_ran = false
|
83
|
+
@behaviour.after(:each) do
|
84
|
+
second_after_ran = true
|
85
|
+
raise "second"
|
86
|
+
end
|
87
|
+
first_after_ran = false
|
88
|
+
@behaviour.after(:each) do
|
89
|
+
first_after_ran = true
|
90
|
+
raise "first"
|
91
|
+
end
|
92
|
+
|
93
|
+
@reporter.should_receive(:example_finished) do |example, error, location, example_not_implemented|
|
94
|
+
example.should equal(example)
|
95
|
+
error.message.should eql("first")
|
96
|
+
location.should eql("after(:each)")
|
97
|
+
example_not_implemented.should be_false
|
98
|
+
end
|
99
|
+
@behaviour.run(@reporter)
|
100
|
+
first_after_ran.should be_true
|
101
|
+
second_after_ran.should be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not run second before(:each) if the first one fails" do
|
105
|
+
@behaviour.it("example") {}
|
106
|
+
first_before_ran = false
|
107
|
+
@behaviour.before(:each) do
|
108
|
+
first_before_ran = true
|
109
|
+
raise "first"
|
110
|
+
end
|
111
|
+
second_before_ran = false
|
112
|
+
@behaviour.before(:each) do
|
113
|
+
second_before_ran = true
|
114
|
+
raise "second"
|
115
|
+
end
|
116
|
+
|
117
|
+
@reporter.should_receive(:example_finished) do |name, error, location, example_not_implemented|
|
118
|
+
name.should eql("example")
|
119
|
+
error.message.should eql("first")
|
120
|
+
location.should eql("before(:each)")
|
121
|
+
example_not_implemented.should be_false
|
122
|
+
end
|
123
|
+
@behaviour.run(@reporter)
|
124
|
+
first_before_ran.should be_true
|
125
|
+
second_before_ran.should be_false
|
126
|
+
end
|
127
|
+
|
65
128
|
it "should supply before(:all) as description if failure in before(:all)" do
|
66
|
-
@reporter.should_receive(:example_finished) do |
|
67
|
-
|
68
|
-
error.message.should
|
129
|
+
@reporter.should_receive(:example_finished) do |example, error, location|
|
130
|
+
example.description.should eql("before(:all)")
|
131
|
+
error.message.should == "in before(:all)"
|
69
132
|
location.should eql("before(:all)")
|
70
133
|
end
|
71
134
|
|
72
|
-
Behaviour.before(:all) { raise "in before(:all)" }
|
135
|
+
Behaviour.before(:all) { raise NonStandardError.new("in before(:all)") }
|
73
136
|
@behaviour.it("test") {true}
|
74
137
|
@behaviour.run(@reporter)
|
75
138
|
end
|
76
139
|
|
77
140
|
it "should provide after(:all) as description if failure in after(:all)" do
|
78
|
-
@reporter.should_receive(:example_finished) do |
|
79
|
-
|
141
|
+
@reporter.should_receive(:example_finished) do |example, error, location|
|
142
|
+
example.description.should eql("after(:all)")
|
80
143
|
error.message.should eql("in after(:all)")
|
81
144
|
location.should eql("after(:all)")
|
82
145
|
end
|
83
146
|
|
84
|
-
Behaviour.after(:all) { raise "in after(:all)" }
|
147
|
+
Behaviour.after(:all) { raise NonStandardError.new("in after(:all)") }
|
85
148
|
@behaviour.run(@reporter)
|
86
149
|
end
|
87
150
|
end
|
@@ -159,8 +222,8 @@ module Spec
|
|
159
222
|
end
|
160
223
|
|
161
224
|
it "should supply before(:all) as description if failure in before(:all)" do
|
162
|
-
@reporter.should_receive(:example_finished) do |
|
163
|
-
|
225
|
+
@reporter.should_receive(:example_finished) do |example, error, location|
|
226
|
+
example.description.should eql("before(:all)")
|
164
227
|
error.message.should eql("in before(:all)")
|
165
228
|
location.should eql("before(:all)")
|
166
229
|
end
|
@@ -171,8 +234,8 @@ module Spec
|
|
171
234
|
end
|
172
235
|
|
173
236
|
it "should provide after(:all) as description if failure in after(:all)" do
|
174
|
-
@reporter.should_receive(:example_finished) do |
|
175
|
-
|
237
|
+
@reporter.should_receive(:example_finished) do |example, error, location|
|
238
|
+
example.description.should eql("after(:all)")
|
176
239
|
error.message.should eql("in after(:all)")
|
177
240
|
location.should eql("after(:all)")
|
178
241
|
end
|
@@ -427,42 +490,6 @@ module Spec
|
|
427
490
|
mod1_method_called.should be_true
|
428
491
|
mod2_method_called.should be_true
|
429
492
|
end
|
430
|
-
|
431
|
-
it "should not include untargeted modules" do
|
432
|
-
special_method_called = false
|
433
|
-
special_mod = Module.new do
|
434
|
-
define_method :special_method do
|
435
|
-
special_method_called = true
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
behaviour = Behaviour.new("I'm not special", :behaviour_type => :not_special) {}
|
440
|
-
behaviour.include special_mod, :behaviour_type => :special
|
441
|
-
behaviour.it "test" do
|
442
|
-
special_method
|
443
|
-
end
|
444
|
-
behaviour.run(@reporter)
|
445
|
-
|
446
|
-
special_method_called.should be_false
|
447
|
-
end
|
448
|
-
|
449
|
-
it "should include targeted modules" do
|
450
|
-
special_method_called = false
|
451
|
-
special_mod = Module.new do
|
452
|
-
define_method :special_method do
|
453
|
-
special_method_called = true
|
454
|
-
end
|
455
|
-
end
|
456
|
-
|
457
|
-
behaviour = Behaviour.new("I'm not special", :behaviour_type => :special) {}
|
458
|
-
behaviour.include special_mod, :behaviour_type => :special
|
459
|
-
behaviour.it "test" do
|
460
|
-
special_method
|
461
|
-
end
|
462
|
-
behaviour.run(@reporter)
|
463
|
-
|
464
|
-
special_method_called.should be_true
|
465
|
-
end
|
466
493
|
|
467
494
|
it "should have accessible class methods from included module" do
|
468
495
|
mod1_method_called = false
|
@@ -522,7 +549,9 @@ module Spec
|
|
522
549
|
@behaviour.should be_matches(['jalla'])
|
523
550
|
end
|
524
551
|
|
525
|
-
it "should include
|
552
|
+
it "should include targetted modules included using configuration" do
|
553
|
+
$included_modules = []
|
554
|
+
|
526
555
|
mod1 = Module.new do
|
527
556
|
class << self
|
528
557
|
def included(mod)
|
@@ -539,21 +568,29 @@ module Spec
|
|
539
568
|
end
|
540
569
|
end
|
541
570
|
|
571
|
+
mod3 = Module.new do
|
572
|
+
class << self
|
573
|
+
def included(mod)
|
574
|
+
$included_modules << self
|
575
|
+
end
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
542
579
|
begin
|
543
|
-
$included_modules = []
|
544
580
|
Spec::Runner.configuration.include(mod1, mod2)
|
581
|
+
Spec::Runner.configuration.include(mod3, :behaviour_type => :cat)
|
545
582
|
|
546
|
-
behaviour = Behaviour.new('
|
583
|
+
behaviour = Behaviour.new("I'm special", :behaviour_type => :dog) do
|
547
584
|
end.run(@reporter)
|
548
585
|
|
549
586
|
$included_modules.should include(mod1)
|
550
587
|
$included_modules.should include(mod2)
|
588
|
+
$included_modules.should_not include(mod3)
|
551
589
|
ensure
|
552
|
-
Spec::Runner.configuration.
|
553
|
-
Spec::Runner.configuration.included_modules.delete(mod2)
|
590
|
+
Spec::Runner.configuration.exclude(mod1, mod2, mod3)
|
554
591
|
end
|
555
592
|
end
|
556
|
-
|
593
|
+
|
557
594
|
it "should include any predicate_matchers included using configuration" do
|
558
595
|
$included_predicate_matcher_found = false
|
559
596
|
Spec::Runner.configuration.predicate_matchers[:do_something] = :does_something?
|