object-history 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  = object-history
2
2
 
3
3
  Test your objects with history path.
4
+
4
5
  http://travis-ci.org/LTe/object-history.png
5
6
 
6
7
  == Instalation
@@ -19,7 +20,8 @@ And on bottom of class add the methods that you want to track
19
20
  track_history_of :your_method
20
21
  end
21
22
 
22
- == Example
23
+ == Examples
24
+ === Track object
23
25
  class TrackedObject
24
26
  attr_accessor :number
25
27
 
@@ -49,6 +51,69 @@ After that you can test with rspec using *have_track* matcher ;-)
49
51
  end
50
52
  end
51
53
 
54
+ === Post example
55
+ class Post
56
+ attr_accessor :status
57
+
58
+ def initialize
59
+ @status = :new
60
+ end
61
+
62
+ def accept
63
+ @status = :accepted
64
+ end
65
+
66
+ def send_post
67
+ @status = :sent
68
+ end
69
+
70
+ def load
71
+ @status = :loaded
72
+ end
73
+
74
+ include ObjectHistory
75
+ track_history_of :accept, :send_post, :load
76
+ end
77
+
78
+ And *Rspec*
79
+ before(:each) do
80
+ @post = Post.new
81
+ end
82
+
83
+ it "should have [:new, :loaded, :accepted, :sent] path" do
84
+ @post.load
85
+ @post.accept
86
+ @post.send_post
87
+
88
+ @post.should have_track(:status, [:new, :loaded, :accepted, :sent])
89
+ end
90
+
91
+ === Accessors
92
+ class Accessor
93
+ attr_accessor :version
94
+
95
+ def initialize
96
+ @version = 0
97
+ end
98
+
99
+ include ObjectHistory
100
+ track_history_of :version=
101
+ end
102
+
103
+ *Rspec*
104
+ before(:each) do
105
+ @accessor = Accessor.new
106
+ end
107
+
108
+ it "should track accessor" do
109
+ @accessor.version = 5
110
+ @accessor.version = 10
111
+
112
+ @accessor.should have_track(:version, [0,5,10])
113
+ end
114
+
115
+
116
+
52
117
  === Deep clone?
53
118
  Works
54
119
  === method_missing?
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,13 +1,25 @@
1
1
  RSpec::Matchers.define :have_track do |accessor, expected|
2
2
  match do |actual|
3
- actual.__history.map{|x|x.send(accessor)} == expected
3
+ if actual.__history
4
+ actual.__history.map{|x|x.send(accessor)} == expected
5
+ else
6
+ [] == expected
7
+ end
4
8
  end
5
9
 
6
10
  failure_message_for_should do |actual|
7
- "expected that #{actual.__history.map{|x|x.send(accessor)}} would be a precise multiple of #{expected}"
11
+ if actual.__history
12
+ "expected that #{actual.__history.map{|x|x.send(accessor)}} would be a precise multiple of #{expected}"
13
+ else
14
+ "expected that #{[]} would be a precise multiple of #{expected}"
15
+ end
8
16
  end
9
17
 
10
18
  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}"
19
+ if actual.__history
20
+ "expected that #{actual.__history.map{|x|x.send(accessor)}} would not be a precise multiple of #{expected}"
21
+ else
22
+ "expected that #{[]} would not be a precise multiple of #{expected}"
23
+ end
12
24
  end
13
25
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{object-history}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Piotr Niełacny"]
@@ -32,6 +32,8 @@ Gem::Specification.new do |s|
32
32
  "object-history.gemspec",
33
33
  "spec/object-history_spec.rb",
34
34
  "spec/spec_helper.rb",
35
+ "spec/support/accessor.rb",
36
+ "spec/support/post.rb",
35
37
  "spec/support/track_object.rb"
36
38
  ]
37
39
  s.homepage = %q{http://github.com/LTe/object-history}
@@ -21,7 +21,6 @@ describe "ObjectHistory" do
21
21
  end
22
22
 
23
23
  context "deep clone" do
24
-
25
24
  before(:each) do
26
25
  @track_object = TrackedObject.new(TrackedObject.new)
27
26
  end
@@ -39,4 +38,31 @@ describe "ObjectHistory" do
39
38
  @track_object.track_object.should have_track(:number, [0,1,2,3,4])
40
39
  end
41
40
  end
41
+
42
+ context "post" do
43
+ before(:each) do
44
+ @post = Post.new
45
+ end
46
+
47
+ it "should have [:new, :loaded, :accepted, :sent] path" do
48
+ @post.load
49
+ @post.accept
50
+ @post.send_post
51
+
52
+ @post.should have_track(:status, [:new, :loaded, :accepted, :sent])
53
+ end
54
+ end
55
+
56
+ context "accessor" do
57
+ before(:each) do
58
+ @accessor = Accessor.new
59
+ end
60
+
61
+ it "should track accessor" do
62
+ @accessor.version = 5
63
+ @accessor.version = 10
64
+
65
+ @accessor.should have_track(:version, [0,5,10])
66
+ end
67
+ end
42
68
  end
@@ -0,0 +1,10 @@
1
+ class Accessor
2
+ attr_accessor :version
3
+
4
+ def initialize
5
+ @version = 0
6
+ end
7
+
8
+ include ObjectHistory
9
+ track_history_of :version=
10
+ end
@@ -0,0 +1,23 @@
1
+ class Post
2
+ attr_accessor :status
3
+
4
+ def initialize
5
+ @status = :new
6
+ end
7
+
8
+ def accept
9
+ @status = :accepted
10
+ end
11
+
12
+ def send_post
13
+ @status = :sent
14
+ end
15
+
16
+ def load
17
+ @status = :loaded
18
+ end
19
+
20
+ include ObjectHistory
21
+ track_history_of :accept, :send_post, :load
22
+ end
23
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object-history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &15267000 !ruby/object:Gem::Requirement
17
+ requirement: &16477000 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.3.0
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *15267000
25
+ version_requirements: *16477000
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: bundler
28
- requirement: &15266420 !ruby/object:Gem::Requirement
28
+ requirement: &16476480 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *15266420
36
+ version_requirements: *16476480
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: jeweler
39
- requirement: &15265820 !ruby/object:Gem::Requirement
39
+ requirement: &16476000 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 1.6.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *15265820
47
+ version_requirements: *16476000
48
48
  description: Track your object with rspec matcher
49
49
  email: piotr.nielacny@gmail.com
50
50
  executables: []
@@ -68,6 +68,8 @@ files:
68
68
  - object-history.gemspec
69
69
  - spec/object-history_spec.rb
70
70
  - spec/spec_helper.rb
71
+ - spec/support/accessor.rb
72
+ - spec/support/post.rb
71
73
  - spec/support/track_object.rb
72
74
  has_rdoc: true
73
75
  homepage: http://github.com/LTe/object-history
@@ -85,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
87
  version: '0'
86
88
  segments:
87
89
  - 0
88
- hash: -3708414665896704862
90
+ hash: 2922439694190282095
89
91
  required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  none: false
91
93
  requirements: