shoulda-callback-matchers 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Nzg1MDgzYWVlNzcxMGExNmVkMjlmNjA0YTkxOTY0MTQ5YzZlYTQwNQ==
5
- data.tar.gz: !binary |-
6
- YjVkYjUzNWMxZDZjYWQ1NDFhZmQ4ZjQ2ZDczNmVkZDcxN2Q4ZGYyZA==
2
+ SHA1:
3
+ metadata.gz: 72c47c82596d5cef0a75c5a359e9f3a2b138f875
4
+ data.tar.gz: 484f42b9d2cad246fb71748ebfff3ad73977e43e
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- OWMwMWU1OTFjYzM4MTJiYmViZjYxZDc1MjQ3YzNlMmRmNzJmZTExN2Q1YzQ1
10
- ODc1NDc5MTg2YjdmYjVhNjQwZTNkYmRhNjk4YTBjNWMwNzk5MzExMmU1MTMw
11
- ODEyYWY3ODY5ZThlZGM0MTgxN2VmODRlNjljZjY2ZTQyMjZmNTI=
12
- data.tar.gz: !binary |-
13
- NzQ1NjZjM2NmMDY3ZWQ3YjAwNDcxNDExNmY0Y2ZjYjMzMjNkNTc1NzU2M2Qz
14
- NWRkZDhlMTAyMjlkYTJhN2FmNmI5NWFkZjBiNGI1MzYxOWExZjlkZmYyMmY2
15
- NTA4NTYzYzkxOWRhMzRkMTU5YzkxZTM0NWQ5OGI3NjFkMGE4NzY=
6
+ metadata.gz: e33037b19ace299416fc07695e994aae498672f70864113ad9e8fdb84f22855f285568690aa1831c9ec6d3de14ef037ec9ad43f78eace98de8fe507f1cf99b59
7
+ data.tar.gz: a6dd677fbdd5778b99b64d01ecb29b8699f6e676c17f38f9a653ae709ab4c3c9465149081b2a37a28370f83d60f10c4ec1c861d4fe8c7817709d77d1548c9813
Binary file
data/Appraisals CHANGED
@@ -2,4 +2,22 @@ appraise '4.0' do
2
2
  gem 'rails', '~>4.0'
3
3
  gem 'jquery-rails'
4
4
  gem 'sass-rails'
5
+ end
6
+
7
+ appraise '3.2' do
8
+ gem 'rails', '~>3.2'
9
+ gem 'jquery-rails'
10
+ gem 'sass-rails'
11
+ end
12
+
13
+ appraise '3.1' do
14
+ gem 'rails', '~>3.2'
15
+ gem 'jquery-rails'
16
+ gem 'sass-rails'
17
+ end
18
+
19
+ appraise '3.0' do
20
+ gem 'rails', '~>3.2'
21
+ gem 'jquery-rails'
22
+ gem 'sass-rails'
5
23
  end
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
- Matchers to test before, after and around hooks:
1
+ Matchers to test before, after and around hooks(currently supports gsymbol and object callbacks):
2
2
 
3
+ Symbol Callbacks:
4
+
3
5
  describe Post do
4
6
  it { should callback(:count_comments).before(:save) }
5
7
  it { should callback(:post_to_twitter).after(:create) }
@@ -12,21 +14,39 @@ Matchers to test before, after and around hooks:
12
14
  it { should callback(:make_email_validation_ready!).before(:validation).on(:create) }
13
15
  it { should callback(:update_user_count).before(:destroy) }
14
16
  end
15
-
16
- Be aware that this tests for the method call and not the method itself. It makes testing via triggering the callback events (validation, save) unnecessary, but you should still test the called procedure seperately.
17
17
 
18
- In Rails 4 and Bundler, add the following to your Gemfile:
18
+ Object Callbacks:
19
19
 
20
- group :test do
21
- gem "shoulda-callback-matchers", ">=0.3.0"
20
+ class CallbackClass
21
+ def before_save{}
22
+ def after_create{}
23
+ def before_validation{}
24
+ def after_find{}
22
25
  end
