Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lte/object-history
Track your object with rspec matcher
https://github.com/lte/object-history
Last synced: about 2 months ago
JSON representation
Track your object with rspec matcher
- Host: GitHub
- URL: https://github.com/lte/object-history
- Owner: LTe
- License: mit
- Created: 2011-06-18T16:44:13.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-06-18T22:09:30.000Z (over 13 years ago)
- Last Synced: 2024-10-08T09:33:44.775Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 97.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: LICENSE.txt
Awesome Lists containing this project
README
= object-history
Test your objects with history path. Simply select the method around which will create a deep copy of an object and see how the object changed during operation.
http://travis-ci.org/LTe/object-history.png
== Instalation
Add to your Gemfile
gem 'object-history'== How to use
Just include *ObjectHistory* to class.
class TrackedObject
include ObjectHistory
endAnd on bottom of class add the methods that you want to track
class TrackedObject
include ObjectHistory
track_history_of :your_method
end== Examples
=== Track object
class TrackedObject
attr_accessor :numberdef initialize(child = nil)
@number = 0
enddef add_one(*args, &block)
@number += 1
block.call(self) if block_given?
endinclude ObjectHistory
track_history_of :add_one
endAfter that you can test with rspec using *have_track* matcher ;-)
describe TrackObject do
before(:each) do
@track_object = TrackObject.new
endit "should every execute add one to :number" do
3.times {@track_object.add_one}
@track_object.should have_track(:number, [0,1,2,3])
end
end=== Post example
class Post
attr_accessor :statusdef initialize
@status = :new
enddef accept
@status = :accepted
enddef send_post
@status = :sent
enddef load
@status = :loaded
endinclude ObjectHistory
track_history_of :accept, :send_post, :load
endAnd *Rspec*
before(:each) do
@post = Post.new
endit "should have [:new, :loaded, :accepted, :sent] path" do
@post.load
@post.accept
@post.send_post@post.should have_track(:status, [:new, :loaded, :accepted, :sent])
end=== Accessors
class Accessor
attr_accessor :versiondef initialize
@version = 0
endinclude ObjectHistory
track_history_of :version=
end*Rspec*
before(:each) do
@accessor = Accessor.new
endit "should track accessor" do
@accessor.version = 5
@accessor.version = 10@accessor.should have_track(:version, [0,5,10])
end=== Deep clone?
Works
=== method_missing?
Fuck method_missing ;*. Just deal with it.== Contributing to object-history
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.== Copyright
Copyright (c) 2011 Piotr Niełacny. See LICENSE.txt for
further details.