Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 4 additions & 2 deletions lib/contracts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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