test/test_vegas_runner.rb in vegas-0.1.2 vs test/test_vegas_runner.rb in vegas-0.1.3

- old
+ new

@@ -1,19 +1,22 @@ require File.join(File.dirname(__FILE__), 'test_helper.rb') -Vegas::Runner::ROOT_DIR = File.join(File.dirname(__FILE__), 'tmp', '.vegas') +Vegas::Runner.class_eval do + remove_const :ROOT_DIR + ROOT_DIR = File.join(File.dirname(__FILE__), 'tmp', '.vegas') +end describe 'Vegas::Runner' do before do FileUtils.rm_rf(File.join(File.dirname(__FILE__), 'tmp')) @log = StringIO.new Vegas::Runner.logger = Logger.new(@log) end - describe '.new' do + describe 'creating an instance' do - describe 'with basic usage' do + describe 'basic usage' do before do Vegas::Runner.any_instance.expects(:system).once vegas(TestApp1, 'vegas_test_app_1', {:sessions => true}, ["route","--debug"]) end @@ -22,10 +25,18 @@ end it "sets app name" do @vegas.app_name.should == 'vegas_test_app_1' end + + it "sets quoted app name" do + @vegas.quoted_app_name.should == "'vegas_test_app_1'" + end + + it "sets filesystem friendly app name" do + @vegas.filesystem_friendly_app_name.should == 'vegas_test_app_1' + end it "stores options" do @vegas.options[:sessions].should.be.true end @@ -42,27 +53,90 @@ end it "writes a url with the port" do @vegas.url_file.should have_matching_file_content(/0.0.0.0\:#{@vegas.port}/) end + + it "knows where to find the pid file" do + @vegas.pid_file.should.equal \ + File.join(@vegas.app_dir, @vegas.filesystem_friendly_app_name + ".pid") + # @vegas.pid_file.should exist_as_file + end end + + describe 'basic usage with a funky app name' do + before do + Vegas::Runner.any_instance.expects(:system).once + vegas(TestApp1, 'Funky YEAH!1!', {:sessions => true}, ["route","--debug"]) + end - describe 'with a sinatra app' do + it "sets app" do + @vegas.app.should == TestApp1 + end + + it "sets app name" do + @vegas.app_name.should == 'Funky YEAH!1!' + end + + it "sets quoted app name" do + @vegas.quoted_app_name.should == "'Funky YEAH!1!'" + end + + it "sets filesystem friendly app name" do + @vegas.filesystem_friendly_app_name.should == 'Funky_YEAH_1_' + end + + it "stores options" do + @vegas.options[:sessions].should.be.true + end + + it "puts unparsed args into args" do + @vegas.args.should == ["route"] + end + + it "parses options into @options" do + @vegas.options[:debug].should.be.true + end + + it "writes the app dir" do + @vegas.app_dir.should exist_as_file + end + + it "writes a url with the port" do + @vegas.url_file.should have_matching_file_content(/0.0.0.0\:#{@vegas.port}/) + end + + it "knows where to find the pid file" do + @vegas.pid_file.should.equal \ + File.join(@vegas.app_dir, @vegas.filesystem_friendly_app_name + ".pid") + # @vegas.pid_file.should exist_as_file + end + end + + describe 'with a sinatra app using mongrel for the server' do before do - TestApp1.expects(:detect_rack_handler).returns(Rack::Handler::Mongrel) + TestApp1.set :server, "mongrel" Vegas::Runner.any_instance.expects(:system).once Rack::Handler::Mongrel.stubs(:run) vegas(TestApp1, 'vegas_test_app_1', {:skip_launch => true, :sessions => true}, ["route","--debug"]) end - + it 'sets the rack handler automaticaly' do @vegas.rack_handler.should == Rack::Handler::Mongrel end + end - it "sets options on the app" do - @vegas.app.sessions.should.be.true + describe 'with a sinatra app using webrick for the server' do + before do + TestApp1.set :server, "webrick" + Vegas::Runner.any_instance.expects(:system).once + Rack::Handler::WEBrick.stubs(:run) + vegas(TestApp1, 'vegas_test_app_1', {:skip_launch => true, :sessions => true}, ["route","--debug"]) end - + + it 'sets the rack handler automaticaly' do + @vegas.rack_handler.should == Rack::Handler::WEBrick + end end describe 'with a simple rack app' do before do vegas(RackApp1, 'rack_app_1', {:skip_launch => true, :sessions => true})