object-history 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - rbx
5
+ - ree
6
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", "~> 2.3.0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.6.0"
7
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.6.1)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.9.2)
11
+ rspec (2.3.0)
12
+ rspec-core (~> 2.3.0)
13
+ rspec-expectations (~> 2.3.0)
14
+ rspec-mocks (~> 2.3.0)
15
+ rspec-core (2.3.1)
16
+ rspec-expectations (2.3.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.3.0)
19
+
20
+ PLATFORMS
21
+ java
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ jeweler (~> 1.6.0)
27
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Piotr Niełacny
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,72 @@
1
+ = object-history
2
+
3
+ Test your objects with history path.
4
+ http://travis-ci.org/LTe/object-history.png
5
+
6
+ == Instalation
7
+ Add to your Gemfile
8
+ gem 'object-history'
9
+
10
+ == How to use
11
+ Just include *ObjectHistory* to class.
12
+ class TrackedObject
13
+ include ObjectHistory
14
+ end
15
+
16
+ And on bottom of class add the methods that you want to track
17
+ class TrackedObject
18
+ include ObjectHistory
19
+ track_history_of :your_method
20
+ end
21
+
22
+ == Example
23
+ class TrackedObject
24
+ attr_accessor :number
25
+
26
+ def initialize(child = nil)
27
+ @number = 0
28
+ end
29
+
30
+ def add_one(*args, &block)
31
+ @number += 1
32
+ block.call(self) if block_given?
33
+ end
34
+
35
+ include ObjectHistory
36
+ track_history_of :add_one
37
+ end
38
+
39
+ After that you can test with rspec using *have_track* matcher ;-)
40
+
41
+ describe TrackObject do
42
+ before(:each) do
43
+ @track_object = TrackObject.new
44
+ end
45
+
46
+ it "should every execute add one to :number" do
47
+ 3.times {@track_object.add_one}
48
+ @track_object.should have_track(:number, [0,1,2,3])
49
+ end
50
+ end
51
+
52
+ === Deep clone?
53
+ Works
54
+ === method_missing?
55
+ Fuck method_missing ;*. Just deal with it.
56
+
57
+
58
+ == Contributing to object-history
59
+
60
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
61
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
62
+ * Fork the project
63
+ * Start a feature/bugfix branch
64
+ * Commit and push until you are happy with your contribution
65
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
66
+ * 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.
67
+
68
+ == Copyright
69
+
70
+ Copyright (c) 2011 Piotr Niełacny. See LICENSE.txt for
71
+ further details.
72
+
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "object-history"
18
+ gem.homepage = "http://github.com/LTe/object-history"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Track your object with rspec matcher}
21
+ gem.description = %Q{Track your object with rspec matcher}
22
+ gem.email = "piotr.nielacny@gmail.com"
23
+ gem.authors = ["Piotr Niełacny"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
+
40
+ rdoc.rdoc_dir = 'rdoc'
41
+ rdoc.title = "object-history #{version}"
42
+ rdoc.rdoc_files.include('README*')
43
+ rdoc.rdoc_files.include('lib/**/*.rb')
44
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,25 @@
1
+ module ObjectHistory
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+ def track_history_of(*methods, &block)
8
+ attr_accessor :__history
9
+
10
+ methods.each do |method|
11
+ track_method = "__#{method}__track__"
12
+ unless private_instance_methods.include?(track_method)
13
+ alias_method track_method, method
14
+ private track_method
15
+ define_method method do |*args, &block|
16
+ @__history ||= [Marshal.load(Marshal.dump(self))]
17
+ ret = send(track_method, *args, &block)
18
+ @__history << Marshal.load(Marshal.dump(self))
19
+ ret
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ RSpec::Matchers.define :have_track do |accessor, expected|
2
+ match do |actual|
3
+ actual.__history.map{|x|x.send(accessor)} == expected
4
+ end
5
+
6
+ failure_message_for_should do |actual|
7
+ "expected that #{actual.__history.map{|x|x.send(accessor)}} would be a precise multiple of #{expected}"
8
+ end
9
+
10
+ failure_message_for_should_not do |actual|
11
+ "expected that #{actual.__history.map{|x|x.send(accessor)}} would not be a precise multiple of #{expected}"
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ require 'object-history/object-history'
2
+ require 'object-history/rspec-matchers.rb' if defined?(RSpec::Matchers)
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{object-history}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Piotr Niełacny"]
12
+ s.date = %q{2011-06-18}
13
+ s.description = %q{Track your object with rspec matcher}
14
+ s.email = %q{piotr.nielacny@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/object-history.rb",
30
+ "lib/object-history/object-history.rb",
31
+ "lib/object-history/rspec-matchers.rb",
32
+ "object-history.gemspec",
33
+ "spec/object-history_spec.rb",
34
+ "spec/spec_helper.rb",
35
+ "spec/support/track_object.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/LTe/object-history}
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.6.2}
41
+ s.summary = %q{Track your object with rspec matcher}
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
50
+ else
51
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ObjectHistory" do
4
+
5
+ before(:each) do
6
+ @track_object = TrackedObject.new
7
+ end
8
+
9
+ it "rspec matcher should work" do
10
+ 3.times {@track_object.add_one}
11
+ @track_object.should have_track(:number, [0,1,2,3])
12
+ end
13
+
14
+ it "should work with blocks" do
15
+ 3.times do
16
+ @track_object.add_one do |track_obj|
17
+ track_obj.number += 1
18
+ end
19
+ end
20
+ @track_object.should have_track(:number, [0,2,4,6])
21
+ end
22
+
23
+ context "deep clone" do
24
+
25
+ before(:each) do
26
+ @track_object = TrackedObject.new(TrackedObject.new)
27
+ end
28
+
29
+ it "should work with deep clone object" do
30
+ 3.times do
31
+ @track_object.add_one
32
+ end
33
+
34
+ 4.times do
35
+ @track_object.track_object.add_one
36
+ end
37
+
38
+ @track_object.should have_track(:number, [0,1,2,3])
39
+ @track_object.track_object.should have_track(:number, [0,1,2,3,4])
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'object-history'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,16 @@
1
+ class TrackedObject
2
+ attr_accessor :number, :track_object
3
+
4
+ def initialize(child = nil)
5
+ @number = 0
6
+ @track_object = child
7
+ end
8
+
9
+ def add_one(*args, &block)
10
+ @number += 1
11
+ block.call(self) if block_given?
12
+ end
13
+
14
+ include ObjectHistory
15
+ track_history_of :add_one
16
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: object-history
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Piotr Niełacny
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-06-18 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &15267000 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 2.3.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *15267000
26
+ - !ruby/object:Gem::Dependency
27
+ name: bundler
28
+ requirement: &15266420 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *15266420
37
+ - !ruby/object:Gem::Dependency
38
+ name: jeweler
39
+ requirement: &15265820 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.6.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *15265820
48
+ description: Track your object with rspec matcher
49
+ email: piotr.nielacny@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - LICENSE.txt
54
+ - README.rdoc
55
+ files:
56
+ - .document
57
+ - .rspec
58
+ - .travis.yml
59
+ - Gemfile
60
+ - Gemfile.lock
61
+ - LICENSE.txt
62
+ - README.rdoc
63
+ - Rakefile
64
+ - VERSION
65
+ - lib/object-history.rb
66
+ - lib/object-history/object-history.rb
67
+ - lib/object-history/rspec-matchers.rb
68
+ - object-history.gemspec
69
+ - spec/object-history_spec.rb
70
+ - spec/spec_helper.rb
71
+ - spec/support/track_object.rb
72
+ has_rdoc: true
73
+ homepage: http://github.com/LTe/object-history
74
+ licenses:
75
+ - MIT
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ segments:
87
+ - 0
88
+ hash: -3708414665896704862
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.6.2
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Track your object with rspec matcher
101
+ test_files: []