1 require File.dirname(__FILE__) + "/../autotest_helper"
11 'false should be false' FAILED
14 ./spec/autotest/rspec_spec.rb:203:
16 Finished in 0.158674 seconds
18 16 examples, 1 failure, 2 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)
30 @kernel.stub!(:proc).and_return @proc
32 File.stub!(:exists).and_return true
33 @windows_alt_separator = "\\"
34 @posix_separator = '/'
36 @rspec_output = rspec_output
40 describe Rspec, "rspec_commands" do
41 it "should contain the various commands, ordered by preference" do
42 Rspec.new.spec_commands.should == [
43 File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec"),
44 "#{Config::CONFIG['bindir']}/spec"
49 describe Rspec, "selection of rspec command" do
50 include AutotestHelper
54 @rspec_autotest = Rspec.new
57 it "should try to find the spec command if it exists in ./bin and use it above everything else" do
58 File.stub!(:exists?).and_return true
60 spec_path = File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec")
61 File.should_receive(:exists?).with(spec_path).and_return true
62 @rspec_autotest.spec_command.should == spec_path
65 it "should otherwise select the default spec command in gem_dir/bin/spec" do
66 @rspec_autotest.stub!(:spec_commands).and_return ["/foo/spec"]
67 Config::CONFIG.stub!(:[]).and_return "/foo"
68 File.should_receive(:exists?).with("/foo/spec").and_return(true)
70 @rspec_autotest.spec_command.should == "/foo/spec"
73 it "should raise an error if no spec command is found at all" do
74 File.stub!(:exists?).and_return false
77 @rspec_autotest.spec_command
78 }.should raise_error(RspecCommandError, "No spec command could be found!")
83 describe Rspec, "selection of rspec command (windows compatibility issues)" do
84 include AutotestHelper
90 it "should use the ALT_SEPARATOR if it is non-nil" do
91 pending("autotest got re-worked so this is failing for the moment")
92 @rspec_autotest = Rspec.new
93 spec_command = File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec")
94 @rspec_autotest.stub!(:spec_commands).and_return [spec_command]
95 @rspec_autotest.spec_command.should == spec_command.gsub('/', '\\')
98 it "should not use the ALT_SEPATOR if it is nil" do
99 @windows_alt_separator = nil
100 @rspec_autotest = Rspec.new
101 spec_command = File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec")
102 @rspec_autotest.stub!(:spec_commands).and_return [spec_command]
103 @rspec_autotest.spec_command.should == spec_command
107 describe Rspec, "adding spec.opts --options" do
109 @rspec_autotest = Rspec.new
112 it "should return the command line option to add spec.opts if the options file exists" do
113 File.stub!(:exist?).and_return true
114 @rspec_autotest.add_options_if_present.should == "-O spec/spec.opts "
117 it "should return an empty string if no spec.opts exists" do
118 File.stub!(:exist?).and_return false
119 Rspec.new.add_options_if_present.should == ""
125 @rspec_autotest = Rspec.new
126 @rspec_autotest.stub!(:ruby).and_return "ruby"
127 @rspec_autotest.stub!(:add_options_if_present).and_return "-O spec/spec.opts"
129 @ruby = @rspec_autotest.ruby
130 @spec_command = @rspec_autotest.spec_command
131 @options = @rspec_autotest.add_options_if_present
133 :spec => ["file_one", "file_two"]
135 # this is not the inner representation of Autotest!
136 @rspec_autotest.stub!(:files_to_test).and_return @files_to_test
137 @files_to_test.stub!(:keys).and_return @files_to_test[:spec]
138 @to_test = @files_to_test.keys.flatten.join ' '
141 it "should make the apropriate test command" do
142 @rspec_autotest.make_test_cmd(@files_to_test).should == "#{@ruby} -S #{@spec_command} #{@options} #{@to_test}"
146 describe Rspec, "test mappings" do
148 @rspec_autotest = Rspec.new
149 @rspec_autotest.hook :initialize
152 it "should map all filenames in spec/ which end in .rb" do
153 @rspec_autotest.instance_eval{@test_mappings}.should have_key(%r%^spec/.*\.rb$%)
156 it "should map all names in lib which end in .rb to the corresponding ones in spec/" do
157 @rspec_autotest.instance_eval{@test_mappings}.should have_key(%r%^lib/(.*)\.rb$%)
160 it "should find all files in spec/shares/* and the spec helper in spec/spec_helper" do
161 @rspec_autotest.instance_eval{@test_mappings}.should have_key(%r%^spec/(spec_helper|shared/.*)\.rb$%)
165 describe Rspec, "handling results" do
166 include AutotestHelper
170 @rspec_autotest = Rspec.new
171 @rspec_autotest.stub!(:hook)
173 @results = mock String
174 @results.stub!(:scan).and_return ""
177 it "should call hook(:red) if there are failures" do
178 @rspec_autotest.stub!(:consolidate_failures).and_return ["spec/some_spec.rb"]
180 @rspec_autotest.should_receive(:hook).with(:red)
181 @rspec_autotest.handle_results(@results)
184 it "should call hook(:green) if there are no failures" do
185 @rspec_autotest.stub!(:consolidate_failures).and_return []
186 @rspec_autotest.should_receive(:hook).with(:green)
187 @rspec_autotest.handle_results(@results)
191 describe Rspec, "handling failed results" do
192 include AutotestHelper
198 it %(should scan the output into a multi-dimensional array,
199 consisting of the failing spec's name as the first element,
200 and the failure as the second) do
201 @rspec_autotest = Rspec.new
202 @rspec_autotest.failed_results(@rspec_output).should == [
204 "false should be false",
205 "expected: true,\n got: false (using ==)\n./spec/autotest/rspec_spec.rb:203:"
211 describe Rspec, "specs for a given file" do
213 @lib_file = "lib/something.rb"
214 @spec_file = "spec/something_spec.rb"
215 @rspec_autotest = Rspec.new
216 @rspec_autotest.hook :initialize
218 @rspec_autotest.instance_variable_set("@files", {@lib_file => Time.now, @spec_file => Time.now})
219 @rspec_autotest.stub!(:find_files_to_test).and_return true
222 it "should find the spec file for a given lib file" do
223 @rspec_autotest.specs_for_file(@lib_file).should == [@spec_file]
226 it "should find the spec file if given a spec file" do
227 @rspec_autotest.specs_for_file(@spec_file).should == [@spec_file]
230 it "should only find the file if the file is being tracked (in @file)" do
231 @other_file = "lib/some_non_tracked_file"
232 @rspec_autotest.specs_for_file(@other_file).should == []
236 describe Rspec, "consolidating failures" do
237 include AutotestHelper
241 @rspec_autotest = Rspec.new
243 @spec_file = "./spec/autotest/rspec_spec.rb"
244 @rspec_autotest.instance_variable_set("@files", {@spec_file => Time.now})
245 @rspec_autotest.stub!(:find_files_to_test).and_return true
248 it "should return no failures if no failures were given in the output" do
249 @rspec_autotest.stub!(:failed_results).and_return [[]]
250 @rspec_autotest.consolidate_failures(@rspec_autotest.failed_results).should == {}
253 it "should return a hash with the spec filename => spec name for each failure or error" do
254 @rspec_autotest.stub!(:failed_results).and_return([
256 "false should be false",
257 "expected: true,\n got: false (using ==)\n./spec/autotest/rspec_spec.rb:203:"
260 @rspec_autotest.consolidate_failures(@rspec_autotest.failed_results).should == {@spec_file => ["false should be false"]}