Updated Rails to 2.1.0
[gitorious:georgyos-clone.git] / vendor / plugins / rspec_on_rails / spec / rails / spec_server_spec.rb
1 require File.dirname(__FILE__) + '/../spec_helper'
2
3 describe "script/spec_server file", :shared => true do
4   attr_accessor :tmbundle_install_directory
5
6   after do
7     system "kill -9 #{@pid}"
8   end
9
10   it "runs a spec" do
11     dir = File.dirname(__FILE__)
12     output = ""
13     Timeout.timeout(10) do
14       loop do
15         output = `#{RAILS_ROOT}/script/spec #{dir}/sample_spec.rb --drb 2>&1`
16         break unless output.include?("No server is running")
17       end
18     end
19
20     unless $?.exitstatus == 0
21       flunk "command 'script/spec spec/sample_spec' failed\n#{output}"
22     end
23   end
24
25   def start_spec_server
26     create_spec_server_pid_file
27     start_spec_server_process
28   end
29
30   def create_spec_server_pid_file
31     current_dir = File.dirname(__FILE__)
32     pid_dir = "#{Dir.tmpdir}/#{Time.now.to_i}"
33     @spec_server_pid_file = "#{pid_dir}/spec_server.pid"
34     FileUtils.mkdir_p pid_dir
35     system "touch #{@spec_server_pid_file}"
36     @rspec_path = File.expand_path("#{current_dir}/../../../rspec/lib")
37   end
38
39   def start_spec_server_process
40     dir = File.dirname(__FILE__)
41     spec_server_cmd =  %Q|export HOME=#{Dir.tmpdir}; |
42     spec_server_cmd << %Q|ruby -e 'system("echo " + Process.pid.to_s + " > #{@spec_server_pid_file}"); |
43     spec_server_cmd << %Q|$LOAD_PATH.unshift("#{@rspec_path}"); require "spec"; |
44     spec_server_cmd << %Q|load "#{RAILS_ROOT}/script/spec_server"' &|
45     system spec_server_cmd
46
47     file_content = ""
48     Timeout.timeout(5) do
49       loop do
50         file_content = File.read(@spec_server_pid_file)
51         break unless file_content.blank?
52       end
53     end
54     @pid = Integer(File.read(@spec_server_pid_file))
55   end
56 end
57
58 describe "script/spec_server file without TextMate bundle" do
59   it_should_behave_like "script/spec_server file"
60   before do
61     start_spec_server
62   end
63 end
64
65 describe "script/spec_server file with TextMate bundle" do
66   it_should_behave_like "script/spec_server file"
67   before do
68     dir = File.dirname(__FILE__)
69     @tmbundle_install_directory = File.expand_path("#{Dir.tmpdir}/Library/Application Support/TextMate/Bundles")
70     @bundle_name = "RSpec.tmbundle"
71     FileUtils.mkdir_p(tmbundle_install_directory)
72     bundle_dir = File.expand_path("#{dir}/../../../../../../#{@bundle_name}")
73     File.directory?(bundle_dir).should be_true
74     unless system(%Q|ln -s #{bundle_dir} "#{tmbundle_install_directory}"|)
75       raise "Creating link to Textmate Bundle"
76     end
77     start_spec_server
78   end
79
80   after do
81     bundle_file_to_remove = "#{tmbundle_install_directory}/#{@bundle_name}"
82     if bundle_file_to_remove == "/"
83       raise "bundle file path resolved to '/' - could not call rm"
84     end
85     unless system(%Q|rm "#{bundle_file_to_remove}"|)
86       raise "Removing Textmate bundle link failed"
87     end
88   end
89 end