C0 code coverage information
Generated on Mon Aug 13 01:18:55 -0400 2007 with rcov 0.8.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
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 ["/foo/spec"]
63 Config::CONFIG.stub!(:[]).and_return "/foo"
64 File.should_receive(:exists?).with("/foo/spec").and_return(true)
65
66 @rspec_autotest.spec_command.should == "/foo/spec"
67 end
68
69 it "should raise an error if no spec command is found at all" do
70 File.stub!(:exists?).and_return false
71
72 lambda {
73 @rspec_autotest.spec_command
74 }.should raise_error(RspecCommandError, "No spec command could be found!")
75 end
76
77 end
78
79 describe Rspec, "selection of rspec command (windows compatibility issues)" do
80 include AutotestHelper
81
82 before :each do
83 common_setup
84 end
85
86 it "should use the ALT_SEPARATOR if it is non-nil" do
87 @rspec_autotest = Rspec.new(@kernel, @posix_separator, @windows_alt_separator)
88 @rspec_autotest.stub!(:spec_commands).and_return [File.join('bin', 'spec')]
89 @rspec_autotest.spec_command.should == "bin\\spec"
90 end
91
92 it "should not use the ALT_SEPATOR if it is nil" do
93 @windows_alt_separator = nil
94 @rspec_autotest = Rspec.new(@kernel, @posix_separator, @windows_alt_separator)
95 @rspec_autotest.stub!(:spec_commands).and_return [File.join('bin', 'spec')]
96 @rspec_autotest.spec_command.should == "bin/spec"
97 end
98 end
99
100 describe Rspec, "adding spec.opts --options" do
101 before :each do
102 @rspec_autotest = Rspec.new
103 end
104
105 it "should return the command line option to add spec.opts if the options file exists" do
106 File.stub!(:exist?).and_return true
107 @rspec_autotest.add_options_if_present.should == "-O spec/spec.opts "
108 end
109
110 it "should return an empty string if no spec.opts exists" do
111 File.stub!(:exist?).and_return false
112 Rspec.new.add_options_if_present.should == ""
113 end
114 end
115
116 describe Rspec do
117 before :each do
118 @rspec_autotest = Rspec.new
119 @rspec_autotest.stub!(:ruby).and_return "ruby"
120 @rspec_autotest.stub!(:add_options_if_present).and_return "-O spec/spec.opts"
121
122 @ruby = @rspec_autotest.ruby
123 @spec_command = @rspec_autotest.spec_command
124 @options = @rspec_autotest.add_options_if_present
125 @files_to_test = {
126 :spec => ["file_one", "file_two"]
127 }
128 # this is not the inner representation of Autotest!
129 @rspec_autotest.stub!(:files_to_test).and_return @files_to_test
130 @files_to_test.stub!(:keys).and_return @files_to_test[:spec]
131 @to_test = @files_to_test.keys.flatten.join ' '
132 end
133
134 it "should make the apropriate test command" do
135 @rspec_autotest.make_test_cmd(@files_to_test).should == "#{@ruby} -S #{@spec_command} #{@options} #{@to_test}"
136 end
137 end
138
139 describe Rspec, "test mappings" do
140 before :each do
141 @proc = mock Proc
142 @kernel = mock Kernel
143 @kernel.stub!(:proc).and_return @proc
144 @rspec_autotest = Rspec.new(@kernel)
145 end
146
147 it "should map all filenames in spec/ which end in .rb" do
148 @rspec_autotest.test_mappings[%r%^spec/.*\.rb$%].should == @proc
149 end
150
151 it "should map all names in lib which end in .rb to the corresponding ones in spec/" do
152 @rspec_autotest.test_mappings[%r%^lib/(.*)\.rb$%].should == @proc
153 end
154
155 it "should find all files in spec/shares/* and the spec helper in spec/spec_helper" do
156 @rspec_autotest.test_mappings[%r%^spec/(spec_helper|shared/.*)\.rb$%].should == @proc
157 end
158 end
159
160 describe Rspec, "handling results" do
161 include AutotestHelper
162
163 before :each do
164 common_setup
165 @rspec_autotest = Rspec.new(@kernel, @posix_separator, @windows_alt_separator)
166 @rspec_autotest.stub!(:hook)
167
168 @results = mock String
169 @results.stub!(:scan).and_return ""
170 end
171
172 it "should call hook(:red) if there are failures" do
173 @rspec_autotest.stub!(:consolidate_failures).and_return ["spec/some_spec.rb"]
174
175 @rspec_autotest.should_receive(:hook).with(:red)
176 @rspec_autotest.handle_results(@results)
177 end
178
179 it "should call hook(:green) if there are no failures" do
180 @rspec_autotest.stub!(:consolidate_failures).and_return []
181 @rspec_autotest.should_receive(:hook).with(:green)
182 @rspec_autotest.handle_results(@results)
183 end
184 end
185
186 describe Rspec, "handling failed results" do
187 include AutotestHelper
188
189 before :each do
190 common_setup
191 end
192
193 it %(should scan the output into a multi-dimensional array,
194 consisting of the failing spec's name as the first element,
195 and the failure as the second) do
196 @rspec_autotest = Rspec.new
197 @rspec_autotest.failed_results(@rspec_output).should == [
198 [
199 "false should be false",
200 "expected: true,\n got: false (using ==)\n./spec/autotest/rspec_spec.rb:203:"
201 ]
202 ]
203 end
204 end
205
206 describe Rspec, "specs for a given file" do
207 before :each do
208 @lib_file = "lib/something.rb"
209 @spec_file = "spec/something_spec.rb"
210 @rspec_autotest = Rspec.new
211
212 @rspec_autotest.instance_variable_set("@files", {@lib_file => Time.now, @spec_file => Time.now})
213 @rspec_autotest.stub!(:find_files_to_test).and_return true
214 end
215
216 it "should find the spec file for a given lib file" do
217 @rspec_autotest.specs_for_file(@lib_file).should == [@spec_file]
218 end
219
220 it "should find the spec file if given a spec file" do
221 @rspec_autotest.specs_for_file(@spec_file).should == [@spec_file]
222 end
223
224 it "should only find the file if the file is being tracked (in @file)" do
225 @other_file = "lib/some_non_tracked_file"
226 @rspec_autotest.specs_for_file(@other_file).should == []
227 end
228 end
229
230 describe Rspec, "consolidating failures" do
231 include AutotestHelper
232
233 before :each do
234 common_setup
235 @rspec_autotest = Rspec.new
236
237 @spec_file = "./spec/autotest/rspec_spec.rb"
238 @rspec_autotest.instance_variable_set("@files", {@spec_file => Time.now})
239 @rspec_autotest.stub!(:find_files_to_test).and_return true
240 end
241
242 it "should return no failures if no failures were given in the output" do
243 @rspec_autotest.stub!(:failed_results).and_return [[]]
244 @rspec_autotest.consolidate_failures(@rspec_autotest.failed_results).should == {}
245 end
246
247 it "should return a hash with the spec filename => spec name for each failure or error" do
248 @rspec_autotest.stub!(:failed_results).and_return([
249 [
250 "false should be false",
251 "expected: true,\n got: false (using ==)\n./spec/autotest/rspec_spec.rb:203:"
252 ]
253 ])
254 @rspec_autotest.consolidate_failures(@rspec_autotest.failed_results).should == {@spec_file => ["false should be false"]}
255 end
256
257 end
258 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.