chronicles 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+
3
+ describe Chronicles::Methods do
4
+
5
+ before do
6
+ class Test
7
+ attr_reader :chronicles, :start_chronicles, :stop_chronicles
8
+ attr_reader :foo, :bar, :baz
9
+ protected :bar
10
+ private :baz
11
+ end
12
+ end
13
+ let(:object) { Test.new }
14
+ after { Object.send :remove_const, :Test }
15
+
16
+ subject { described_class.new(object) }
17
+
18
+ describe ".new" do
19
+
20
+ it "creates an array" do
21
+ expect(subject).to be_kind_of Array
22
+ end
23
+
24
+ context "by default" do
25
+
26
+ it { is_expected.to match_array %i(foo bar baz) }
27
+
28
+ end # context
29
+
30
+ context "public: false" do
31
+
32
+ subject { described_class.new object, public: false }
33
+ it { is_expected.to match_array %i(bar baz) }
34
+
35
+ end # context
36
+
37
+ context "protected: false" do
38
+
39
+ subject { described_class.new object, protected: false }
40
+ it { is_expected.to match_array %i(foo baz) }
41
+
42
+ end # context
43
+
44
+ context "private: false" do
45
+
46
+ subject { described_class.new object, private: false }
47
+ it { is_expected.to match_array %i(foo bar) }
48
+
49
+ end # context
50
+
51
+ context "except: ['foo', 'bar']" do
52
+
53
+ subject { described_class.new object, except: %w(foo bar) }
54
+ it { is_expected.to match_array %i(baz) }
55
+
56
+ end # context
57
+
58
+ context "except: 'foo'" do
59
+
60
+ subject { described_class.new object, except: "foo" }
61
+ it { is_expected.to match_array %i(bar baz) }
62
+
63
+ end # context
64
+
65
+ context "only: ['foo', 'bar']" do
66
+
67
+ subject { described_class.new object, only: %w(foo bar) }
68
+ it { is_expected.to match_array %i(foo bar) }
69
+
70
+ end # context
71
+
72
+ context "only: 'foo'" do
73
+
74
+ subject { described_class.new object, only: "foo" }
75
+ it { is_expected.to match_array %i(foo) }
76
+
77
+ end # context
78
+
79
+ context "only: %w(foo baz), private: false" do
80
+
81
+ subject { described_class.new object, only: %w(foo baz), private: false }
82
+ it { is_expected.to match_array %i(foo) }
83
+
84
+ end # context
85
+
86
+ end # describe .new
87
+
88
+ end # describe Chronicles::Methods
@@ -0,0 +1,143 @@
1
+ # encoding: utf-8
2
+
3
+ describe Chronicles::Updater do
4
+
5
+ let(:test_class) do
6
+ Class.new do
7
+ define_method(:chronicles) { @chronicles ||= [] }
8
+ define_method(:foo) { |arg = nil| arg || :foo }
9
+ define_method(:bar) { :bar }
10
+ define_method(:baz) { :baz }
11
+
12
+ protected :bar
13
+ private :baz
14
+ end
15
+ end
16
+
17
+ let(:object) { test_class.new }
18
+ let(:name) { :foo }
19
+ let(:code) { "chronicles << :foo" }
20
+ subject { described_class.new object, name, code }
21
+
22
+ describe ".new" do
23
+
24
+ end # describe .new
25
+
26
+ describe "#object" do
27
+
28
+ it "is initialized" do
29
+ expect(subject.object).to eq object
30
+ end
31
+
32
+ end # describe #object
33
+
34
+ describe "#name" do
35
+
36
+ it "is initialized" do
37
+ expect(subject.name).to eq name
38
+ end
39
+
40
+ end # describe #name
41
+
42
+ describe "#code" do
43
+
44
+ it "is initialized" do
45
+ expect(subject.code).to eq code
46
+ end
47
+
48
+ end # describe #code
49
+
50
+ describe "#type" do
51
+
52
+ context "for public method's #name" do
53
+
54
+ subject { described_class.new object, :foo }
55
+
56
+ it "returns 'public'" do
57
+ expect(subject.type).to eq "public"
58
+ end
59
+
60
+ end # context
61
+
62
+ context "for protected method's #name" do
63
+
64
+ subject { described_class.new object, :bar }
65
+
66
+ it "returns 'protected'" do
67
+ expect(subject.type).to eq "protected"
68
+ end
69
+
70
+ end # context
71
+
72
+ context "for private method's #name" do
73
+
74
+ subject { described_class.new object, :baz }
75
+
76
+ it "returns 'private'" do
77
+ expect(subject.type).to eq "private"
78
+ end
79
+
80
+ end # context
81
+
82
+ end # describe #type
83
+
84
+ describe "#klass" do
85
+
86
+ it "returns #object's singleton class" do
87
+ expect(subject.klass).to eq object.singleton_class
88
+ end
89
+
90
+ end # describe #klass
91
+
92
+ describe "#run" do
93
+
94
+ context "with existing code" do
95
+
96
+ it "invokes the original method" do
97
+ object.singleton_class.send(:define_method, :foo) { :bar }
98
+ expect { subject.run }.to change { object.foo }.from(:bar).to(:foo)
99
+ end
100
+
101
+ it "preserves the original method arguments" do
102
+ subject.run
103
+ expect(object.foo(:baz)).to eq :baz
104
+ end
105
+
106
+ it "prepends the original method with code" do
107
+ subject.run
108
+ expect { object.foo }.to change { object.chronicles }.from([]).to [:foo]
109
+ end
110
+
111
+ it "keeps the method public" do
112
+ subject.run
113
+ expect(object.public_methods).to include :foo
114
+ end
115
+
116
+ it "keeps the method protected" do
117
+ subject = described_class.new object, :bar
118
+ subject.run
119
+ expect(object.protected_methods).to include :bar
120
+ end
121
+
122
+ it "keeps the method private" do
123
+ subject = described_class.new object, :baz
124
+ subject.run
125
+ expect(object.private_methods).to include :baz
126
+ end
127
+
128
+ end # context
129
+
130
+ context "with empty code" do
131
+
132
+ before { allow(subject).to receive(:code) }
133
+
134
+ it "restores the original method" do
135
+ object.singleton_class.send(:define_method, :foo) { :bar }
136
+ expect { subject.run }.to change { object.foo }.from(:bar).to(:foo)
137
+ end
138
+
139
+ end # context
140
+
141
+ end # describe #run
142
+
143
+ end # describe Chronicles::Updater
@@ -0,0 +1,197 @@
1
+ # encoding: utf-8
2
+
3
+ describe Chronicles do
4
+
5
+ let(:test_class) do
6
+ Class.new do
7
+ include Chronicles
8
+
9
+ attr_reader :foo
10
+
11
+ protected
12
+
13
+ attr_reader :bar
14
+
15
+ private
16
+
17
+ attr_reader :baz
18
+ end
19
+ end
20
+
21
+ subject { test_class.new }
22
+
23
+ describe "#chronicles" do
24
+
25
+ it "returns an empty array" do
26
+ expect(subject.chronicles).to eq []
27
+ end
28
+
29
+ end # describe #chronicles
30
+
31
+ describe "#start_chronicles" do
32
+
33
+ context "by default" do
34
+
35
+ before do
36
+ subject.start_chronicles
37
+ %i(foo bar baz foo).each(&subject.method(:send))
38
+ end
39
+
40
+ it "starts looking for all methods" do
41
+ expect(subject.chronicles).to eq %i(foo bar baz foo)
42
+ end
43
+
44
+ end # context
45
+
46
+ context "public: false" do
47
+
48
+ before do
49
+ subject.start_chronicles public: false
50
+ %i(foo bar baz foo).each(&subject.method(:send))
51
+ end
52
+
53
+ it "starts looking for proper methods" do
54
+ expect(subject.chronicles).to eq %i(bar baz)
55
+ end
56
+
57
+ end # context
58
+
59
+ context "protected: false" do
60
+
61
+ before do
62
+ subject.start_chronicles protected: false
63
+ %i(foo bar baz foo).each(&subject.method(:send))
64
+ end
65
+
66
+ it "starts looking for proper methods" do
67
+ expect(subject.chronicles).to eq %i(foo baz foo)
68
+ end
69
+
70
+ end # context
71
+
72
+ context "private: false" do
73
+
74
+ before do
75
+ subject.start_chronicles private: false
76
+ %i(foo bar baz foo).each(&subject.method(:send))
77
+ end
78
+
79
+ it "starts looking for proper methods" do
80
+ expect(subject.chronicles).to eq %i(foo bar foo)
81
+ end
82
+
83
+ end # context
84
+
85
+ context "except: foo" do
86
+
87
+ before do
88
+ subject.start_chronicles except: :foo
89
+ %i(foo bar baz foo).each(&subject.method(:send))
90
+ end
91
+
92
+ it "starts looking for proper methods" do
93
+ expect(subject.chronicles).to eq %i(bar baz)
94
+ end
95
+
96
+ end # context
97
+
98
+ context "only: foo" do
99
+
100
+ before do
101
+ subject.start_chronicles only: :foo
102
+ %i(foo bar baz foo).each(&subject.method(:send))
103
+ end
104
+
105
+ it "starts looking for proper methods" do
106
+ expect(subject.chronicles).to eq %i(foo foo)
107
+ end
108
+
109
+ end # context
110
+
111
+ end # describe #start_chronicles
112
+
113
+ describe "#stop_chronicles" do
114
+
115
+ before { subject.start_chronicles }
116
+
117
+ context "by default" do
118
+
119
+ before do
120
+ subject.stop_chronicles
121
+ %i(foo bar baz foo).each(&subject.method(:send))
122
+ end
123
+
124
+ it "stops looking for all methods" do
125
+ expect(subject.chronicles).to eq []
126
+ end
127
+
128
+ end # context
129
+
130
+ context "public: false" do
131
+
132
+ before do
133
+ subject.stop_chronicles public: false
134
+ %i(foo bar baz foo).each(&subject.method(:send))
135
+ end
136
+
137
+ it "stops looking for proper methods" do
138
+ expect(subject.chronicles).to eq %i(foo foo)
139
+ end
140
+
141
+ end # context
142
+
143
+ context "protected: false" do
144
+
145
+ before do
146
+ subject.stop_chronicles protected: false
147
+ %i(foo bar baz foo).each(&subject.method(:send))
148
+ end
149
+
150
+ it "stops looking for proper methods" do
151
+ expect(subject.chronicles).to eq %i(bar)
152
+ end
153
+
154
+ end # context
155
+
156
+ context "private: false" do
157
+
158
+ before do
159
+ subject.stop_chronicles private: false
160
+ %i(foo bar baz foo).each(&subject.method(:send))
161
+ end
162
+
163
+ it "stops looking for proper methods" do
164
+ expect(subject.chronicles).to eq %i(baz)
165
+ end
166
+
167
+ end # context
168
+
169
+ context "except: foo" do
170
+
171
+ before do
172
+ subject.stop_chronicles except: :foo
173
+ %i(foo bar baz foo).each(&subject.method(:send))
174
+ end
175
+
176
+ it "stops looking for proper methods" do
177
+ expect(subject.chronicles).to eq %i(foo foo)
178
+ end
179
+
180
+ end # context
181
+
182
+ context "only: foo" do
183
+
184
+ before do
185
+ subject.stop_chronicles only: :foo
186
+ %i(foo bar baz foo).each(&subject.method(:send))
187
+ end
188
+
189
+ it "stops looking for proper methods" do
190
+ expect(subject.chronicles).to eq %i(bar baz)
191
+ end
192
+
193
+ end # context
194
+
195
+ end # describe #stop_chronicles
196
+
197
+ end # describe Chronicles
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chronicles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kozin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hexx-rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ description:
28
+ email: andrew.kozin@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files:
32
+ - README.md
33
+ - LICENSE
34
+ files:
35
+ - ".coveralls.yml"
36
+ - ".gitignore"
37
+ - ".metrics"
38
+ - ".rspec"
39
+ - ".rubocop.yml"
40
+ - ".travis.yml"
41
+ - ".yardopts"
42
+ - Gemfile
43
+ - Guardfile
44
+ - LICENSE
45
+ - README.md
46
+ - Rakefile
47
+ - chronicles.gemspec
48
+ - config/metrics/STYLEGUIDE
49
+ - config/metrics/cane.yml
50
+ - config/metrics/churn.yml
51
+ - config/metrics/flay.yml
52
+ - config/metrics/metric_fu.yml
53
+ - config/metrics/reek.yml
54
+ - config/metrics/roodi.yml
55
+ - config/metrics/rubocop.yml
56
+ - config/metrics/saikuro.yml
57
+ - config/metrics/simplecov.yml
58
+ - config/metrics/yardstick.yml
59
+ - lib/chronicles.rb
60
+ - lib/chronicles/injector.rb
61
+ - lib/chronicles/methods.rb
62
+ - lib/chronicles/updater.rb
63
+ - lib/chronicles/version.rb
64
+ - spec/spec_helper.rb
65
+ - spec/tests/chronicles/injector_spec.rb
66
+ - spec/tests/chronicles/methods_spec.rb
67
+ - spec/tests/chronicles/updater_spec.rb
68
+ - spec/tests/chronicles_spec.rb
69
+ homepage: https://github.com/nepalez/chronicles
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.4.6
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Remembering object methods' call
93
+ test_files:
94
+ - spec/spec_helper.rb
95
+ - spec/tests/chronicles_spec.rb
96
+ - spec/tests/chronicles/updater_spec.rb
97
+ - spec/tests/chronicles/methods_spec.rb
98
+ - spec/tests/chronicles/injector_spec.rb
99
+ has_rdoc: