diff --git a/Gemfile b/Gemfile index 9e2a184..f69b40a 100644 --- a/Gemfile +++ b/Gemfile @@ -4,10 +4,11 @@ gemspec group :test do gem "rspec" - gem "rubocop", "~> 0.29.1", :platform => [:ruby_20, :ruby_21] + gem "rubocop", "~> 0.29.1", :platform => [:ruby_20, :ruby_21, :ruby_22] end group :development do gem "method_profiler" gem "ruby-prof" + gem "rake" end diff --git a/README.md b/README.md index 399c85f..f0eb5be 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,18 @@ Check out [this awesome tutorial](http://egonschiele.github.com/contracts.ruby). Check out [this screencast](https://vimeo.com/85883356). +## Development + +To get started do the following: + +1. Install required gems for development + + `bundle install` + +2. Run our test suite + + `bundle exec rake` + ## Performance Using contracts.ruby results in very little slowdown. Check out [this blog post](http://adit.io/posts/2013-03-04-How-I-Made-My-Ruby-Project-10x-Faster.html#seconds-6) for more info. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..f87b0e6 --- /dev/null +++ b/Rakefile @@ -0,0 +1,11 @@ +if RUBY_VERSION >= "2" + task :default => [:spec, :rubocop] + + require "rubocop/rake_task" + RuboCop::RakeTask.new +else + task :default => [:spec] +end + +require "rspec/core/rake_task" +RSpec::Core::RakeTask.new(:spec) diff --git a/lib/contracts.rb b/lib/contracts.rb index 4074666..7a1e711 100644 --- a/lib/contracts.rb +++ b/lib/contracts.rb @@ -110,6 +110,8 @@ def initialize(klass, method, *contracts) @ret_validator = Contract.make_validator(ret_contract) + @pattern_match = false + # == @has_proc_contract last_contract = args_contracts.last is_a_proc = last_contract.is_a?(Class) && (last_contract <= Proc || last_contract <= Method) @@ -251,7 +253,7 @@ def maybe_append_options! args, blk # Used to determine type of failure exception this contract should raise in case of failure def failure_exception - if @pattern_match + if pattern_match? PatternMatchingError else ParamContractError @@ -266,6 +268,6 @@ def pattern_match! # Used to determine if contract is a pattern matching contract def pattern_match? - @pattern_match + @pattern_match == true end end