after_do 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a27fee536c317e5ba1edbfe81e495dccad4f1fc
4
- data.tar.gz: d0c51288921b665794ec7b89130d3b27584eef36
3
+ metadata.gz: 8a511da98cd0406b771b511abda97039ba62ed9e
4
+ data.tar.gz: 7d8fdb3c67e82a5d88cc1860257c260b5f302cf9
5
5
  SHA512:
6
- metadata.gz: fd71a09544a38876a753c5f24cc01fb5e607152167d061f4616504645b9867952ff4b719d8b1ae9f3f5ce428a9d80da74612f3c3d9b2e9d86aa275cd7edb8bec
7
- data.tar.gz: f8a079648a8b52de280ccd31a8d7b117eac59e862614ea34beafd05a82e12406bcfa62de2ba393b92b65c6fe86c4062942a6c396914120b4a138d496996cc09d
6
+ metadata.gz: 4bf5a61e4f96913d67dd4b748f4459dd77f38f0f901a5c2194995e4c4b146e5ecef90a54e34b46a37d19f100e5fca198b152b8be47b1ecd49dd34cf728f7196a
7
+ data.tar.gz: 1db2f852508993f9aab51d23bf9300721050a42d4097c69601da50c5266fc1cd445f4cc9037993dd61d37fbbed3a7cf3eec8d17bf554b9c7d09b254f8eca893c
@@ -1 +1 @@
1
- ruby-2.0.0-p247
1
+ ruby-2.0.0-p353
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - rbx-19mode
3
+ - rbx-2.2.1
4
4
  - jruby-19mode
5
5
  - 1.9.3
6
6
  - 2.0
data/Gemfile CHANGED
@@ -3,9 +3,14 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in after_do.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'rubysl', platform: :rbx
7
+ gem 'rubinius-coverage', platform: :rbx
8
+ gem 'json', platform: :rbx
9
+
6
10
  gem 'bundler', '~> 1.3'
7
11
  gem 'rake'
8
12
  gem 'rspec'
9
13
  gem 'guard-rspec'
10
14
  gem 'simplecov'
11
- gem 'coveralls'
15
+ gem 'coveralls'
16
+ gem 'rdoc'
data/README.md CHANGED
@@ -1,15 +1,17 @@
1
- # AfterDo [![Gem Version](https://badge.fury.io/rb/after_do.png)](http://badge.fury.io/rb/after_do)[![Build Status](https://travis-ci.org/PragTob/after_do.png?branch=master)](https://travis-ci.org/PragTob/after_do)[![Code Climate](https://codeclimate.com/github/PragTob/after_do.png)](https://codeclimate.com/github/PragTob/after_do)[![Coverage Status](https://coveralls.io/repos/PragTob/after_do/badge.png)](https://coveralls.io/r/PragTob/after_do)
1
+ # after_do [![Gem Version](https://badge.fury.io/rb/after_do.png)](http://badge.fury.io/rb/after_do)[![Build Status](https://travis-ci.org/PragTob/after_do.png?branch=master)](https://travis-ci.org/PragTob/after_do)[![Code Climate](https://codeclimate.com/github/PragTob/after_do.png)](https://codeclimate.com/github/PragTob/after_do)[![Coverage Status](https://coveralls.io/repos/PragTob/after_do/badge.png)](https://coveralls.io/r/PragTob/after_do)
2
2
 
3
- AfterDo is simple gem, that allows you to execute a specified block after specified method of a class are called. If the class extends `AfterDo` you can simply do this by
3
+ after_do is simple gem, that allows you to execute some blocks (callbacks) after specific method of a class are called. If the class extends `AfterDo` you can simply do this by
4
4
 
5
5
  ```
6
6
  MyClass.after :some_method do whatever_you_want end
7
7
  ```
8
8
 
9
- Why would you want to do this? Well to fight cross-cutting concerns such as logging. E.g. there are concerns in an applications that apply to multiple objects (e.g. they cross-cut). A popular example is logging - you might want to log multiple actions but logging is not the primary concern of the class in question. With logging you litter all your code with logging statements - that concern is spread over many files. With AfterDo you could put all the logging in one file. Other use cases include gathering business statistics or redrawing timing of elements. Personally I extracted this gem from a project where I wanted to decouple my domain objects from the way they are saved (for fun and profit!).
9
+ Why would you want to do this? Well to fight cross-cutting concerns such as logging. E.g. there are concerns in an applications that apply to multiple objects (e.g. they cross-cut). A popular example is logging - you might want to log multiple actions but logging is not the primary concern of the class in question. With logging you litter all your code with logging statements - that concern is spread over many files. With after_do you could put all the logging in one file. Other use cases include gathering business statistics or redrawing timing of elements. Personally I extracted this gem from a project where I wanted to decouple my domain objects from the way they are saved (for fun and profit!).
10
10
  This should generally not be done to alter behavior of the class and its instances - this makes programs more confusing rather than easier to understand.
11
11
 
12
- AfterDo has no external runtime dependencies and the code is around 120 lines of code (blank lines included) with lots of small methods. So simplecov reports there are not even 70 relevant lines.
12
+ The idea for this is inspired by Aspect Oriented Programming - e.g. do something when specific methods are executed. However I doubt that this formally fulfills the lingo (join points, aspects, advice...)
13
+
14
+ after_do has no external runtime dependencies and the code is around 160 lines of code (blank lines and documentation included) with lots of small methods. So simplecov reports there are a little above 70 relevant lines code (it ignores blank lines, docs etc.).
13
15
 
14
16
  ## Installation
15
17
 
@@ -27,18 +29,18 @@ Or install it yourself as:
27
29
 
28
30
  ## Usage
29
31
 
30
- This section is dedicated to show of the general usage and effects of AfterDo. You can also check out the samples directory for some samples or the specs in the spec folder.
32
+ This section is dedicated to show of the general usage and effects of after_do. You can also check out the samples directory for some samples or the specs in the spec folder.
31
33
 
32
34
  ### General usage
33
35
 
34
- In order to use AfterDo the class/module you want to use it with first has to extend the `AfterDo` module. You can do this right in the class definition or afterwards like this: `MyClass.extend AfterDo`.
36
+ In order to use after_do the class/module you want to use it with first has to extend the `AfterDo` module. You can do this right in the class definition or afterwards like this: `MyClass.extend AfterDo`.
35
37
  With this setup you can add a callback to `method` like this:
36
38
 
37
39
  ```ruby
38
40
  MyClass.after :method do magic end
39
41
  ```
40
42
 
41
- With AfterDo you can do simple things like printing something out every time a method is called as in this example:
43
+ With after_do you can do simple things like printing something out every time a method is called as in this example:
42
44
 
43
45
  ```ruby
44
46
  class Dog
@@ -66,7 +68,7 @@ dog2.bark
66
68
 
67
69
  ### How does it work?
68
70
 
69
- When you attach a callback to a method with AfterDo what it basically does is it creates a copy of that method and then redefines the method to basically look like this (pseudo code):
71
+ When you attach a callback to a method with after_do what it basically does is it creates a copy of that method and then redefines the method to basically look like this (pseudo code):
70
72
 
71
73
  ```ruby
72
74
  execute_before_callbacks
@@ -79,7 +81,7 @@ To do this some helper methods are defined in the AfterDo module. As classes hav
79
81
 
80
82
  ### Getting a hold of the method arguments and the object
81
83
 
82
- With AfterDo both the arguments to the method you are attaching the callback to and the object for which the callback is executed are passed into the callback block.
84
+ With after_do both the arguments to the method you are attaching the callback to and the object for which the callback is executed are passed into the callback block.
83
85
 