26
+
27
+ describe Post do
28
+ it { should callback(CallbackClass).before(:save) }
29
+ it { should callback(CallbackClass).after(:create) }
30
+ it { should callback(CallbackClass).before(:validation) }
31
+ it { should callback(CallbackClass).after(:find) }
32
+ end
33
+
34
+ describe User do
35
+ it { should_not callback(CallbackClass).before(:validation).on(:update) }
36
+ it { should callback(CallbackClass).before(:validation).on(:create) }
37
+ it { should callback(CallbackClass).before(:destroy) }
38
+ end
39
+
40
+ Be aware that this tests for the method call and not the method itself. It makes testing via triggering the callback events (validation, save) unnecessary, but you should still test the called procedure seperately.
23
41
 
24
- In Rails 3 and Bundler, add version 0.0.2 to your Gemfile:
42
+ In Rails 3 or 4 and Bundler, add the following to your Gemfile:
25
43
 
26
44
  group :test do
27
- gem "shoulda-callback-matchers", "=0.2.0"
45
+ gem "shoulda-callback-matchers", "~> 0.4"
28
46
  end
29
47
 
48
+ This gem uses semantic versioning, so you won't have incompability issues with patches.
49
+
30
50
  rspec-rails needs to be in the development group so that Rails generators work.
31
51
 
32
52
  group :development, :test do
@@ -37,9 +57,14 @@ Shoulda will automatically include matchers into the appropriate example groups.
37
57
 
38
58
  ## Credits
39
59
 
