Changeset 571

Show
Ignore:
Timestamp:
06/30/08 13:25:05 (2 months ago)
Author:
bbleything
Message:
  • move the command infrastructure specs into a shared behaviours file and make it shared
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • linen/trunk/spec/command_infrastructure_spec.rb

    r570 r571  
    2020 
    2121require File.join(File.dirname(__FILE__),"spec_helper.rb") 
    22 require 'linen/argument' 
     22require File.join(File.dirname(__FILE__),"shared_behaviours.rb") 
    2323 
    24 describe "A class that includes Linen::Plugin::CommandInfrastructure" do 
     24describe Linen::Plugin::CommandInfrastructure do 
    2525    before( :each ) do 
    2626        @command_class = Class.new { include Linen::Plugin::CommandInfrastructure } 
    27          
    28         @plugin = mock( "mock plugin" ) 
    29         @plugin.stub!( :short_name ).and_return( "plugin" ) 
    30          
    31         @command = @command_class.new( @plugin, "command" ) {} 
    3227    end 
    3328     
    34     describe "conforms to the Command definition API" do 
    35         it "implements the require_confirmation directive" do 
    36             @command.instance_variable_get( :@require_confirmation ).should be_nil 
    37             @command = @command_class.new( @plugin, "command" ) { require_confirmation } 
    38             @command.instance_variable_get( :@require_confirmation ).should be_true 
    39         end 
    40          
    41         it "implements the action directive" do 
    42             proc = lambda {} 
    43              
    44             @command.instance_variable_get( :@action_proc ).should be_nil 
    45             @command = @command_class.new( @plugin, "command" ) { action &proc } 
    46             @command.instance_variable_get( :@action_proc ).should be( proc ) 
    47         end 
    48          
    49         it "implements the help_message directive" do 
    50             message = "This command is used for BEES" 
    51              
    52             @command.instance_variable_get( :@help_text ).should == "No help for plugin command" 
    53             @command = @command_class.new( @plugin, "command" ) { help_message message } 
    54             @command.instance_variable_get( :@help_text ).should be( message ) 
    55         end 
    56          
    57         it "implements the inspect directive" do 
    58             proc = lambda {} 
    59              
    60             @command.instance_variable_get( :@inspect_proc ).should be_nil 
    61             @command = @command_class.new( @plugin, "command" ) { inspect &proc } 
    62             @command.instance_variable_get( :@inspect_proc ).should be( proc ) 
    63         end 
    64     end 
    65      
    66     describe "conforms to the Command execution API" do 
    67         it "provides the requires_confirmation? helper method" do 
    68             @command.requires_confirmation?.should be_false 
    69             @command = @command_class.new( @plugin, "command" ) { require_confirmation } 
    70             @command.requires_confirmation?.should be_true 
    71         end 
    72          
    73         it "provides the can_inspect? helper method" do 
    74             @command.can_inspect?.should be_false 
    75             @command = @command_class.new( @plugin, "command" ) { inspect {} } 
    76             @command.can_inspect?.should be_true 
    77         end 
    78          
    79         it "can be executed" do 
    80             proc = lambda {} 
    81             workspace = mock( "workspace" ) 
    82             Linen::Workspace.should_receive( :new ).and_return( workspace ) 
    83             workspace.should_receive( :instance_eval ).with( &proc )             
    84  
    85             @command = @command_class.new( @plugin, "command" ) { action &proc }         
    86             @command.execute 
    87         end 
    88          
    89         it "can be inspected" do 
    90             proc = lambda {} 
    91             workspace = mock( "workspace" ) 
    92             Linen::Workspace.should_receive( :new ).twice.and_return( workspace ) 
    93             workspace.should_receive( :instance_eval ).with( &proc )             
    94  
    95             @command = @command_class.new( @plugin, "command" ) { inspect &proc } 
    96             @command.inspect 
    97         end 
    98          
    99         it "can display help information when no help message is set" do 
    100             @command = @command_class.new( @plugin, "command" ) {} 
    101             @command.instance_variable_set( :@arguments, [ :a, :b, :c ] ) 
    102              
    103             help_lines = @command.help.split( "\n" ) 
    104             help_lines.shift.should == "No help for plugin command" 
    105             help_lines.shift.should == "" 
    106             help_lines.shift.should == "Usage: plugin command <a> <b> <c>" 
    107         end 
    108          
    109         it "can display help information when a help message is set" do 
    110             help_msg = "I can shoot bees from my sandwich!" 
    111             @command = @command_class.new( @plugin, "sandwich" ) { help_message help_msg } 
    112             @command.instance_variable_set( :@arguments, [ :shoot, :reload, :eat ] ) 
    113              
    114             help_lines = @command.help.split( "\n" ) 
    115             help_lines.shift.should == help_msg 
    116             help_lines.shift.should == "" 
    117             help_lines.shift.should == "Usage: plugin sandwich <shoot> <reload> <eat>" 
    118         end 
    119     end 
     29    it_should_behave_like "A class that includes Linen::Plugin::CommandInfrastructure" 
    12030end