84
86
  So if you have a method that takes two arguments you can get those like this:
85
87
 
@@ -139,7 +141,7 @@ e.two 'one', 'two'
139
141
 
140
142
  ### Attaching a callback to multiple methods
141
143
 
142
- In AfterDo you can attach a callback to multiple methods by just listing them:
144
+ In after_do you can attach a callback to multiple methods by just listing them:
143
145
 
144
146
  ```ruby
145
147
  SomeClass.after :one_method, :another_method do something end
@@ -177,7 +179,7 @@ The callbacks are executed in the order in which they were added.
177
179
 
178
180
  ### Working with inheritance
179
181
 
180
- AfterDo also works with inheritance. E.g. if you attach a callback to a method in a super class and that method is called in a sub class the callback is still executed.
182
+ after_do also works with inheritance. E.g. if you attach a callback to a method in a super class and that method is called in a sub class the callback is still executed.
181
183
 
182
184
  See this sample:
183
185
 
@@ -198,6 +200,59 @@ b = B.new
198
200
  b.a #prints out: a was called
199
201
  ```
200
202
 
203
+ ### Usage from within a class
204
+
205
+ If you got some repetitive tasks, that needs to be done after/before a lot of methods in a class then you can also use after_do for this. This works a bit like `before_action`/`after_action` which you might know from Ruby on Rails.
206
+
207
+ E.g. like this:
208
+
209
+ ```
210
+ class MyClass
211
+ extend AfterDo
212
+
213
+ # ...
214
+
215
+ after :my_method, :method2, :m3 do |args*, instance| instance.a_method end
216
+ end
217
+ ```
218
+
219
+ See this example:
220
+
221
+ ```ruby
222
+ class Team
223
+ extend AfterDo
224
+
225
+ def add_member(member)
226
+ # ...
227
+ end
228
+
229
+ def remove_member(member)
230
+ # ..
231
+ end
232
+
233
+ def change_name(new_name)
234
+ # ..
235
+ end
236
+
237
+ def save
238
+ # ..
239
+ puts 'saving...'
240
+ end
241
+
242
+ after :add_member, :remove_member, :change_name do |*, team| team.save end
243
+ end
244
+
245
+ team = Team.new
246
+ team.add_member 'Maren'
247
+ team.change_name 'Ruby Cherries'
248
+ team.remove_member 'Guilia'
249
+
250
+ # Output is:
251
+ # saving...
252
+ # saving...
253
+ # saving...
254
+ ```
255
+
201
256
  ### Removing callbacks
202
257
 
203
258
  You can remove all callbacks you added to a class by doing:
@@ -206,9 +261,11 @@ You can remove all callbacks you added to a class by doing:
206
261
  MyClass.remove_all_callbacks
