Permalink
Browse files

Updating the specs so things work again

  • Loading branch information...
1 parent 4df8614 commit 111afeee049b49e1e6bf7d57f6ed9efe3a8441d9 @TwP TwP committed Jan 1, 2009
Showing with 90 additions and 139 deletions.
  1. +68 −139 spec/bones/app_spec.rb
  2. +22 −0 spec/spec_helper.rb
View
@@ -2,166 +2,95 @@
require File.expand_path(
File.join(File.dirname(__FILE__), %w[.. spec_helper]))
+class Runner
+ attr_accessor :name
+ def run(*a, &b) nil; end
+end
+
describe Bones::App do
+ before :all do
+ @out = StringIO.new
+ @err = StringIO.new
+ end
+
before :each do
- @main = Bones::App.new
- @skeleton_dir = File.join(@main.mrbones_dir, 'data')
- @skeleton_dir = Bones.path('data') unless test(?e, @skeleton_dir)
+ @runner = Runner.new
+ @app = Bones::App.new(@out, @err)
+
+ Bones::App::CreateCommand.stub!(:new).
+ and_return {@runner.name = :create; @runner}
+ Bones::App::UpdateCommand.stub!(:new).
+ and_return {@runner.name = :update; @runner}
+ Bones::App::FreezeCommand.stub!(:new).
+ and_return {@runner.name = :freeze; @runner}
+ Bones::App::UnfreezeCommand.stub!(:new).
+ and_return {@runner.name = :unfreeze; @runner}
+ Bones::App::InfoCommand.stub!(:new).
+ and_return {@runner.name = :info; @runner}
+ end
+
+ after :each do
+ @out.clear
+ @err.clear
end
- it 'has some defaults when initialized' do
- @main.options.should == {
- :skeleton_dir => @skeleton_dir,
- :with_tasks => false,
- :verbose => false,
- :name => nil,
- :output_dir => nil,
- :action => nil
- }
+ it 'should provide a create command' do
+ @app.run %w[create]
+ @runner.name.should == :create
end
- it 'provides access to the output_dir' do
- @main.output_dir.should be_nil
- @main.options[:output_dir] = 'foo'
- @main.output_dir.should == 'foo'
+ it 'should provide an update command' do
+ @app.run %w[update]
+ @runner.name.should == :update
end
- it 'provides access to the skeleton_dir' do
- @main.skeleton_dir.should == @skeleton_dir
- @main.options[:skeleton_dir] = 'bar'
- @main.skeleton_dir.should == 'bar'
+ it 'should provide a freeze command' do
+ @app.run %w[freeze]
+ @runner.name.should == :freeze
end
- it 'provides access to the project name' do
- @main.name.should be_nil
- @main.options[:name] = 'baz'
- @main.name.should == 'baz'
+ it 'should provide an unfreeze command' do
+ @app.run %w[unfreeze]
+ @runner.name.should == :unfreeze
end
- it 'provides access to the project classname' do
- @main.options[:name] = 'foo-bar'
- @main.classname.should == 'FooBar'
+ it 'should provide an info command' do
+ @app.run %w[info]
+ @runner.name.should == :info
end
- it 'determines if a project should be updated' do
- @main.options[:output_dir] = Bones.path
- @main.update?.should == false
+ it 'should provide a help command' do
+ @app.run %w[--help]
+ @out.readline
+ @out.readline.should match(%r/^ Mr Bones is a handy tool that builds/)
+ @out.clear
- @main.options[:with_tasks] = true
- @main.update?.should == true
+ @app.run %w[-h]
+ @out.readline
+ @out.readline.should match(%r/^ Mr Bones is a handy tool that builds/)
+ end
- @main.options[:output_dir] = Bones.path(%w[foo bar baz buz tmp])
- @main.update?.should == false
+ it 'should default to the help message if no command is given' do
+ @app.run []
+ @out.readline
+ @out.readline.should match(%r/^ Mr Bones is a handy tool that builds/)
end
- # ------------------------------------------------------------------------
- describe 'when parsing command line options' do
-
- before :each do
- @main.stub!(:mrbones_dir).and_return(Bones.path(%w[spec data]))
- end
-
- it 'parses the project name' do
- @main.parse %w[foo-bar]
- @main.name.should == 'foo-bar'
- @main.output_dir.should == 'foo-bar'
- end
-
- it 'parses the verbose flag' do
- @main.parse %w[-v foo-bar]
- @main.name.should == 'foo-bar'
- @main.verbose?.should == true
-
- @main = Bones::App.new
- @main.parse %w[--verbose foo-bar]
- @main.name.should == 'foo-bar'
- @main.verbose?.should == true
- end
-
- it 'parses the directory flag' do
- @main.parse %w[-d blah foo-bar]
- @main.name.should == 'foo-bar'
- @main.output_dir.should == 'blah'
-
- @main = Bones::App.new
- @main.parse %w[--directory blah foo-bar]
- @main.name.should == 'foo-bar'
- @main.output_dir.should == 'blah'
- end
-
- it 'parses the directory flag' do
- @main.parse %w[-d blah foo-bar]
- @main.name.should == 'foo-bar'
- @main.output_dir.should == 'blah'
-
- @main = Bones::App.new
- @main.parse %w[--directory blah foo-bar]
- @main.name.should == 'foo-bar'
- @main.output_dir.should == 'blah'
- end
-
- it 'parses the skeleton to use flag' do
- @main.stub!(:mrbones_dir).and_return(Bones.path(%w[spec data]))
- @main.parse %w[-s data foo-bar]
- @main.name.should == 'foo-bar'
- @main.skeleton_dir.should == Bones.path(%w[spec data data])
-
- @main = Bones::App.new
- @main.stub!(:mrbones_dir).and_return(Bones.path(%w[spec data]))
- @main.parse %w[--skeleton foo foo-bar]
- @main.name.should == 'foo-bar'
- @main.skeleton_dir.should == Bones.path(%w[spec data foo])
- end
-
- it 'parses the with-tasks flag' do
- @main.parse %w[--with-tasks foo-bar]
- @main.name.should == 'foo-bar'
- @main.with_tasks?.should == true
- end
-
- it 'parses the freeze flag' do
- @main.parse %w[--freeze]
- @main.name.should be_nil
- @main.options[:action].should == :freeze
-
- @main = Bones::App.new
- @main.parse %w[--freeze foo-bar]
- @main.name.should == 'foo-bar'
- @main.options[:action].should == :freeze
- end
-
- it 'parses the unfreeze flag' do
- @main.parse %w[--unfreeze]
- @main.name.should be_nil
- @main.options[:action].should == :unfreeze
- end
-
- it 'parses the info flag' do
- @main.parse %w[--info]
- @main.name.should be_nil
- @main.options[:action].should == :info
-
- @main = Bones::App.new
- @main.parse %w[-i]
- @main.name.should be_nil
- @main.options[:action].should == :info
- end
-
- it 'parses the repository flag' do
- @main.parse %w[--freeze --repository git://github.com/TwP/bones.git]
- @main.repository.should == 'git://github.com/TwP/bones.git'
- @main.options[:action].should == :freeze
-
- @main = Bones::App.new
- @main.parse %w[--freeze -r http://example.com/projects/sts/svn/trunk]
- @main.repository.should == 'http://example.com/projects/sts/svn/trunk'
- @main.options[:action].should == :freeze
- end
+ it 'should report an error for unrecognized commands' do
+ lambda {@app.run %w[foo]}.should raise_error(SystemExit)
+ @err.readline.should == 'ERROR: While executing bones ... (RuntimeError)'
+ @err.readline.should == ' Unknown command "foo"'
end
- # ------------------------------------------------------------------------
- #describe 'when archiving tasks'
+ it 'should report a version number' do
+ @app.run %w[--version]
+ @out.readline.should == "Mr Bones #{Bones::VERSION}"
+ @out.clear
+
+ @app.run %w[-v]
+ @out.readline.should == "Mr Bones #{Bones::VERSION}"
+ end
end # describe Bones::App
View
@@ -3,6 +3,7 @@
unless defined? BONES_SPEC_HELPER
BONES_SPEC_HELPER = true
+require 'stringio'
require File.expand_path(
File.join(File.dirname(__FILE__), %w[.. lib bones]))
@@ -17,6 +18,27 @@
# config.mock_with :rr
end
+class StringIO
+ alias :_readline :readline
+ def readline
+ @_pos ||= 0
+ seek @_pos
+ begin
+ _line = _readline
+ @_pos = tell
+ _line.rstrip
+ rescue EOFError
+ nil
+ end
+ end
+
+ def clear
+ truncate 0
+ seek 0
+ @_pos = 0
+ end
+end
+
end # unless defined?
# EOF

0 comments on commit 111afee

Please sign in to comment.