require 'spec_helper' require 'classicCMS/cli' require 'stringio' describe 'Base' do before :all do #set directory $default[:dir] = Dir.pwd $default[:log] = $stdout $stdout = StringIO.new end before :each do clear_tmp @cli = ClassicCMS::Cli.command ['new'] end it "should display an help message when the app name isn't displayed" do capture_log do ClassicCMS::Cli.command ['new'] $stdout.string.should == "hmm you are using the command wrong: classicCMS new [app name]\n" end end it "should display error message when app name already exist" do capture_log do Dir.mkdir 'app' ClassicCMS::Cli.command ['new', 'app'] $stdout.string.should == "hmm I think that app already exists!\n" end end it "should display message when command is finished" do capture_log do app_name = 'app' ClassicCMS::Cli.command ['new', app_name] $stdout.string.should == "#{app_name} created!\n" end end it "should create a directory with app name" do capture_log do app_name = 'app' ClassicCMS::Cli.command ['new', app_name] File.directory?(app_name).should == true end end it "should create public directory" do capture_log do app_name = 'app' ClassicCMS::Cli.command ['new', app_name] File.directory?(app_name + '/public').should == true end end it "should create views directory" do capture_log do app_name = 'app' ClassicCMS::Cli.command ['new', app_name] File.directory?(app_name + '/views').should == true end end it "should display message that server is starting" do capture_log do ClassicCMS::Cli.command ['server'] $stdout.string.should == "going to start server...\n" end end it "should display an error message when command isn't recognized" do capture_log do ClassicCMS::Cli.command ['nonexistant'] $stdout.string.should == "you are so smart! I don't know what you mean!\n" end end after :all do Dir::chdir $default[:dir] $stdout = $default[:log] end end