40
- This gem is maintained by me,
60
+ This gem is maintained by me and its contributors,
41
61
  Shoulda is maintained and funded by [thoughtbot](http://thoughtbot.com/community)
42
62
 
63
+ ## Contributors & Contributions
64
+ - @pvertenten
65
+
66
+ Let's make this gem useful, send me a PR if you've discovered an issue you'd like to fix!
67
+
43
68
  ## License
44
69
 
45
70
  Shoulda is Copyright © 2006-2012 thoughtbot, inc.
@@ -15,6 +15,7 @@ module Shoulda # :nodoc:
15
15
  # Examples:
16
16
  # it { should callback(:method).after(:create) }
17
17
  # it { should callback(:method).before(:validation).unless(:should_it_not?) }
18
+ # it { should callback(CallbackClass).before(:validation).unless(:should_it_not?) }
18
19
  #
19
20
  def callback(method)
20
21
  CallbackMatcher.new(method)
@@ -60,8 +61,9 @@ module Shoulda # :nodoc:
60
61
  false
61
62
  else
62
63
  callbacks = subject.send(:"_#{@lifecycle}_callbacks").dup
63
- callbacks = callbacks.select do |callback|
64
- callback.filter == @method &&
64
+ callbacks = callbacks.select do |callback|
65
+ subject.respond_to?(callback.filter) &&
66
+ is_callback?(subject, callback) &&
65
67
  callback.kind == @hook &&
66
68
  matches_conditions?(callback) &&
67
69
  matches_optional_lifecycle?(callback)
@@ -69,6 +71,21 @@ module Shoulda # :nodoc:
69
71
  callbacks.size > 0
70
72
  end
71
73
  end
74
+
75
+ def is_callback?(subject, callback)
76
+ is_callback_object?(subject, callback) || is_callback_symbol?(subject, callback)
77
+ end
78
+
79
+ def is_callback_symbol?(subject, callback)
80
+ callback.filter == @method
81
+ end
82
+
83
+ def is_callback_object?(subject, callback)
84
+ @method.kind_of?(Class) &&
85
+ callback.filter.match(/^_callback/) &&
86
+ subject.respond_to?("#{callback.filter}_object") &&
87
+ subject.send("#{callback.filter}_object").class == @method
88
+ end
72
89
 
73
90
  def failure_message
74
91
  @failure_message || "expected #{@method} to be listed as a callback #{@hook} #{@lifecycle}#{optional_lifecycle_phrase}#{condition_phrase}, but was not"
@@ -89,7 +106,7 @@ module Shoulda # :nodoc:
89
106
  end
90
107
 
91
108
  def matches_optional_lifecycle?(callback)
92
- !@optional_lifecycle || callback.options[:if].include?("[:#{@optional_lifecycle}].include? self.validation_context")
109
+ !@optional_lifecycle || callback.options[:if].include?(lifecycle_context_string)
93
110
  end
94
111
 
95
112
  def condition_phrase
@@ -99,6 +116,14 @@ module Shoulda # :nodoc:
99
116
  def optional_lifecycle_phrase
100
117
  " on #{@optional_lifecycle}" if @optional_lifecycle
101
118
  end
119
+
120
+ def lifecycle_context_string
121
+ if ActiveRecord::VERSION::MAJOR == 4
122
+ "[:#{@optional_lifecycle}].include? self.validation_context"
123
+ else
124
+ "self.validation_context == :#{@optional_lifecycle}"
125
+ end
126
+ end
102
127
 
103
128
  end
104
129
  end
@@ -1,7 +1,7 @@
1
1
  module Shoulda
2
2
  module Callback
3
3
  module Matchers
4
- VERSION = '0.3.3'.freeze
4
+ VERSION = '0.4.0'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -18,19 +18,19 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
  s.extensions = 'ext/mkrf_conf.rb'
20
20
 
21
- s.add_dependency('activesupport', '~> 4.0')
21
+ s.add_dependency('activesupport', '>= 3')
22
22
 
23
- s.add_development_dependency('appraisal', '~> 0.5.0')
23
+ s.add_development_dependency('appraisal', '~> 0.5')
24
24
  s.add_development_dependency('aruba')
25
- s.add_development_dependency('bourne', '~> 1.3.0')
26
- s.add_development_dependency('bundler', '>= 1.1.0')
27
- s.add_development_dependency('rails', '>= 3.0')
28
- s.add_development_dependency('rake', '~> 10.0.0')
29
- s.add_development_dependency('rspec-rails', '~> 2.12.0')
25
+ s.add_development_dependency('bourne', '~> 1.3')
26
+ s.add_development_dependency('bundler', '>= 1.1')
27
+ s.add_development_dependency('rails', '>= 3')
28
+ s.add_development_dependency('rake', '~> 10')
29
+ s.add_development_dependency('rspec-rails', '~> 2')
30
30
 
31
31
  if RUBY_ENGINE == 'rbx'
32
- s.add_development_dependency "rubysl", "~> 2.0"
33
- s.add_development_dependency "rubysl-test-unit", '~> 2.0'
32
+ s.add_development_dependency "rubysl", "~> 2"
33
+ s.add_development_dependency "rubysl-test-unit", '~> 2'
34
34
  s.add_development_dependency "racc", "~> 1.4"
35
35
  end
36
36
  end
@@ -4,10 +4,19 @@ describe Shoulda::Callback::Matchers::ActiveModel do
4
4
 
5
5
  context "invalid use" do
6
6
  before do
7
+ @callback_object_class = define_model(:callback) do
8
+ define_method("before_create"){}
9
+ define_method("after_save"){}
10
+ end
11
+ callback_object = @callback_object_class.new
7
12
  @model = define_model(:example, :attr => :string,
8
13
  :other => :integer) do
9
14
  before_create :dance!, :if => :evaluates_to_false!
10
15
  after_save :shake!, :unless => :evaluates_to_true!
16
+ before_create callback_object, :if => :evaluates_to_false!
17
+ after_save callback_object, :unless => :evaluates_to_true!
18
+ define_method(:shake!){}
19
+ define_method(:dance!){}
11
20
  end.new
12
21
  end
13
22
  it "should return a meaningful failure message when used without a defined lifecycle" do
@@ -22,16 +31,49 @@ describe Shoulda::Callback::Matchers::ActiveModel do
22
31
  matcher.failure_message.should == "The .on option is only valid for the validation lifecycle and cannot be used with create, use with .before(:validation) or .after(:validation)"
23
32
  matcher.negative_failure_message.should == "The .on option is only valid for the validation lifecycle and cannot be used with create, use with .before(:validation) or .after(:validation)"
24
33
  end
34
+ it "should return a meaningful failure message when used without a defined lifecycle" do
35
+ matcher = callback(@callback_object_class)
36
+ matcher.matches?(@model).should be_false
37
+ matcher.failure_message.should == "callback Callback can not be tested against an undefined lifecycle, use .before, .after or .around"
38
+ matcher.negative_failure_message.should == "callback Callback can not be tested against an undefined lifecycle, use .before, .after or .around"
39
+ end
40
+ it "should return a meaningful failure message when used with an optional lifecycle without the original lifecycle being validation" do
41
+ matcher = callback(@callback_object_class).after(:create).on(:save)
42
+ matcher.matches?(@model).should be_false
43
+ matcher.failure_message.should == "The .on option is only valid for the validation lifecycle and cannot be used with create, use with .before(:validation) or .after(:validation)"
44
+ matcher.negative_failure_message.should == "The .on option is only valid for the validation lifecycle and cannot be used with create, use with .before(:validation) or .after(:validation)"
45
+ end
25
46
  end
26
47
 
27
48
  [:save, :create, :update, :destroy].each do |lifecycle|
28
49
  context "on #{lifecycle}" do
29
50
  before do
51
+
52
+ @callback_object_class = define_model(:callback) do
53
+ define_method("before_#{lifecycle}"){}
54
+ define_method("after_#{lifecycle}"){}
55
+ define_method("around_#{lifecycle}"){}
56
+ end
57
+
58
+ callback_object = @callback_object_class.new
59
+
60
+ @callback_object_not_found_class = define_model(:callback_not_fount) do
61
+ define_method("before_#{lifecycle}"){}
62
+ define_method("after_#{lifecycle}"){}
63
+ define_method("around_#{lifecycle}"){}
64
+ end
65
+
30
66
  @model = define_model(:example, :attr => :string,
31
67
  :other => :integer) do
32
68
  send(:"before_#{lifecycle}", :dance!, :if => :evaluates_to_false!)
33
69
  send(:"after_#{lifecycle}", :shake!, :unless => :evaluates_to_true!)
34
70
  send(:"around_#{lifecycle}", :giggle!)
71
+ send(:"before_#{lifecycle}", callback_object, :if => :evaluates_to_false!)
72
+ send(:"after_#{lifecycle}", callback_object, :unless => :evaluates_to_true!)
73
+ send(:"around_#{lifecycle}", callback_object)
74
+ define_method(:shake!){}
75
+ define_method(:dance!){}
76
+ define_method(:giggle!){}
35
77
  end.new
36
78
  end
37
79
  context "as a simple callback test" do
@@ -47,10 +89,32 @@ describe Shoulda::Callback::Matchers::ActiveModel do
47
89
  it "should not find callbacks that are not there" do
48
90
  @model.should_not callback(:scream!).around(lifecycle)
49
91
  end
92
+ it "should not find callback_objects around the fact" do
93
+ @model.should_not callback(:shake!).around(lifecycle)
94
+ end
50
95
  it "should have a meaningful description" do
51
96
  matcher = callback(:dance!).before(lifecycle)
52
97
  matcher.description.should == "callback dance! before #{lifecycle}"
53
98
  end
99
+ it "should find the callback_object before the fact" do
100
+ @model.should callback(@callback_object_class).before(lifecycle)
101
+ end
102
+ it "should find the callback_object after the fact" do
103
+ @model.should callback(@callback_object_class).after(lifecycle)
104
+ end
105
+ it "should find the callback_object around the fact" do
106
+ @model.should callback(@callback_object_class).around(lifecycle)
107
+ end
108
+ it "should not find callbacks that are not there" do
109
+ @model.should_not callback(@callback_object_not_found_class).around(lifecycle)
110
+ end
111
+ it "should not find callback_objects around the fact" do
112
+ @model.should_not callback(@callback_object_not_found_class).around(lifecycle)
113
+ end
114
+ it "should have a meaningful description" do
115
+ matcher = callback(@callback_object_class).before(lifecycle)
116
+ matcher.description.should == "callback Callback before #{lifecycle}"
117
+ end
54
118
  end
55
119
  context "with conditions" do
56
120
  it "should match the if condition" do
@@ -69,12 +133,46 @@ describe Shoulda::Callback::Matchers::ActiveModel do
69
133
  matcher = callback(:dance!).after(lifecycle).unless(:evaluates_to_false!)
70
134
  matcher.description.should == "callback dance! after #{lifecycle} unless evaluates_to_false! evaluates to false"
71
135
  end
136
+
137
+ it "should match the if condition" do
138
+ @model.should callback(@callback_object_class).before(lifecycle).if(:evaluates_to_false!)
139
+ end
140
+ it "should match the unless condition" do
141
+ @model.should callback(@callback_object_class).after(lifecycle).unless(:evaluates_to_true!)
142
+ end
143
+ it "should not find callbacks not matching the conditions" do
144
+ @model.should_not callback(@callback_object_class).around(lifecycle).unless(:evaluates_to_false!)
145
+ end
146
+ it "should not find callbacks that are not there entirely" do
147
+ @model.should_not callback(@callback_object_not_found_class).before(lifecycle).unless(:evaluates_to_false!)
148
+ end
149
+ it "should have a meaningful description" do
150
+ matcher = callback(@callback_object_class).after(lifecycle).unless(:evaluates_to_false!)
151
+ matcher.description.should == "callback Callback after #{lifecycle} unless evaluates_to_false! evaluates to false"
152
+ end
72
153
  end
73
154
  end
74
155
  end
75
156
 
76
157
  context "on validation" do
77
158
  before do
159
+ @callback_object_class = define_model(:callback) do
160
+ define_method("before_validation"){}
161
+ define_method("after_validation"){}
162
+ end
163
+
164
+ @callback_object_class2 = define_model(:callback2) do
165
+ define_method("before_validation"){}
166
+ define_method("after_validation"){}
167
+ end
168
+
169
+ callback_object = @callback_object_class.new
170
+ callback_object2 = @callback_object_class2.new
171
+
172
+ @callback_object_not_found_class = define_model(:callback_not_fount) do
173
+ define_method("before_validation"){}
174
+ define_method("after_validation"){}
175
+ end
78
176
  @model = define_model(:example, :attr => :string,
79
177
  :other => :integer) do
80
178
  before_validation :dance!, :if => :evaluates_to_false!
@@ -82,6 +180,16 @@ describe Shoulda::Callback::Matchers::ActiveModel do
82
180
  before_validation :dress!, :on => :create
83
181
  after_validation :shriek!, :on => :update, :unless => :evaluates_to_true!
84
182
  after_validation :pucker!, :on => :save, :if => :evaluates_to_false!
183
+ before_validation callback_object, :if => :evaluates_to_false!
184
+ after_validation callback_object, :unless => :evaluates_to_true!
185
+ before_validation callback_object, :on => :create
186
+ after_validation callback_object, :on => :update, :unless => :evaluates_to_true!
187
+ after_validation callback_object2, :on => :save, :if => :evaluates_to_false!
188
+ define_method(:dance!){}
189
+ define_method(:shake!){}
190
+ define_method(:dress!){}
191
+ define_method(:shriek!){}
192
+ define_method(:pucker!){}
85
193
  end.new
86
194
  end
87
195
 
@@ -102,6 +210,23 @@ describe Shoulda::Callback::Matchers::ActiveModel do
102
210
  matcher = callback(:dance!).before(:validation)
103
211
  matcher.description.should == "callback dance! before validation"
104
212
  end
213
+
214
+ it "should find the callback before the fact" do
215
+ @model.should callback(@callback_object_class).before(:validation)
216
+ end
217
+ it "should find the callback after the fact" do
218
+ @model.should callback(@callback_object_class).after(:validation)
219
+ end
220
+ it "should not find a callback around the fact" do
221
+ @model.should_not callback(@callback_object_class).around(:validation)
222
+ end
223
+ it "should not find callbacks that are not there" do
224
+ @model.should_not callback(@callback_object_not_found_class).around(:validation)
225
+ end
226
+ it "should have a meaningful description" do
227
+ matcher = callback(@callback_object_class).before(:validation)
228
+ matcher.description.should == "callback Callback before validation"
229
+ end
105
230
  end
106
231
 
107
232
  context "with additinal lifecycles defined" do
@@ -121,6 +246,23 @@ describe Shoulda::Callback::Matchers::ActiveModel do
121
246
  matcher = callback(:dance!).after(:validation).on(:update)
122
247
  matcher.description.should == "callback dance! after validation on update"
123
248
  end
249
+
250
+ it "should find the callback before the fact on create" do
251
+ @model.should callback(@callback_object_class).before(:validation).on(:create)
252
+ end
253
+ it "should find the callback after the fact on update" do
254
+ @model.should callback(@callback_object_class).after(:validation).on(:update)
255
+ end
256
+ it "should find the callback after the fact on save" do
257
+ @model.should callback(@callback_object_class2).after(:validation).on(:save)
258
+ end
259
+ it "should not find a callback for Callback after the fact on update" do
260
+ @model.should_not callback(@callback_object_class2).after(:validation).on(:update)
261
+ end
262
+ it "should have a meaningful description" do
263
+ matcher = callback(@callback_object_class).after(:validation).on(:update)
264
+ matcher.description.should == "callback Callback after validation on update"
265
+ end
124
266
  end
125
267
 
126
268
  context "with conditions" do
@@ -140,6 +282,23 @@ describe Shoulda::Callback::Matchers::ActiveModel do
140
282
  matcher = callback(:dance!).after(:validation).unless(:evaluates_to_false!)
141
283
  matcher.description.should == "callback dance! after validation unless evaluates_to_false! evaluates to false"
142
284
  end
285
+
286
+ it "should match the if condition" do
287
+ @model.should callback(@callback_object_class).before(:validation).if(:evaluates_to_false!)
288
+ end
289
+ it "should match the unless condition" do
290
+ @model.should callback(@callback_object_class).after(:validation).unless(:evaluates_to_true!)
291
+ end
292
+ it "should not find callbacks not matching the conditions" do
293
+ @model.should_not callback(@callback_object_class).around(:validation).unless(:evaluates_to_false!)
294
+ end
295
+ it "should not find callbacks that are not there entirely" do
296
+ @model.should_not callback(@callback_object_not_found_class).before(:validation).unless(:evaluates_to_false!)
297
+ end
298
+ it "should have a meaningful description" do
299
+ matcher = callback(@callback_object_class).after(:validation).unless(:evaluates_to_false!)
300
+ matcher.description.should == "callback Callback after validation unless evaluates_to_false! evaluates to false"
301
+ end
143
302
  end
144
303
 
145
304
  context "with conditions and additional lifecycles" do
@@ -159,6 +318,23 @@ describe Shoulda::Callback::Matchers::ActiveModel do
159
318
  matcher = callback(:dance!).after(:validation).on(:save).unless(:evaluates_to_false!)
160
319
  matcher.description.should == "callback dance! after validation on save unless evaluates_to_false! evaluates to false"
161
320
  end
321
+
322
+ it "should find the callback before the fact on create" do
323
+ @model.should callback(@callback_object_class).before(:validation).on(:create)
324
+ end
325
+ it "should find the callback after the fact on update with the unless condition" do
326
+ @model.should callback(@callback_object_class).after(:validation).on(:update).unless(:evaluates_to_true!)
327
+ end
328
+ it "should find the callback after the fact on save with the if condition" do
329
+ @model.should callback(@callback_object_class2).after(:validation).on(:save).if(:evaluates_to_false!)
330
+ end
331
+ it "should not find a callback for Callback after the fact on save with the wrong condition" do
332
+ @model.should_not callback(@callback_object_class).after(:validation).on(:save).unless(:evaluates_to_false!)
333
+ end
334
+ it "should have a meaningful description" do
335
+ matcher = callback(@callback_object_class).after(:validation).on(:save).unless(:evaluates_to_false!)
336
+ matcher.description.should == "callback Callback after validation on save unless evaluates_to_false! evaluates to false"
337
+ end
162
338
  end
163
339
  end
164
340
 
@@ -166,10 +342,29 @@ describe Shoulda::Callback::Matchers::ActiveModel do
166
342
 
167
343
  context "on #{lifecycle}" do
168
344
  before do
345
+
346
+ @callback_object_class = define_model(:callback) do
347
+ define_method("after_#{lifecycle}"){}
348
+ end
349
+ @callback_object_class2 = define_model(:callback2) do
350
+ define_method("after_#{lifecycle}"){}
351
+ end
352
+
353
+ callback_object = @callback_object_class.new
354
+ callback_object2 = @callback_object_class2.new
355
+
356
+ @callback_object_not_found_class = define_model(:callback_not_fount) do
357
+ define_method("after_#{lifecycle}"){}
358
+ end
359
+
169
360
  @model = define_model(:example, :attr => :string,
170
361
  :other => :integer) do
171
362
  send(:"after_#{lifecycle}", :dance!, :if => :evaluates_to_false!)
172
363
  send(:"after_#{lifecycle}", :shake!, :unless => :evaluates_to_true!)
364
+ send(:"after_#{lifecycle}", callback_object, :if => :evaluates_to_false!)
365
+ send(:"after_#{lifecycle}", callback_object2, :unless => :evaluates_to_true!)
366
+ define_method(:shake!){}
367
+ define_method(:dance!){}
173
368
 
174
369
  define_method :evaluates_to_false! do
175
370
  false
@@ -199,6 +394,23 @@ describe Shoulda::Callback::Matchers::ActiveModel do
199
394
  matcher = callback(:dance!).before(lifecycle)
200
395
  matcher.description.should == "callback dance! before #{lifecycle}"
201
396
  end
397
+
398
+ it "should not find a callback before the fact" do
399
+ @model.should_not callback(@callback_object_class).before(lifecycle)
400
+ end
401
+ it "should find the callback after the fact" do
402
+ @model.should callback(@callback_object_class).after(lifecycle)
403
+ end
404
+ it "should not find a callback around the fact" do
405
+ @model.should_not callback(@callback_object_class).around(lifecycle)
406
+ end
407
+ it "should not find callbacks that are not there" do
408
+ @model.should_not callback(@callback_object_not_found_class).around(lifecycle)
409
+ end
410
+ it "should have a meaningful description" do
411
+ matcher = callback(@callback_object_class).before(lifecycle)
412
+ matcher.description.should == "callback Callback before #{lifecycle}"
413
+ end
202
414
  end
203
415
 
204
416
  context "with conditions" do
@@ -218,6 +430,22 @@ describe Shoulda::Callback::Matchers::ActiveModel do
218
430
  matcher = callback(:dance!).after(lifecycle).unless(:evaluates_to_false!)
219
431
  matcher.description.should == "callback dance! after #{lifecycle} unless evaluates_to_false! evaluates to false"
220
432
  end
433
+ it "should match the if condition" do
434
+ @model.should callback(@callback_object_class).after(lifecycle).if(:evaluates_to_false!)
435
+ end
436
+ it "should match the unless condition" do
437
+ @model.should callback(@callback_object_class2).after(lifecycle).unless(:evaluates_to_true!)
438
+ end
439
+ it "should not find callbacks not matching the conditions" do
440
+ @model.should_not callback(@callback_object_class).around(lifecycle).unless(:evaluates_to_false!)
441
+ end
442
+ it "should not find callbacks that are not there entirely" do
443
+ @model.should_not callback(@callback_object_not_found_class).before(lifecycle).unless(:evaluates_to_false!)
444
+ end
445
+ it "should have a meaningful description" do
446
+ matcher = callback(@callback_object_class).after(lifecycle).unless(:evaluates_to_false!)
447
+ matcher.description.should == "callback Callback after #{lifecycle} unless evaluates_to_false! evaluates to false"
448
+ end
221
449
  end
222
450
 
223
451
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoulda-callback-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beat Richartz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-04 00:00:00.000000000 Z
11
+ date: 2014-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: appraisal
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.0
33
+ version: '0.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.0
40
+ version: '0.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: aruba
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
@@ -58,70 +58,70 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.0
61
+ version: '1.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 1.3.0
68
+ version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.1.0
75
+ version: '1.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
- version: 1.1.0
82
+ version: '1.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rails
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
- version: '3.0'
89
+ version: '3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
- version: '3.0'
96
+ version: '3'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ~>
102
102
  - !ruby/object:Gem::Version
103
- version: 10.0.0
103
+ version: '10'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
- version: 10.0.0
110
+ version: '10'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec-rails
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 2.12.0
117
+ version: '2'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ~>
123
123
  - !ruby/object:Gem::Version
124
- version: 2.12.0
124
+ version: '2'
125
125
  description: Making callback tests easy on the fingers and eyes
126
126
  email: attraccessor@gmail.com
127
127
  executables: []
@@ -129,6 +129,7 @@ extensions:
129
129
  - ext/mkrf_conf.rb
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - .DS_Store
132
133
  - .gitignore
133
134
  - .ruby-gemset
134
135
  - .ruby-version
@@ -164,17 +165,17 @@ require_paths:
164
165
  - lib
165
166
  required_ruby_version: !ruby/object:Gem::Requirement
166
167
  requirements:
167
- - - ! '>='
168
+ - - '>='
168
169
  - !ruby/object:Gem::Version
169
170
  version: '0'
170
171
  required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  requirements:
172
- - - ! '>='
173
+ - - '>='
173
174
  - !ruby/object:Gem::Version
174
175
  version: '0'
175
176
  requirements: []
176
177
  rubyforge_project:
177
- rubygems_version: 2.1.11
178
+ rubygems_version: 2.2.2
178
179
  signing_key:
179
180
  specification_version: 4
180
181
  summary: Making callback tests easy on the fingers and eyes