| 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" |
|---|