]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/runner/drb_command_line_spec.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / spec / spec / runner / drb_command_line_spec.rb
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3 module Spec
4   module Runner
5     describe DrbCommandLine, "without running local server" do
6       unless Config::CONFIG['ruby_install_name'] == 'jruby'
7         it "should print error when there is no running local server" do
8           err = StringIO.new
9           out = StringIO.new
10           DrbCommandLine.run(OptionParser.parse(['--version'], err, out))
11
12           err.rewind
13           err.read.should =~ /No server is running/
14         end
15       end    
16     end
17
18     class DrbCommandLineSpec < ::Spec::Example::ExampleGroup
19       describe DrbCommandLine, "with local server"
20
21       class CommandLineForSpec
22         def self.run(argv, stderr, stdout)
23           exit Spec::Runner::CommandLine.run(OptionParser.parse(argv, stderr, stdout))
24         end
25       end
26       
27       unless Config::CONFIG['ruby_install_name'] == 'jruby'
28         before(:all) do
29           DRb.start_service("druby://localhost:8989", CommandLineForSpec)
30           @@drb_example_file_counter = 0
31         end
32
33         before(:each) do
34           create_dummy_spec_file
35           @@drb_example_file_counter = @@drb_example_file_counter + 1
36         end
37
38         after(:each) do
39           File.delete(@dummy_spec_filename)
40         end
41
42         after(:all) do
43           DRb.stop_service
44         end
45
46         it "should run against local server" do
47           out = run_spec_via_druby(['--version'])
48           out.should =~ /RSpec/n
49         end
50
51         it "should output green colorized text when running with --colour option" do
52           out = run_spec_via_druby(["--colour", @dummy_spec_filename])
53           out.should =~ /\e\[32m/n
54         end
55
56         it "should output red colorized text when running with -c option" do
57           out = run_spec_via_druby(["-c", @dummy_spec_filename])
58           out.should =~ /\e\[31m/n
59         end
60
61         def create_dummy_spec_file
62           @dummy_spec_filename = File.expand_path(File.dirname(__FILE__)) + "/_dummy_spec#{@@drb_example_file_counter}.rb"
63           File.open(@dummy_spec_filename, 'w') do |f|
64             f.write %{
65               describe "DUMMY CONTEXT for 'DrbCommandLine with -c option'" do
66                 it "should be output with green bar" do
67                   true.should be_true
68                 end
69
70                 it "should be output with red bar" do
71                   violated("I want to see a red bar!")
72                 end
73               end
74             }
75           end
76         end
77
78         def run_spec_via_druby(argv)
79           err, out = StringIO.new, StringIO.new
80           out.instance_eval do
81             def tty?; true end
82           end
83           options = ::Spec::Runner::Options.new(err, out)
84           options.argv = argv
85           Spec::Runner::DrbCommandLine.run(options)
86           out.rewind; out.read
87         end
88       end
89
90     end
91   end
92 end