Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prathamesh-sonpatki/expectations
Write expectations about the input
https://github.com/prathamesh-sonpatki/expectations
Last synced: 19 days ago
JSON representation
Write expectations about the input
- Host: GitHub
- URL: https://github.com/prathamesh-sonpatki/expectations
- Owner: prathamesh-sonpatki
- License: mit
- Created: 2013-11-30T09:19:39.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2013-12-07T04:13:50.000Z (almost 11 years ago)
- Last Synced: 2024-10-08T05:50:47.170Z (30 days ago)
- Language: Ruby
- Size: 148 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
![Build Status](https://api.travis-ci.org/prathamesh-sonpatki/expectations.png)
# Work in progress
# Expectations
Sometimes we need to validate our input before proceeding.
For eg.
``` ruby
if params[:user] && params[:user][:auth_details]
...
else
...
end
```This makes code look bad. Also doesn't convey our expectations about
the input.We can write RSpec like syntax for our inputs.
For eg.
``` ruby
expect(params).to_have_key(:user) #=> true/false
expect(params[:user]).to_have_key(:auth_details) #=> true/false
```
We can also pass a block which will be yieled when the input
expectation is failed``` ruby
expect(params).to_have_key(:user) do |obj|
obj.errors.join(", ")
end# => "Expected key :user to be present. Not found."
```
## Installation### Don't install yet!!
Add this line to your application's Gemfile:
gem 'expectations'
And then execute:
$ bundle
Or install it yourself as:
$ gem install expectations
## Usage
## TODO:
1. Add more object types
2. Add more validation methods
3. Make yielding of block more flexible
4. Think more!!## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request