changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/autotest/rspec_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + "/../autotest_helper"
2
3class Autotest
4
5 module AutotestHelper
6 def rspec_output
7 <<-HERE
8.............PPF
9
101)
11'false should be false' FAILED
12expected: true,
13 got: false (using ==)
14./spec/autotest/rspec_spec.rb:203:
15
16Finished in 0.158674 seconds
17
1816 examples, 1 failure, 2 pending
19
20Pending:
21Autotest::Rspec handling failed results should return an array of failed examples and errors (TODO)
22Autotest::Rspec tests/specs for a given file should find all the specs for a given file (TODO)
23HERE
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 == [
43 File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec"),
44 "#{Config::CONFIG['bindir']}/spec"
45 ]
46 end
47 end
48
49 describe Rspec, "selection of rspec command" do
50 include AutotestHelper
51
52 before :each do
53 common_setup
54 @rspec_autotest = Rspec.new
55 end
56
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
59
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
63 end
64
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)
69
70 @rspec_autotest.spec_command.should == "/foo/spec"
71 end
72
73 it "should raise an error if no spec command is found at all" do
74 File.stub!(:exists?).and_return false
75
76 lambda {
77 @rspec_autotest.spec_command
78 }.should raise_error(RspecCommandError, "No spec command could be found!")
79 end
80
81 end
82
83 describe Rspec, "selection of rspec command (windows compatibility issues)" do
84 include AutotestHelper
85
86 before :each do
87 common_setup
88 end
89
90 it "should use the ALT_SEPARATOR if it is non-nil" do
91 @rspec_autotest = Rspec.new
92 spec_command = File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec")
93 @rspec_autotest.stub!(:spec_commands).and_return [spec_command]
94 @rspec_autotest.spec_command(@windows_alt_separator).should == spec_command.gsub('/', @windows_alt_separator)
95 end
96
97 it "should not use the ALT_SEPATOR if it is nil" do
98 @windows_alt_separator = nil
99 @rspec_autotest = Rspec.new
100 spec_command = File.expand_path("#{File.dirname(__FILE__)}/../../bin/spec")
101 @rspec_autotest.stub!(:spec_commands).and_return [spec_command]
102 @rspec_autotest.spec_command.should == spec_command
103 end
104 end
105
106 describe Rspec, "adding spec.opts --options" do
107 before :each do
108 @rspec_autotest = Rspec.new
109 end
110
111 it "should return the command line option to add spec.opts if the options file exists" do
112 File.stub!(:exist?).and_return true
113 @rspec_autotest.add_options_if_present.should == "-O spec/spec.opts "
114 end
115
116 it "should return an empty string if no spec.opts exists" do
117 File.stub!(:exist?).and_return false
118 Rspec.new.add_options_if_present.should == ""
119 end
120 end
121
122 describe Rspec do
123 before :each do
124 @rspec_autotest = Rspec.new
125 @rspec_autotest.stub!(:ruby).and_return "ruby"
126 @rspec_autotest.stub!(:add_options_if_present).and_return "-O spec/spec.opts"
127
128 @ruby = @rspec_autotest.ruby
129 @spec_command = @rspec_autotest.spec_command
130 @options = @rspec_autotest.add_options_if_present
131 @files_to_test = {
132 :spec => ["file_one", "file_two"]
133 }
134 # this is not the inner representation of Autotest!
135 @rspec_autotest.stub!(:files_to_test).and_return @files_to_test
136 @files_to_test.stub!(:keys).and_return @files_to_test[:spec]
137 @to_test = @files_to_test.keys.flatten.join ' '
138 end
139
140 it "should make the apropriate test command" do
141 @rspec_autotest.make_test_cmd(@files_to_test).should == "#{@ruby} -S #{@spec_command} #{@options} #{@to_test}"
142 end
143 end
144
145 describe Rspec, "mappings" do
146
147 before(:each) do
148 @lib_file = "lib/something.rb"
149 @spec_file = "spec/something_spec.rb"
150 @rspec_autotest = Rspec.new
151 @rspec_autotest.hook :initialize
152 end
153
154 it "should find the spec file for a given lib file" do
155 @rspec_autotest.should map_specs([@spec_file]).to(@lib_file)
156 end
157
158 it "should find the spec file if given a spec file" do
159 @rspec_autotest.should map_specs([@spec_file]).to(@spec_file)
160 end
161
162 it "should only find the file if the file is being tracked (in @file)" do
163 @rspec_autotest.should map_specs([]).to("lib/untracked_file")
164 end
165 end
166
167 describe Rspec, "consolidating failures" do
168 include AutotestHelper
169
170 before :each do
171 common_setup
172 @rspec_autotest = Rspec.new
173
174 @spec_file = "./spec/autotest/rspec_spec.rb"
175 @rspec_autotest.instance_variable_set("@files", {@spec_file => Time.now})
176 @rspec_autotest.stub!(:find_files_to_test).and_return true
177 end
178
179 it "should return no failures if no failures were given in the output" do
180 @rspec_autotest.consolidate_failures([[]]).should == {}
181 end
182
183 it "should return a hash with the spec filename => spec name for each failure or error" do
184 @rspec_autotest.stub!(:test_files_for).and_return "./spec/autotest/rspec_spec.rb"
185 foo = [
186 [
187 "false should be false",
188 "expected: true,\n got: false (using ==)\n./spec/autotest/rspec_spec.rb:203:"
189 ]
190 ]
191 @rspec_autotest.consolidate_failures(foo).should == {@spec_file => ["false should be false"]}
192 end
193
194 end
195end