shoulda-callback-matchers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sqlite3", :platform=>:ruby
6
+ gem "activerecord-jdbc-adapter", :platform=>:jruby
7
+ gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
8
+ gem "jdbc-sqlite3", :platform=>:jruby
9
+ gem "jruby-openssl", :platform=>:jruby
10
+ gem "therubyrhino", :platform=>:jruby
11
+ gem "rails", "~>3.1.0"
12
+ gem "jquery-rails"
13
+ gem "sass-rails"
14
+
15
+ gemspec :path=>"../"
@@ -0,0 +1,155 @@
1
+ PATH
2
+ remote: /Users/beatrichartz/Projects/shoulda-callback-matchers
3
+ specs:
4
+ shoulda-callback-matchers (0.1.0)
5
+ activesupport (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.1.8)
11
+ actionpack (= 3.1.8)
12
+ mail (~> 2.3.3)
13
+ actionpack (3.1.8)
14
+ activemodel (= 3.1.8)
15
+ activesupport (= 3.1.8)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ i18n (~> 0.6)
19
+ rack (~> 1.3.6)
20
+ rack-cache (~> 1.2)
21
+ rack-mount (~> 0.8.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.0.4)
24
+ activemodel (3.1.8)
25
+ activesupport (= 3.1.8)
26
+ builder (~> 3.0.0)
27
+ i18n (~> 0.6)
28
+ activerecord (3.1.8)
29
+ activemodel (= 3.1.8)
30
+ activesupport (= 3.1.8)
31
+ arel (~> 2.2.3)
32
+ tzinfo (~> 0.3.29)
33
+ activeresource (3.1.8)
34
+ activemodel (= 3.1.8)
35
+ activesupport (= 3.1.8)
36
+ activesupport (3.1.8)
37
+ multi_json (>= 1.0, < 1.3)
38
+ appraisal (0.4.1)
39
+ bundler
40
+ rake
41
+ arel (2.2.3)
42
+ aruba (0.5.0)
43
+ childprocess (= 0.2.3)
44
+ cucumber (>= 1.1.1)
45
+ ffi (>= 1.0.11)
46
+ rspec-expectations (>= 2.7.0)
47
+ bourne (1.1.2)
48
+ mocha (= 0.10.5)
49
+ builder (3.0.4)
50
+ childprocess (0.2.3)
51
+ ffi (~> 1.0.6)
52
+ cucumber (1.2.1)
53
+ builder (>= 2.1.2)
54
+ diff-lcs (>= 1.1.3)
55
+ gherkin (~> 2.11.0)
56
+ json (>= 1.4.6)
57
+ diff-lcs (1.1.3)
58
+ erubis (2.7.0)
59
+ ffi (1.0.11)
60
+ gherkin (2.11.5)
61
+ json (>= 1.4.6)
62
+ hike (1.2.1)
63
+ i18n (0.6.1)
64
+ jquery-rails (2.1.3)
65
+ railties (>= 3.1.0, < 5.0)
66
+ thor (~> 0.14)
67
+ json (1.7.5)
68
+ mail (2.3.3)
69
+ i18n (>= 0.4.0)
70
+ mime-types (~> 1.16)
71
+ treetop (~> 1.4.8)
72
+ metaclass (0.0.1)
73
+ mime-types (1.19)
74
+ mocha (0.10.5)
75
+ metaclass (~> 0.0.1)
76
+ multi_json (1.2.0)
77
+ polyglot (0.3.3)
78
+ rack (1.3.6)
79
+ rack-cache (1.2)
80
+ rack (>= 0.4)
81
+ rack-mount (0.8.3)
82
+ rack (>= 1.0.0)
83
+ rack-ssl (1.3.2)
84
+ rack
85
+ rack-test (0.6.2)
86
+ rack (>= 1.0)
87
+ rails (3.1.8)
88
+ actionmailer (= 3.1.8)
89
+ actionpack (= 3.1.8)
90
+ activerecord (= 3.1.8)
91
+ activeresource (= 3.1.8)
92
+ activesupport (= 3.1.8)
93
+ bundler (~> 1.0)
94
+ railties (= 3.1.8)
95
+ railties (3.1.8)
96
+ actionpack (= 3.1.8)
97
+ activesupport (= 3.1.8)
98
+ rack-ssl (~> 1.3.2)
99
+ rake (>= 0.8.7)
100
+ rdoc (~> 3.4)
101
+ thor (~> 0.14.6)
102
+ rake (0.9.4)
103
+ rdoc (3.12)
104
+ json (~> 1.4)
105
+ rspec (2.8.0)
106
+ rspec-core (~> 2.8.0)
107
+ rspec-expectations (~> 2.8.0)
108
+ rspec-mocks (~> 2.8.0)
109
+ rspec-core (2.8.0)
110
+ rspec-expectations (2.8.0)
111
+ diff-lcs (~> 1.1.2)
112
+ rspec-mocks (2.8.0)
113
+ rspec-rails (2.8.1)
114
+ actionpack (>= 3.0)
115
+ activesupport (>= 3.0)
116
+ railties (>= 3.0)
117
+ rspec (~> 2.8.0)
118
+ sass (3.2.3)
119
+ sass-rails (3.1.6)
120
+ actionpack (~> 3.1.0)
121
+ railties (~> 3.1.0)
122
+ sass (>= 3.1.10)
123
+ tilt (~> 1.3.2)
124
+ sprockets (2.0.4)
125
+ hike (~> 1.2)
126
+ rack (~> 1.0)
127
+ tilt (~> 1.1, != 1.3.0)
128
+ sqlite3 (1.3.6)
129
+ thor (0.14.6)
130
+ tilt (1.3.3)
131
+ treetop (1.4.12)
132
+ polyglot
133
+ polyglot (>= 0.3.1)
134
+ tzinfo (0.3.35)
135
+
136
+ PLATFORMS
137
+ ruby
138
+
139
+ DEPENDENCIES
140
+ activerecord-jdbc-adapter
141
+ activerecord-jdbcsqlite3-adapter
142
+ appraisal (~> 0.4.0)
143
+ aruba
144
+ bourne (~> 1.1.2)
145
+ bundler (>= 1.1.0)
146
+ jdbc-sqlite3
147
+ jquery-rails
148
+ jruby-openssl
149
+ rails (~> 3.1.0)
150
+ rake (~> 0.9.2)
151
+ rspec-rails (~> 2.8.1)
152
+ sass-rails
153
+ shoulda-callback-matchers!
154
+ sqlite3
155
+ therubyrhino
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sqlite3", :platform=>:ruby
6
+ gem "activerecord-jdbc-adapter", :platform=>:jruby
7
+ gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
8
+ gem "jdbc-sqlite3", :platform=>:jruby
9
+ gem "jruby-openssl", :platform=>:jruby
10
+ gem "therubyrhino", :platform=>:jruby
11
+ gem "rails", "~>3.2.0"
12
+ gem "jquery-rails"
13
+ gem "sass-rails"
14
+
15
+ gemspec :path=>"../"
@@ -0,0 +1,153 @@
1
+ PATH
2
+ remote: /Users/beatrichartz/Projects/shoulda-callback-matchers
3
+ specs:
4
+ shoulda-callback-matchers (0.1.0)
5
+ activesupport (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.2.9)
11
+ actionpack (= 3.2.9)
12
+ mail (~> 2.4.4)
13
+ actionpack (3.2.9)
14
+ activemodel (= 3.2.9)
15
+ activesupport (= 3.2.9)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.4)
19
+ rack (~> 1.4.0)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.2.1)
23
+ activemodel (3.2.9)
24
+ activesupport (= 3.2.9)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.9)
27
+ activemodel (= 3.2.9)
28
+ activesupport (= 3.2.9)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activeresource (3.2.9)
32
+ activemodel (= 3.2.9)
33
+ activesupport (= 3.2.9)
34
+ activesupport (3.2.9)
35
+ i18n (~> 0.6)
36
+ multi_json (~> 1.0)
37
+ appraisal (0.4.1)
38
+ bundler
39
+ rake
40
+ arel (3.0.2)
41
+ aruba (0.5.0)
42
+ childprocess (= 0.2.3)
43
+ cucumber (>= 1.1.1)
44
+ ffi (>= 1.0.11)
45
+ rspec-expectations (>= 2.7.0)
46
+ bourne (1.1.2)
47
+ mocha (= 0.10.5)
48
+ builder (3.0.4)
49
+ childprocess (0.2.3)
50
+ ffi (~> 1.0.6)
51
+ cucumber (1.2.1)
52
+ builder (>= 2.1.2)
53
+ diff-lcs (>= 1.1.3)
54
+ gherkin (~> 2.11.0)
55
+ json (>= 1.4.6)
56
+ diff-lcs (1.1.3)
57
+ erubis (2.7.0)
58
+ ffi (1.0.11)
59
+ gherkin (2.11.5)
60
+ json (>= 1.4.6)
61
+ hike (1.2.1)
62
+ i18n (0.6.1)
63
+ journey (1.0.4)
64
+ jquery-rails (2.1.3)
65
+ railties (>= 3.1.0, < 5.0)
66
+ thor (~> 0.14)
67
+ json (1.7.5)
68
+ mail (2.4.4)
69
+ i18n (>= 0.4.0)
70
+ mime-types (~> 1.16)
71
+ treetop (~> 1.4.8)
72
+ metaclass (0.0.1)
73
+ mime-types (1.19)
74
+ mocha (0.10.5)
75
+ metaclass (~> 0.0.1)
76
+ multi_json (1.3.7)
77
+ polyglot (0.3.3)
78
+ rack (1.4.1)
79
+ rack-cache (1.2)
80
+ rack (>= 0.4)
81
+ rack-ssl (1.3.2)
82
+ rack
83
+ rack-test (0.6.2)
84
+ rack (>= 1.0)
85
+ rails (3.2.9)
86
+ actionmailer (= 3.2.9)
87
+ actionpack (= 3.2.9)
88
+ activerecord (= 3.2.9)
89
+ activeresource (= 3.2.9)
90
+ activesupport (= 3.2.9)
91
+ bundler (~> 1.0)
92
+ railties (= 3.2.9)
93
+ railties (3.2.9)
94
+ actionpack (= 3.2.9)
95
+ activesupport (= 3.2.9)
96
+ rack-ssl (~> 1.3.2)
97
+ rake (>= 0.8.7)
98
+ rdoc (~> 3.4)
99
+ thor (>= 0.14.6, < 2.0)
100
+ rake (0.9.4)
101
+ rdoc (3.12)
102
+ json (~> 1.4)
103
+ rspec (2.8.0)
104
+ rspec-core (~> 2.8.0)
105
+ rspec-expectations (~> 2.8.0)
106
+ rspec-mocks (~> 2.8.0)
107
+ rspec-core (2.8.0)
108
+ rspec-expectations (2.8.0)
109
+ diff-lcs (~> 1.1.2)
110
+ rspec-mocks (2.8.0)
111
+ rspec-rails (2.8.1)
112
+ actionpack (>= 3.0)
113
+ activesupport (>= 3.0)
114
+ railties (>= 3.0)
115
+ rspec (~> 2.8.0)
116
+ sass (3.2.3)
117
+ sass-rails (3.2.5)
118
+ railties (~> 3.2.0)
119
+ sass (>= 3.1.10)
120
+ tilt (~> 1.3)
121
+ sprockets (2.2.1)
122
+ hike (~> 1.2)
123
+ multi_json (~> 1.0)
124
+ rack (~> 1.0)
125
+ tilt (~> 1.1, != 1.3.0)
126
+ sqlite3 (1.3.6)
127
+ thor (0.16.0)
128
+ tilt (1.3.3)
129
+ treetop (1.4.12)
130
+ polyglot
131
+ polyglot (>= 0.3.1)
132
+ tzinfo (0.3.35)
133
+
134
+ PLATFORMS
135
+ ruby
136
+
137
+ DEPENDENCIES
138
+ activerecord-jdbc-adapter
139
+ activerecord-jdbcsqlite3-adapter
140
+ appraisal (~> 0.4.0)
141
+ aruba
142
+ bourne (~> 1.1.2)
143
+ bundler (>= 1.1.0)
144
+ jdbc-sqlite3
145
+ jquery-rails
146
+ jruby-openssl
147
+ rails (~> 3.2.0)
148
+ rake (~> 0.9.2)
149
+ rspec-rails (~> 2.8.1)
150
+ sass-rails
151
+ shoulda-callback-matchers!
152
+ sqlite3
153
+ therubyrhino
@@ -0,0 +1 @@
1
+ require 'shoulda/callback/matchers'
@@ -0,0 +1,7 @@
1
+ require 'shoulda/callback/matchers/version'
2
+
3
+ if defined?(RSpec)
4
+ require 'shoulda/callback/matchers/integrations/rspec'
5
+ end
6
+
7
+ require 'shoulda/callback/matchers/integrations/test_unit'
@@ -0,0 +1,107 @@
1
+ module Shoulda # :nodoc:
2
+ module Callback # :nodoc:
3
+ module Matchers # :nodoc:
4
+ module ActiveModel # :nodoc:
5
+
6
+ # Ensures that the given model has a callback defined for the given method
7
+ #
8
+ # Options:
9
+ # * <tt>before(:lifecycle)</tt>. <tt>Symbol</tt>. - define the callback as a callback before the fact. :lifecycle can be :save, :create, :update, :destroy, :validation
10
+ # * <tt>after(:lifecycle)</tt>. <tt>Symbol</tt>. - define the callback as a callback after the fact. :lifecycle can be :save, :create, :update, :destroy, :validation, :initialize, :find, :touch
11
+ # * <tt>around(:lifecycle)</tt>. <tt>Symbol</tt>. - define the callback as a callback around the fact. :lifecycle can be :save, :create, :update, :destroy
12
+ # <tt>if(:condition)</tt>. <tt>Symbol</tt>. - add a positive condition to the callback to be matched against
13
+ # <tt>unless(:condition)</tt>. <tt>Symbol</tt>. - add a negative condition to the callback to be matched against
14
+ #
15
+ # Examples:
16
+ # it { should callback(:method).after(:create) }
17
+ # it { should callback(:method).before(:validation).unless(:should_it_not?) }
18
+ #
19
+ def callback(method)
20
+ CallbackMatcher.new(method)
21
+ end
22
+
23
+ class CallbackMatcher # :nodoc:
24
+
25
+ def initialize(method)
26
+ @method = method
27
+ end
28
+
29
+ [:before, :after, :around].each do |hook|
30
+ define_method hook do |lifecycle|
31
+ @hook = hook
32
+ @lifecycle = lifecycle
33
+
34
+ self
35
+ end
36
+ end
37
+
38
+ [:if, :unless].each do |condition_type|
39
+ define_method condition_type do |condition|
40
+ @condition_type = condition_type
41
+ @condition = condition
42
+
43
+ self
44
+ end
45
+ end
46
+
47
+ def on(optional_lifecycle)
48
+ unless @lifecycle == :validation
49
+ @failure_message = "The .on option is only valid for the validation lifecycle and cannot be used with #{@lifecycle}, use with .before(:validation) or .after(:validation)"
50
+ else
51
+ @optional_lifecycle = optional_lifecycle
52
+ end
53
+
54
+ self
55
+ end
56
+
57
+ def matches?(subject)
58
+ unless @lifecycle
59
+ @failure_message = "callback #{@method} can not be tested against an undefined lifecycle, use .before, .after or .around"
60
+ false
61
+ else
62
+ callbacks = subject.send(:"_#{@lifecycle}_callbacks").dup
63
+ callbacks = callbacks.select do |callback|
64
+ callback.filter == @method &&
65
+ callback.kind == @hook &&
66
+ matches_conditions?(callback) &&
67
+ matches_optional_lifecycle?(callback)
68
+ end
69
+ callbacks.size > 0
70
+ end
71
+ end
72
+
73
+ def failure_message
74
+ @failure_message || "expected #{@method} to be listed as a callback #{@hook} #{@lifecycle}#{optional_lifecycle_phrase}#{condition_phrase}, but was not"
75
+ end
76
+
77
+ def negative_failure_message
78
+ @failure_message || "expected #{@method} not to be listed as a callback #{@hook} #{@lifecycle}#{optional_lifecycle_phrase}#{condition_phrase}, but was"
79
+ end
80
+
81
+ def description
82
+ "callback #{@method} #{@hook} #{@lifecycle}#{optional_lifecycle_phrase}#{condition_phrase}"
83
+ end
84
+
85
+ private
86
+
87
+ def matches_conditions?(callback)
88
+ !@condition || callback.options[@condition_type].include?(@condition)
89
+ end
90
+
91
+ def matches_optional_lifecycle?(callback)
92
+ !@optional_lifecycle || callback.options[:if].include?("self.validation_context == :#{@optional_lifecycle}")
93
+ end
94
+
95
+ def condition_phrase
96
+ " #{@condition_type} #{@condition} evaluates to #{@condition_type == :if ? 'true' : 'false'}" if @condition
97
+ end
98
+
99
+ def optional_lifecycle_phrase
100
+ " on #{@optional_lifecycle}" if @optional_lifecycle
101
+ end
102
+
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end