Permalink
Browse files

usable! and a spec for functions with default args

  • Loading branch information...
1 parent a3072e6 commit 9c760fda22b70b4c0df7415280b441389f59da17 @egonSchiele committed Jul 1, 2012
Showing with 18 additions and 8 deletions.
  1. +3 −5 README.md
  2. +10 −3 spec/contracts_specs.rb
  3. +5 −0 spec/fixtures/fixtures.rb
View
@@ -6,9 +6,7 @@ You can think of contracts as `assert` on steroids.
## Current Status
-**Experimental, actively developing.**
-
-This project is stable enough for use. However, it's API / usage is still evolving, and future versions will probably break older versions (for now!).
+**Usable!**
## Installation
@@ -20,7 +18,7 @@ This project is stable enough for use. However, it's API / usage is still evolvi
## Hello World
-A contract is one line of code that you write above a method definition. It validates the arguments to the method, and validates it's return value.
+A contract is one line of code that you write above a method definition. It validates the arguments to the method, and validates the return value of the method.
Here is a simple contract:
@@ -71,7 +69,7 @@ If you're using the library, please [let me know](https://github.com/egonSchiele
## Credits
-Inspired by [contracts.coffee](http://disnetdev.com/contracts.coffee/). I also heavily "borrowed" from their README to write this one. Sorry/thanks!
+Inspired by [contracts.coffee](http://disnetdev.com/contracts.coffee/).
Copyright 2012 [Aditya Bhargava](http://adit.io).
View
@@ -120,13 +120,20 @@
describe "contracts on functions" do
it "should pass for a function that passes the contract" do
- expect { map([1, 2, 3], lambda { |x| x + 1 }).to_not raise_error }
+ expect { @o.map([1, 2, 3], lambda { |x| x + 1 }).to_not raise_error }
end
it "should fail for a function that doesn't pass the contract" do
- expect { map([1, 2, 3], lambda { |x| "bad return value" }).to raise_error }
+ expect { @o.map([1, 2, 3], lambda { |x| "bad return value" }).to raise_error }
end
- end
+ end
+
+ describe "default args to functions" do
+ it "should work for a function call that relies on default args" do
+ expect { @o.default_args.to_not raise_error }
+ expect { @o.default_args("foo").to raise_error }
+ end
+ end
describe "failure callbacks" do
before :each do
@@ -138,3 +138,8 @@ def map(arr, func)
end
ret
end
+
+Contract Num => Num
+def default_args(x = 1)
+ 2
+end

0 comments on commit 9c760fd

Please sign in to comment.