207
262
  ```
208
263
 
264
+ Note that this not remove callbacks defined in super classes.
265
+
209
266
  ### Errors
210
267
 
211
- There are some custom errors that AfterDo throws. When you try to add a callback to a method which that class does not understand it will throw `AfterDo::NonExistingMethodError`.
268
+ There are some custom errors that after_do throws. When you try to add a callback to a method which that class does not understand it will throw `AfterDo::NonExistingMethodError`.
212
269
 
213
270
  When an error occurs during one of the callbacks that are attached to a method it will throw `AfterDo::CallbackError` with information about the original error and where the block/callback causing this error was defined to help pinpoint the error.
214
271
 
@@ -245,7 +302,7 @@ m.value = 'new value'
245
302
 
246
303
  ### Method granularity
247
304
 
248
- AfterDo works on the granularity of methods. That means that you can only attach callbacks to methods. This is no problem however, since if it's your code you can always define new methods. E.g. you want to attach callbacks to the end of some operation that happens in the middle of a method just define a new method for that piece of code.
305
+ after_do works on the granularity of methods. That means that you can only attach callbacks to methods. This is no problem however, since if it's your code you can always define new methods. E.g. you want to attach callbacks to the end of some operation that happens in the middle of a method just define a new method for that piece of code.
249
306
 
250
307
  I sometimes do this for evaluating the block, as I want to do something when that block finished evaluating so I define a method `eval_block` wherein I just evaluate the block.
251
308
 
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = AfterDo::VERSION
9
9
  spec.authors = ["Tobias Pfeiffer"]
10
10
  spec.email = ["pragtob@gmail.com"]
11
- spec.description = %q{after_do is a gem that let's you execute a block of your choice after a specific method was called on a class.}
12
- spec.summary = %q{after_do allows you to do simple after hooks on methods}
11
+ spec.description = %q{after_do is a gem that let's you execute a block of your choice after or before a specific method is called on a class. This is inspired by Aspect Oriented Programming and should be used to fight cross-cutting concerns.}
12
+ spec.summary = %q{after_do allows you to add simple after/before hooks to methods}
13
13
  spec.homepage = "https://github.com/PragTob/after_do"
14
14
  spec.license = "MIT"
15
15
 
@@ -1,36 +1,67 @@
1
+ # The after_do library to add callbacks to methods in Ruby. Before using this
2
+ # with any class, that class has to extend the AfterDo module first e.g.
3
+ # MyClass.extend AfterDo
4
+ # MyClass.after :some_method do awesome_stuff end
5
+ #
6
+ # More information at the github page: https://github.com/PragTob/after_do
1
7
  module AfterDo
8
+ # The prefix for the copies of the original methods made by after_do
2
9
  ALIAS_PREFIX = '__after_do_orig_'
3
10
 
11
+ # ::nodoc::
4
12
  def self.extended(klazz)
5
13
  klazz.send(:include, AfterDo::Instance)
6
14
  klazz.send(:extend, AfterDo::Class)
7
15
  end
8
16
 
17
+ # Raised when trying to attach a callback to a non existing method
9
18
  class NonExistingMethodError < StandardError ; end
19
+
20
+ # Raised when an error occurs in one of the callbacks of a method. Provides
21
+ # additional information as to for which method and where the block was
22
+ # defined.
10
23
  class CallbackError < StandardError ; end
11
24
 
25
+ # These methods become available on a class after the AfterDo module was
26
+ # extended (e.g. extending the AfterDo module results in extending
27
+ # AfterDo::Class)
12
28
  module Class
13
-
14
- def _after_do_callbacks
15
- @_after_do_callbacks || _after_do_basic_hash
16
- end
17
-
29
+ # A method to add a callback to a method or a list of methods to be executed
30
+ # after the original method was executed. E.g.:
31
+ # MyClass.after :some_method do awesome_stuff end
32
+ # It can only take a list of methods after which a block should be executed:
33
+ # MyClass.after :method1, :method2, :method3 do puts 'jay!' end
34
+ # The list might also be an Array.
18
35
  def after(*methods, &block)
19
36
  _after_do_define_callback(:after, methods, block)
20
37
  end
21
38
 
39
+ # This method works much like .after - just that the blocks are executed
40
+ # before the method is called.
22
41
  def before(*methods, &block)
23
42
  _after_do_define_callback(:before, methods, block)
24
43
  end
25
44
 
45
+ # Removes all callbacks attach to methods in this class.
26
46
  def remove_all_callbacks
27
- @_after_do_callbacks = _after_do_basic_hash if @_after_do_callbacks
47
+ @_after_do_callbacks = _after_do_basic_hash
48
+ end
49
+
50
+ # It's not really meant for you to mess with - therefore the
51
+ # _after_do prefix (it's an internal structure but needs to be accessible)
52
+ # from instances.
53
+ # However it's an accessor for the after_do callbacks associated with this
54
+ # class. This is a hash of the following form:
55
+ # {after: {method: [callback1, callback2, ...]},
56
+ # before: {method: [callback1, callback2, ...]}
57
+ def _after_do_callbacks
58
+ @_after_do_callbacks || _after_do_basic_hash
28
59
  end
29
60
 
30
61
  private
31
62
  def _after_do_define_callback(type, methods, block)
32
63
  @_after_do_callbacks ||= _after_do_basic_hash
33
- methods.flatten! #in case someone used an Array
64
+ methods = methods.flatten #in case someone used an Array
34
65
  _after_do_raise_no_method_specified(type) if methods.empty?
35
66
  methods.each do |method|
36
67
  _after_do_add_callback_to_method(type, method, block)
@@ -98,7 +129,11 @@ module AfterDo
98
129
  end
99
130
  end
100
131
 
132
+ # These methods become available on instances of a class after extending the
133
+ # AfterDo module. They are just needed for the callback lookup/execution and
134
+ # all of them are private - you should not call them.
101
135
  module Instance
136
+ private
102
137
  def _after_do_execute_callbacks(type, method, *args)
103
138
  callback_classes = self.class.ancestors.select do |klazz|
104
139
  _after_do_has_callback_for?(klazz, type, method)
@@ -123,4 +158,4 @@ module AfterDo
123
158
  end
124
159
  end
125
160
  end
126
- end
161
+ end
@@ -1,3 +1,4 @@
1
1
  module AfterDo
2
- VERSION = "0.2.2"
2
+ # ::nodoc::
3
+ VERSION = "0.2.3"
3
4
  end
@@ -20,10 +20,15 @@ class Team
20
20
  puts 'saving...'
21
21
  end
22
22
 
23
- after :add_member, :remove_member, :change_name do |*args, team| team.save end
23
+ after :add_member, :remove_member, :change_name do |*, team| team.save end
24
24
  end
25
25
 
26
26
  team = Team.new
27
27
  team.add_member 'Maren'
28
28
  team.change_name 'Ruby Cherries'
29
29
  team.remove_member 'Guilia'
30
+
31
+ # Output is:
32
+ # saving...
33
+ # saving...
34
+ # saving...
@@ -27,13 +27,17 @@ describe AfterDo do
27
27
  end
28
28
 
29
29
  shared_examples_for 'calling callbacks' do |callback_adder|
30
- it 'responds to before/after' do
31
- @dummy_class.should respond_to callback_adder
30
+ it 'does not monkey patch Class' do
31
+ expect(Class.new).not_to respond_to callback_adder
32
+ end
33
+
34
+ it 'responds to before/after extended with AfterDo' do
35
+ expect(@dummy_class).to respond_to callback_adder
32
36
  end
33
37
 
34
38
  def simple_callback_called_test(callback_adder)
35
39
  @dummy_class.send callback_adder, :zero do mockie.call_method end
36
- mockie.should_receive :call_method
40
+ expect(mockie).to receive :call_method
37
41
  dummy_instance.zero
38
42
  end
39
43
 
@@ -50,21 +54,21 @@ describe AfterDo do
50
54
  before_return_value = dummy_instance.zero
51
55
  @dummy_class.send callback_adder, :zero do 42 end
52
56
  after_return_value = dummy_instance.zero
53
- after_return_value.should eq before_return_value
57
+ expect(after_return_value).to eq before_return_value
54
58
  end
55
59
 
56
60
  it 'marks the copied method as private' do
57
61
  @dummy_class.send callback_adder, :zero do end
58
62
  copied_method_name = (AfterDo::ALIAS_PREFIX + 'zero').to_sym
59
- dummy_instance.respond_to?(copied_method_name).should be_false
63
+ expect(dummy_instance).not_to respond_to copied_method_name
60
64
  end
61
65
 
62
66
  it 'can add multiple call backs' do
63
- mockie.should_receive :call_method
67
+ expect(mockie).to receive :call_method
64
68
  mock2 = double
65
- mock2.should_receive :call_another_method
69
+ expect(mock2).to receive :call_another_method
66
70
  mock3 = double
67
- mock3.should_receive :bla
71
+ expect(mock3).to receive :bla
68
72
  @dummy_class.send callback_adder, :zero do mockie.call_method end
69
73
  @dummy_class.send callback_adder, :zero do mock2.call_another_method end
70
74
  @dummy_class.send callback_adder, :zero do mock3.bla end
@@ -73,14 +77,14 @@ describe AfterDo do
73
77
 
74
78
  describe 'removing callbacks' do
75
79
  it 'can remove all callbacks' do
76
- mockie.should_not_receive :call_method
80
+ expect(mockie).not_to receive :call_method
77
81
  @dummy_class.send callback_adder, :zero do mockie.call_method end
78
82
  @dummy_class.remove_all_callbacks
79
83
  dummy_instance.zero
80
84
  end
81
85
 
82
86
  it 'does not crash the addition of new callbacks afterwards' do
83
- mockie.should_receive :call_method
87
+ expect(mockie).to receive :call_method
84
88
  @dummy_class.send callback_adder, :zero do mockie.call_method end
85
89
  @dummy_class.remove_all_callbacks
86
90
  @dummy_class.send callback_adder, :zero do mockie.call_method end
@@ -141,7 +145,7 @@ describe AfterDo do
141
145
  describe 'with parameters' do
142
146
 
143
147
  before :each do
144
- mockie.should_receive :call_method
148
+ expect(mockie).to receive :call_method
145
149
  end
146
150
 
147
151
  it 'can handle methods with a parameter' do
@@ -157,13 +161,13 @@ describe AfterDo do
157
161
 
158
162
  describe 'with parameters for the given block' do
159
163
  it 'can handle one block parameter' do
160
- mockie.should_receive(:call_method).with(5)
164
+ expect(mockie).to receive(:call_method).with(5)
161
165
  @dummy_class.send callback_adder, :one do |i| mockie.call_method i end
162
166
  dummy_instance.one 5
163
167
  end
164
168
 
165
169
  it 'can handle two block parameters' do
166
- mockie.should_receive(:call_method).with(5, 8)
170
+ expect(mockie).to receive(:call_method).with(5, 8)
167
171
  @dummy_class.send callback_adder, :two do |i, j| mockie.call_method i, j end
168
172
  dummy_instance.two 5, 8
169
173
  end
@@ -177,34 +181,42 @@ describe AfterDo do
177
181
  end
178
182
 
179
183
  it 'can take multiple method names as arguments' do
180
- mockie.should_receive(:call_method).exactly(3).times
181
- @dummy_class.send callback_adder, :zero, :one, :two do mockie.call_method end
184
+ expect(mockie).to receive(:call_method).exactly(3).times
185
+ @dummy_class.send callback_adder, :zero, :one, :two do
186
+ mockie.call_method
187
+ end
182
188
  call_all_3_methods
183
189
  end
184
190
 
185
191
  it 'can get the methods as an Array' do
186
- mockie.should_receive(:call_method).exactly(3).times
187
- @dummy_class.send callback_adder, [:zero, :one, :two] do mockie.call_method end
192
+ expect(mockie).to receive(:call_method).exactly(3).times
193
+ @dummy_class.send callback_adder, [:zero, :one, :two] do
194
+ mockie.call_method
195
+ end
188
196
  call_all_3_methods
189
197
  end
190
198
 
191
199
  it 'raises an error when no method is specified' do
192
200
  expect do
193
- @dummy_class.send callback_adder do mockie.call_method end
201
+ @dummy_class.send callback_adder do
202
+ mockie.call_method
203
+ end
194
204
  end.to raise_error ArgumentError
195
205
  end
196
206
  end
197
207
 
198
208
  describe 'it can get a hold of self, if needbe' do
199
209
  it 'works for a method without arguments' do
200
- mockie.should_receive(:call_method).with(dummy_instance)
201
- @dummy_class.send callback_adder, :zero do |object| mockie.call_method(object) end
210
+ expect(mockie).to receive(:call_method).with(dummy_instance)
211
+ @dummy_class.send callback_adder, :zero do |object|
212
+ mockie.call_method(object)
213
+ end
202
214
  dummy_instance.zero
203
215
  end
204
216
 
205
217
  it 'works for a method with 2 arguments' do
206
- mockie.should_receive(:call_method).with(1, 2, dummy_instance)
207
- @dummy_class.send callback_adder, :two do |first, second, object|
218
+ expect(mockie).to receive(:call_method).with(1, 2, dummy_instance)
219
+ @dummy_class.send callback_adder, :two do |first, second, object|
208
220
  mockie.call_method(first, second, object)
209
221
  end
210
222
  dummy_instance.two 1, 2
@@ -223,7 +235,7 @@ describe AfterDo do
223
235
  end
224
236
 
225
237
  it 'class knows about the after/before method' do
226
- @inherited_class.should respond_to callback_adder
238
+ expect(@inherited_class).to respond_to callback_adder
227
239
  end
228
240
 
229
241
  describe 'callback on parent class' do
@@ -232,18 +244,18 @@ describe AfterDo do
232
244
  end
233
245
 
234
246
  it 'works when we have a callback on the parent class' do
235
- mockie.should_receive :call
247
+ expect(mockie).to receive :call
236
248
  inherited_instance.zero
237
249
  end
238
250
 
239
251
  it 'remove_callbacks does not remove the callbacks on parent class' do
240
- mockie.should_receive :call
252
+ expect(mockie).to receive :call
241
253
  @inherited_class.remove_all_callbacks
242
254
  inherited_instance.zero
243
255
  end
244
256
 
245
257
  it 'remove_callbacks on the parent does remove the callbacks' do
246
- mockie.should_not_receive :call
258
+ expect(mockie).not_to receive :call
247
259
  @dummy_class.remove_all_callbacks
248
260
  inherited_instance.zero
249
261
  end
@@ -263,18 +275,18 @@ describe AfterDo do
263
275
  end
264
276
 
265
277
  it 'calls the before callback' do
266
- callback.should_receive :before_call
278
+ expect(callback).to receive :before_call
267
279
  dummy_instance.zero
268
280
  end
269
281
 
270
282
  it 'calls the after callback' do
271
- callback.should_receive :after_call
283
+ expect(callback).to receive :after_call
272
284
  dummy_instance.zero
273
285
  end
274
286
 
275
287
  it 'receives the calls in the right order' do
276
- callback.should_receive(:before_call).ordered
277
- callback.should_receive(:after_call).ordered
288
+ expect(callback).to receive(:before_call).ordered
289
+ expect(callback).to receive(:after_call).ordered
278
290
  dummy_instance.zero
279
291
  end
280
292
  end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: after_do
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Pfeiffer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-15 00:00:00.000000000 Z
11
+ date: 2013-12-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: after_do is a gem that let's you execute a block of your choice after
14
- a specific method was called on a class.
14
+ or before a specific method is called on a class. This is inspired by Aspect Oriented
15
+ Programming and should be used to fight cross-cutting concerns.
15
16
  email:
16
17
  - pragtob@gmail.com
17
18
  executables: []
@@ -58,10 +59,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
59
  version: '0'
59
60
  requirements: []
60
61
  rubyforge_project:
61
- rubygems_version: 2.0.6
62
+ rubygems_version: 2.0.14
62
63
  signing_key:
63
64
  specification_version: 4
64
- summary: after_do allows you to do simple after hooks on methods
65
+ summary: after_do allows you to add simple after/before hooks to methods
65
66
  test_files:
66
67
  - spec/after_do_spec.rb
67
68
  - spec/spec_helper.rb