spec/unit/cli_spec.rb in xcbootstrap-0.0.3 vs spec/unit/cli_spec.rb in xcbootstrap-0.1.0
- old
+ new
@@ -1,33 +1,71 @@
require_relative '../spec_helper'
describe 'Cli' do
before(:each) do
- fake_boostrap = mock().as_null_object
- XCBootstrap::Bootstrap.stub(:new).and_return(fake_boostrap)
+ @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 }
- context 'with the template and project arguments' do
- it 'should point to the default template dir' do
- default_template_dir = File.expand_path("templates")
- XCBootstrap::Bootstrap.should_receive(:new).with(default_template_dir, anything, anything)
- XCBootstrap::Cli.new("", {}).run(["--template", "MyTemplate", "--project", "../MyProject"])
- end
+ describe 'listing all templates' do
+ it 'should print out all available templates' do
+ output = capture_stdout { cli.list }
+
+ output.split.size.should == 3
- it 'should bootstrap the project from the template' do
- XCBootstrap::Bootstrap.should_receive(:new).with(anything, "MyTemplate", "../MyProject")
- XCBootstrap::Cli.new("", {}).run(["--template", "MyTemplate", "--project", "../MyProject"])
+ output.should include("Templates:")
+ output.should include("template1")
+ output.should include("template2")
end
end
- context 'without the template flag' do
- it 'should raise an error' do
- expect { XCBootstrap::Cli.new("", {}).run(["--project", "../MyProject"]) }.to raise_error
+ 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
- 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
- context 'without the project flag' do
- it 'should raise an error' do
- expect { XCBootstrap::Cli.new("", {}).run(["--template", "MyTemplate"]) }.to raise_error
+ 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