require_relative '../spec_helper' describe 'Cli' do before(:each) do @fake_boostrap = mock().as_null_object Bootstrap.stub(:new).and_return(@fake_boostrap) Templates.stub(:all_templates).and_return(["template1", "template2"]) # Force class reload, as the method names are added automatically load File.expand_path(File.join(File.dirname(__FILE__), "../../lib/xcbootstrap/cli.rb")) end let(:cli) { Cli.new } let(:create_cli) { Create.new } describe 'listing all templates' do it 'should print out all available templates' do output = capture_stdout { cli.list } output.split.size.should == 3 output.should include("Templates:") output.should include("template1") output.should include("template2") end end describe 'creating a new project based on a template' do it 'should have the option to create new projects' do cli.should respond_to("create") end it 'should be able to create each available template' do create_cli.should respond_to("template1") create_cli.should respond_to("template2") end it 'should require the project to be specified' do expect { create_cli.template1 }.to raise_error end context 'with a project name specified' do before(:each) do end it 'should run successfully' do expect { create_cli.template1("MyApp") }.to_not raise_error end it 'should create the bootstrapper with the template and project' do # default_template_dir = File.expand_path("templates") Bootstrap.should_receive(:new).with(anything, "template1", "MyApp") create_cli.template1("MyApp") end it 'should pass through the template root to the bootstrapper' do Bootstrap.should_receive(:new).with(/templates/, anything, anything) create_cli.template1("MyApp") end it 'should process and finish the bootstrapping' do @fake_boostrap.should_receive(:process) @fake_boostrap.should_receive(:finish) create_cli.template1("MyApp") end end end end