summary refs log tree commit diff
diff options
context:
space:
mode:
authorrff.rff <rff.rff@gmail.com>2008-01-14 01:34:44 +0100
committerrff.rff <rff.rff@gmail.com>2008-01-14 01:34:44 +0100
commit7c7f279c9b61a89240f93c0339042cbd7485d0c5 (patch)
tree78ac28fefb130a8a105e2f43b46807c8ab074016
parent2444359b9a64408475887edaf7af5d6920833aff (diff)
downloadbacon-7c7f279c9b61a89240f93c0339042cbd7485d0c5.tar.gz
bacon-7c7f279c9b61a89240f93c0339042cbd7485d0c5.tar.xz
bacon-7c7f279c9b61a89240f93c0339042cbd7485d0c5.zip
add should('foo') shortcut for it('should foo')
darcs-hash:20080114003444-16231-e4a97d3932c8636751d72f101e0363c124522390.gz
-rw-r--r--lib/bacon.rb8
-rw-r--r--test/spec_should.rb34
2 files changed, 42 insertions, 0 deletions
diff --git a/lib/bacon.rb b/lib/bacon.rb
index 945f1f1..0bede91 100644
--- a/lib/bacon.rb
+++ b/lib/bacon.rb
@@ -125,6 +125,14 @@ module Bacon
       Counter[:specifications] += 1
       run_requirement description, block
     end
+    
+    def should(*args, &block)
+      if Counter[:depth]==0
+        it('should '+args.first,&block)
+      else
+        super(*args,&block)
+      end
+    end
 
     def run_requirement(description, spec)
       Bacon.handle_requirement description do
diff --git a/test/spec_should.rb b/test/spec_should.rb
new file mode 100644
index 0000000..be34038
--- /dev/null
+++ b/test/spec_should.rb
@@ -0,0 +1,34 @@
+$: << File.dirname(__FILE__) + '/../lib/'
+require 'bacon'
+
+
+describe "#should shortcut for #it('should')" do
+  
+  should "be called" do
+    @called= true
+  end
+  
+  should "save some characters by typing should" do
+    lambda { should.satisfy { 1 == 1 } }.should.not.raise
+  end
+
+  should "save characters even on failure" do
+    lambda { should.satisfy { 1 == 2 } }.should.raise Bacon::Error
+  end
+
+  should "work nested" do
+    should.satisfy {1==1}
+  end
+  
+
+  count = Bacon::Counter[:specifications]
+  should "add new specifications" do
+    # XXX this should +=1 but it's +=2
+    (count+1).should == Bacon::Counter[:specifications]
+  end
+
+  should "have been called" do
+    @called.should.be == true
+  end
+
+end