README.md in dependor-0.0.5 vs README.md in dependor-0.0.6
- old
+ new
@@ -1,8 +1,12 @@
# Dependor
[![build status](https://secure.travis-ci.org/psyho/dependor.png)](http://travis-ci.org/psyho/dependor)
+[![Code Climate](https://codeclimate.com/github/psyho/dependor.png)](https://codeclimate.com/github/psyho/dependor)
+[![Coverage Status](https://coveralls.io/repos/psyho/dependor/badge.png)](https://coveralls.io/r/psyho/dependor)
+[![Gem Version](https://badge.fury.io/rb/dependor.png)](http://badge.fury.io/rb/dependor)
+[![Dependency Status](https://gemnasium.com/psyho/dependor.png)](https://gemnasium.com/psyho/dependor)
## What is Dependor
Dependor is a set of helpers that make writing Ruby apps that use the dependency injection pattern easier.
It comes as a set of modules, which you can selectively add to your project.
@@ -266,9 +270,71 @@
def get
render text: foo
end
end
+```
+
+## Testing
+
+Dependor doesn't add any dependencies to your classes so you can test them any way you like.
+
+Following class:
+
+```ruby
+class PostCreator
+ takes :post_repository
+
+ def publish(post)
+ post_repository.store(post)
+ end
+end
+```
+
+can be tested:
+
+```ruby
+let(:post_repository) { stub }
+let(:creator) { PostCreator.new(post_repository }
+
+it "stores posts" do
+ post = Post.new
+ post_repository.expects(:store).with(post)
+ creator.publish(post)
+end
+```
+
+## Dependor::Isolate
+
+Dependor::Isolate provides `isolate` function that creates an instance of given class with dependencies taken from a local context. It can be easily integrated with rspec by requiring 'dependor/rspec'.
+
+Previous example can be rewritten as:
+
+```ruby
+require 'dependor/rspec'
+
+let(:post_repository) { stub }
+let(:creator) { isolate(PostCreator) }
+
+it "stores posts" do
+ post = Post.new
+ post_repository.expects(store).with(post)
+ creator.publish(post)
+end
+```
+
+Dependencies are taken from methods available in local context, but they can be specified in paramaters as well:
+
+```ruby
+post_repository = stub
+creator = isolate(PostCreator, post_repository: post_repository)
+```
+
+Or they can be captured from local variables when syntax with block is used:
+
+```ruby
+post_repository = stub
+creator = isolate{PostCreator}
```
## License
MIT. See the MIT-LICENSE file.