/
commands_spec.rb
45 lines (36 loc) · 1.15 KB
/
commands_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Commandant::Command do
before { Commandant.clear! }
subject { Commandant::Command }
describe ".new" do
it "requres a name" do
lambda { subject.new(){ "this is the command" }
}.should raise_error(ArgumentError)
end
it "requires a block" do
lambda { subject.new(:name)
}.should raise_error(ArgumentError)
end
it "accepts a description" do
subject.new(:name, "description"){}.description.should == "description"
end
it "adds the command to the list of commands by name" do
command = subject.new(:name){ "block" }
Commandant::COMMANDS[:name].should == command
end
describe "when the command already exists" do
before { Commandant::Command.new(:dup) { "I am a duplicate" } }
it do
lambda {
Commandant.command(:dup) { "I am a duplicate" }
}.should raise_error(ArgumentError)
end
end
end
describe "#call" do
subject { Commandant::Command.new(:name){ "called" } }
it "calls the given command" do
subject.call.should == "called"
end
end
end