spec/scaffolder/tool/help_spec.rb in scaffolder-tools-0.1.2 vs spec/scaffolder/tool/help_spec.rb in scaffolder-tools-0.1.3

- old
+ new

@@ -1,6 +1,6 @@ -require File.expand_path(File.join(File.dirname(__FILE__),'..','..','spec_helper')) +require 'spec_helper' describe Scaffolder::Tool::Help do it "should inherit from Scaffolder::Tool" do described_class.superclass.should == Scaffolder::Tool @@ -16,111 +16,101 @@ [options] Commands: MSG - before(:each) do - @settings = Hash.new - @settings.stubs(:rest).returns([]) - end + describe "execution with" do - describe "execution with no command and the version argument" do - - subject do - @settings[:version] = true - @settings[:empty_args] = true - described_class.new(@settings) + before(:each) do + @settings = Hash.new + @settings.stubs(:rest).returns([]) end - it "should not raise an error" do - lambda{ subject.execute }.should_not raise_error - end + describe "unknown command" do - it "should return the version number" do - version = File.read('VERSION').strip - subject.execute.should == "scaffolder tool version " + version - end + subject do + @settings[:unknown_tool] = 'anything' + described_class.new(@settings) + end - end + it "should raise an error" do + lambda{ subject.execute }.should(raise_error(ArgumentError, + "Unknown command 'anything'.\nSee 'scaffolder help'.")) + end - describe "execution with no command" do - - subject do - @settings[:empty_args] = true - described_class.new(@settings) end - it "should not raise an error" do - lambda{ subject.execute }.should_not raise_error - end + describe "no arguments" do - it "should contain the usage information" do - subject.execute.should include(USAGE) - end + subject do + @settings[:empty_args] = true + described_class.new(@settings) + end - it "should contain each tool information" do - tool_subclasses.each do |cls| - subject.execute.should include(cls.description) + it "should not raise an error" do + lambda{ subject.execute }.should_not raise_error end - end - end + it "should contain the usage information" do + subject.execute.should include(USAGE) + end - describe "execution with an invalid command arguments" do + it "should contain each tool information" do + tool_subclasses.each do |cls| + subject.execute.should include(cls.description) + end + end - subject do - @settings[:unknown_tool] = 'unknown_command' - described_class.new(@settings) end - it "should raise an error" do - lambda{ subject.execute }.should(raise_error(ArgumentError, - "Unknown command 'unknown_command'.\nSee 'scaffolder help'.")) - end + describe "version argument" do - end + subject do + @settings[:version] = true + @settings[:empty_args] = true + described_class.new(@settings) + end - describe "execution with the name of a scaffolder tool command" do + it "should not raise an error" do + lambda{ subject.execute }.should_not raise_error + end - before(:each) do - @tool = Class.new(Scaffolder::Tool) - described_class.superclass.const_set('Fake',@tool) + it "should return the version number" do + version = File.read('VERSION').strip + subject.execute.should == "scaffolder tool version " + version + end - @man_dir = File.join(%W|#{File.dirname(__FILE__)} .. .. .. man| ) - @fake_man = File.join(@man_dir,'scaffolder-fake.1.ronn') end - after(:each) do - described_class.superclass.send(:remove_const,'Fake') - end + describe "existing man page" do - subject do - @settings.stubs(:rest).returns(['fake']) - described_class.new(@settings) - end + before(:each) do + @tool = Class.new(Scaffolder::Tool) + described_class.superclass.const_set('Fake',@tool) - it "should not raise an error" do - Kernel.stubs(:system).with("ronn -m #{File.expand_path(@fake_man)}") - lambda{ subject.execute }.should_not raise_error - end + @man_dir = File.join(%W|#{File.dirname(__FILE__)} .. .. .. man| ) + @fake_man = File.join(@man_dir,'scaffolder-fake.1.ronn') + end - it "should call ronn on the command line with the man file location" do - Kernel.expects(:system).with("ronn -m #{File.expand_path(@fake_man)}") - subject.execute - end + after(:each) do + described_class.superclass.send(:remove_const,'Fake') + end - end + subject do + @settings.stubs(:rest).returns(['fake']) + described_class.new(@settings) + end - describe "execution with the name of a unknown command" do + it "should not raise an error" do + Kernel.stubs(:system).with("ronn -m #{File.expand_path(@fake_man)}") + lambda{ subject.execute }.should_not raise_error + end - subject do - @settings.stubs(:rest).returns(['fake']) - described_class.new(@settings) - end + it "should call ronn on the command line with the man file location" do + Kernel.expects(:system).with("ronn -m #{File.expand_path(@fake_man)}") + subject.execute + end - it "should raise an error" do - lambda{ subject.execute }.should(raise_error(ArgumentError, - "Unknown command 'fake'.\nSee 'scaffolder help'.")) end end end