shoulda-matchers 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.gitignore +8 -7
  2. data/.travis.yml +4 -0
  3. data/Appraisals +8 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +77 -66
  7. data/MIT-LICENSE +1 -1
  8. data/NEWS.md +63 -1
  9. data/README.md +189 -33
  10. data/Rakefile +6 -5
  11. data/features/rails_integration.feature +1 -1
  12. data/features/step_definitions/rails_steps.rb +7 -6
  13. data/gemfiles/3.0.gemfile +2 -2
  14. data/gemfiles/3.0.gemfile.lock +14 -5
  15. data/gemfiles/3.1.gemfile +2 -2
  16. data/gemfiles/3.1.gemfile.lock +14 -5
  17. data/gemfiles/3.2.gemfile +2 -2
  18. data/gemfiles/3.2.gemfile.lock +16 -7
  19. data/gemfiles/4.0.0.gemfile +2 -2
  20. data/gemfiles/4.0.0.gemfile.lock +15 -6
  21. data/gemfiles/4.0.1.gemfile +2 -2
  22. data/gemfiles/4.0.1.gemfile.lock +15 -6
  23. data/gemfiles/4.1.gemfile +19 -0
  24. data/gemfiles/4.1.gemfile.lock +176 -0
  25. data/lib/shoulda/matchers.rb +17 -1
  26. data/lib/shoulda/matchers/action_controller.rb +4 -2
  27. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +100 -0
  28. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
  29. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +4 -4
  30. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
  31. data/lib/shoulda/matchers/action_controller/route_matcher.rb +12 -12
  32. data/lib/shoulda/matchers/action_controller/route_params.rb +1 -1
  33. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +2 -1
  34. data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +167 -0
  35. data/lib/shoulda/matchers/active_model.rb +4 -2
  36. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +23 -5
  37. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +0 -4
  38. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +66 -14
  39. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +8 -8
  40. data/lib/shoulda/matchers/active_model/errors.rb +40 -0
  41. data/lib/shoulda/matchers/active_model/helpers.rb +6 -6
  42. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +33 -14
  43. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +26 -0
  44. data/lib/shoulda/matchers/active_model/numericality_matchers/{odd_even_number_matcher.rb → numeric_type_matcher.rb} +9 -20
  45. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +26 -0
  46. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +5 -21
  47. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +1 -1
  48. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +71 -22
  49. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +6 -1
  50. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +25 -6
  51. data/lib/shoulda/matchers/active_record.rb +1 -0
  52. data/lib/shoulda/matchers/active_record/association_matcher.rb +67 -13
  53. data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +40 -0
  54. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +24 -1
  55. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +1 -1
  56. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +1 -1
  57. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
  58. data/lib/shoulda/matchers/assertion_error.rb +7 -2
  59. data/lib/shoulda/matchers/error.rb +24 -0
  60. data/lib/shoulda/matchers/independent.rb +10 -0
  61. data/lib/shoulda/matchers/independent/delegate_matcher.rb +157 -0
  62. data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +34 -0
  63. data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +36 -0
  64. data/lib/shoulda/matchers/integrations/rspec.rb +13 -14
  65. data/lib/shoulda/matchers/integrations/test_unit.rb +11 -9
  66. data/lib/shoulda/matchers/version.rb +1 -1
  67. data/lib/shoulda/matchers/warn.rb +7 -0
  68. data/shoulda-matchers.gemspec +2 -1
  69. data/spec/shoulda/matchers/action_controller/callback_matcher_spec.rb +79 -0
  70. data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +3 -3
  71. data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +11 -11
  72. data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +21 -21
  73. data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +10 -10
  74. data/spec/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +45 -18
  75. data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +8 -8
  76. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +19 -19
  77. data/spec/shoulda/matchers/action_controller/route_params_spec.rb +6 -6
  78. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +11 -11
  79. data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +44 -44
  80. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +205 -0
  81. data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +24 -24
  82. data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +37 -37
  83. data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +17 -21
  84. data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +24 -24
  85. data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +173 -67
  86. data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +40 -40
  87. data/spec/shoulda/matchers/active_model/exception_message_finder_spec.rb +20 -20
  88. data/spec/shoulda/matchers/active_model/helpers_spec.rb +27 -25
  89. data/spec/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +126 -13
  90. data/spec/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +59 -0
  91. data/spec/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +59 -0
  92. data/spec/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +27 -26
  93. data/spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +15 -15
  94. data/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +8 -8
  95. data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +9 -9
  96. data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +229 -44
  97. data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +44 -25
  98. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +110 -62
  99. data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +19 -19
  100. data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +30 -30
  101. data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +378 -192
  102. data/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +4 -0
  103. data/spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +33 -33
  104. data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +21 -17
  105. data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +8 -8
  106. data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +14 -14
  107. data/spec/shoulda/matchers/independent/delegate_matcher/stubbed_target_spec.rb +43 -0
  108. data/spec/shoulda/matchers/independent/delegate_matcher_spec.rb +184 -0
  109. data/spec/spec_helper.rb +4 -0
  110. data/spec/support/activemodel_helpers.rb +2 -2
  111. data/spec/support/capture_helpers.rb +19 -0
  112. data/spec/support/controller_builder.rb +22 -3
  113. data/spec/support/fail_with_message_including_matcher.rb +33 -0
  114. data/spec/support/model_builder.rb +1 -1
  115. data/spec/support/shared_examples/numerical_submatcher.rb +19 -0
  116. data/spec/support/shared_examples/numerical_type_submatcher.rb +17 -0
  117. data/spec/support/test_application.rb +23 -0
  118. metadata +90 -22
  119. checksums.yaml +0 -7
  120. data/spec/shoulda/matchers/active_model/numericality_matchers/odd_even_number_matcher_spec.rb +0 -97
  121. data/spec/support/shared_examples/numerical_submatcher_spec.rb +0 -23
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "shoulda-context", "~> 1.1.2"
5
+ gem "shoulda-context", "~> 1.2.0"
6
6
  gem "sqlite3", :platform=>:ruby
7
7
  gem "activerecord-jdbc-adapter", :platform=>:jruby
8
8
  gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
@@ -16,4 +16,4 @@ gem "rails", "4.0.1"
16
16
  gem "sass-rails", "4.0.1"
17
17
  gem "bcrypt-ruby", "~> 3.1.2"
18
18
 
19
- gemspec :path=>"../"
19
+ gemspec :path=>".././"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- shoulda-matchers (2.5.0)
4
+ shoulda-matchers (2.6.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -35,9 +35,10 @@ GEM
35
35
  multi_json (~> 1.3)
36
36
  thread_safe (~> 0.1)
37
37
  tzinfo (~> 0.3.37)
38
- appraisal (0.5.2)
38
+ appraisal (1.0.0.beta2)
39
39
  bundler
40
40
  rake
41
+ thor (>= 0.14.0)
41
42
  arel (4.0.1)
42
43
  aruba (0.5.3)
43
44
  childprocess (>= 0.3.6)
@@ -50,6 +51,7 @@ GEM
50
51
  builder (3.1.4)
51
52
  childprocess (0.3.9)
52
53
  ffi (~> 1.0, >= 1.0.11)
54
+ coderay (1.1.0)
53
55
  cucumber (1.3.10)
54
56
  builder (>= 2.1.2)
55
57
  diff-lcs (>= 1.1.3)
@@ -70,6 +72,7 @@ GEM
70
72
  mime-types (~> 1.16)
71
73
  treetop (~> 1.4.8)
72
74
  metaclass (0.0.1)
75
+ method_source (0.8.2)
73
76
  mime-types (1.25.1)
74
77
  minitest (4.7.5)
75
78
  mocha (0.14.0)
@@ -79,6 +82,10 @@ GEM
79
82
  polyglot (0.3.3)
80
83
  protected_attributes (1.0.5)
81
84
  activemodel (>= 4.0.1, < 5.0)
85
+ pry (0.9.12.6)
86
+ coderay (~> 1.0)
87
+ method_source (~> 0.8)
88
+ slop (~> 3.4)
82
89
  rack (1.5.2)
83
90
  rack-test (0.6.2)
84
91
  rack (>= 1.0)
@@ -97,7 +104,7 @@ GEM
97
104
  activesupport (= 4.0.1)
98
105
  rake (>= 0.8.7)
99
106
  thor (>= 0.18.1, < 2.0)
100
- rake (10.1.0)
107
+ rake (10.1.1)
101
108
  rspec-core (2.14.7)
102
109
  rspec-expectations (2.14.4)
103
110
  diff-lcs (>= 1.1.3, < 2.0)
@@ -114,7 +121,8 @@ GEM
114
121
  railties (>= 4.0.0, < 5.0)
115
122
  sass (>= 3.1.10)
116
123
  sprockets-rails (~> 2.0.0)
117
- shoulda-context (1.1.6)
124
+ shoulda-context (1.2.0)
125
+ slop (3.4.7)
118
126
  sprockets (2.10.1)
119
127
  hike (~> 1.2)
120
128
  multi_json (~> 1.0)
@@ -141,7 +149,7 @@ DEPENDENCIES
141
149
  activerecord-jdbc-adapter
142
150
  activerecord-jdbcsqlite3-adapter
143
151
  activeresource (= 4.0.0)
144
- appraisal (~> 0.4)
152
+ appraisal (~> 1.0.0.beta2)
145
153
  aruba
146
154
  bcrypt-ruby (~> 3.1.2)
147
155
  bourne (~> 1.3)
@@ -151,11 +159,12 @@ DEPENDENCIES
151
159
  jquery-rails
152
160
  jruby-openssl
153
161
  protected_attributes
162
+ pry
154
163
  rails (= 4.0.1)
155
164
  rake (>= 0.9.2)
156
165
  rspec-rails (>= 2.13.1, < 3)
157
166
  sass-rails (= 4.0.1)
158
- shoulda-context (~> 1.1.2)
167
+ shoulda-context (~> 1.2.0)
159
168
  shoulda-matchers!
160
169
  sqlite3
161
170
  therubyrhino
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "shoulda-context", "~> 1.2.0"
6
+ gem "sqlite3", :platform=>:ruby
7
+ gem "activerecord-jdbc-adapter", :platform=>:jruby
8
+ gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
9
+ gem "jdbc-sqlite3", :platform=>:jruby
10
+ gem "jruby-openssl", :platform=>:jruby
11
+ gem "therubyrhino", :platform=>:jruby
12
+ gem "jquery-rails"
13
+ gem "activeresource", "4.0.0"
14
+ gem "rails", "~> 4.1.0"
15
+ gem "sass-rails", "4.0.3"
16
+ gem "bcrypt-ruby", "~> 3.1.2"
17
+ gem "protected_attributes", "~> 1.0.6"
18
+
19
+ gemspec :path=>".././"
@@ -0,0 +1,176 @@
1
+ PATH
2
+ remote: .././
3
+ specs:
4
+ shoulda-matchers (2.6.0)
5
+ activesupport (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.1.0)
11
+ actionpack (= 4.1.0)
12
+ actionview (= 4.1.0)
13
+ mail (~> 2.5.4)
14
+ actionpack (4.1.0)
15
+ actionview (= 4.1.0)
16
+ activesupport (= 4.1.0)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ actionview (4.1.0)
20
+ activesupport (= 4.1.0)
21
+ builder (~> 3.1)
22
+ erubis (~> 2.7.0)
23
+ activemodel (4.1.0)
24
+ activesupport (= 4.1.0)
25
+ builder (~> 3.1)
26
+ activerecord (4.1.0)
27
+ activemodel (= 4.1.0)
28
+ activesupport (= 4.1.0)
29
+ arel (~> 5.0.0)
30
+ activeresource (4.0.0)
31
+ activemodel (~> 4.0)
32
+ activesupport (~> 4.0)
33
+ rails-observers (~> 0.1.1)
34
+ activesupport (4.1.0)
35
+ i18n (~> 0.6, >= 0.6.9)
36
+ json (~> 1.7, >= 1.7.7)
37
+ minitest (~> 5.1)
38
+ thread_safe (~> 0.1)
39
+ tzinfo (~> 1.1)
40
+ appraisal (1.0.0.beta2)
41
+ bundler
42
+ rake
43
+ thor (>= 0.14.0)
44
+ arel (5.0.0)
45
+ aruba (0.5.4)
46
+ childprocess (>= 0.3.6)
47
+ cucumber (>= 1.1.1)
48
+ rspec-expectations (>= 2.7.0)
49
+ bcrypt-ruby (3.1.2)
50
+ bourne (1.5.0)
51
+ mocha (>= 0.13.2, < 0.15)
52
+ builder (3.2.2)
53
+ childprocess (0.4.0)
54
+ ffi (~> 1.0, >= 1.0.11)
55
+ coderay (1.1.0)
56
+ cucumber (1.3.10)
57
+ builder (>= 2.1.2)
58
+ diff-lcs (>= 1.1.3)
59
+ gherkin (~> 2.12)
60
+ multi_json (>= 1.7.5, < 2.0)
61
+ multi_test (>= 0.0.2)
62
+ diff-lcs (1.2.5)
63
+ erubis (2.7.0)
64
+ ffi (1.9.3)
65
+ gherkin (2.12.2)
66
+ multi_json (~> 1.3)
67
+ hike (1.2.3)
68
+ i18n (0.6.9)
69
+ jquery-rails (3.1.0)
70
+ railties (>= 3.0, < 5.0)
71
+ thor (>= 0.14, < 2.0)
72
+ json (1.8.1)
73
+ mail (2.5.4)
74
+ mime-types (~> 1.16)
75
+ treetop (~> 1.4.8)
76
+ metaclass (0.0.2)
77
+ method_source (0.8.2)
78
+ mime-types (1.25.1)
79
+ minitest (5.3.2)
80
+ mocha (0.14.0)
81
+ metaclass (~> 0.0.1)
82
+ multi_json (1.9.2)
83
+ multi_test (0.0.3)
84
+ polyglot (0.3.4)
85
+ protected_attributes (1.0.7)
86
+ activemodel (>= 4.0.1, < 5.0)
87
+ pry (0.9.12.6)
88
+ coderay (~> 1.0)
89
+ method_source (~> 0.8)
90
+ slop (~> 3.4)
91
+ rack (1.5.2)
92
+ rack-test (0.6.2)
93
+ rack (>= 1.0)
94
+ rails (4.1.0)
95
+ actionmailer (= 4.1.0)
96
+ actionpack (= 4.1.0)
97
+ actionview (= 4.1.0)
98
+ activemodel (= 4.1.0)
99
+ activerecord (= 4.1.0)
100
+ activesupport (= 4.1.0)
101
+ bundler (>= 1.3.0, < 2.0)
102
+ railties (= 4.1.0)
103
+ sprockets-rails (~> 2.0)
104
+ rails-observers (0.1.2)
105
+ activemodel (~> 4.0)
106
+ railties (4.1.0)
107
+ actionpack (= 4.1.0)
108
+ activesupport (= 4.1.0)
109
+ rake (>= 0.8.7)
110
+ thor (>= 0.18.1, < 2.0)
111
+ rake (10.2.2)
112
+ rspec-core (2.14.7)
113
+ rspec-expectations (2.14.4)
114
+ diff-lcs (>= 1.1.3, < 2.0)
115
+ rspec-mocks (2.14.4)
116
+ rspec-rails (2.14.1)
117
+ actionpack (>= 3.0)
118
+ activemodel (>= 3.0)
119
+ activesupport (>= 3.0)
120
+ railties (>= 3.0)
121
+ rspec-core (~> 2.14.0)
122
+ rspec-expectations (~> 2.14.0)
123
+ rspec-mocks (~> 2.14.0)
124
+ sass (3.2.19)
125
+ sass-rails (4.0.3)
126
+ railties (>= 4.0.0, < 5.0)
127
+ sass (~> 3.2.0)
128
+ sprockets (~> 2.8, <= 2.11.0)
129
+ sprockets-rails (~> 2.0)
130
+ shoulda-context (1.2.0)
131
+ slop (3.4.7)
132
+ sprockets (2.11.0)
133
+ hike (~> 1.2)
134
+ multi_json (~> 1.0)
135
+ rack (~> 1.0)
136
+ tilt (~> 1.1, != 1.3.0)
137
+ sprockets-rails (2.1.0)
138
+ actionpack (>= 4.0)
139
+ activesupport (>= 4.0)
140
+ sprockets (~> 2.8)
141
+ sqlite3 (1.3.9)
142
+ thor (0.19.1)
143
+ thread_safe (0.3.3)
144
+ tilt (1.4.1)
145
+ treetop (1.4.15)
146
+ polyglot
147
+ polyglot (>= 0.3.1)
148
+ tzinfo (1.1.0)
149
+ thread_safe (~> 0.1)
150
+
151
+ PLATFORMS
152
+ ruby
153
+
154
+ DEPENDENCIES
155
+ activerecord-jdbc-adapter
156
+ activerecord-jdbcsqlite3-adapter
157
+ activeresource (= 4.0.0)
158
+ appraisal (~> 1.0.0.beta2)
159
+ aruba
160
+ bcrypt-ruby (~> 3.1.2)
161
+ bourne (~> 1.3)
162
+ bundler (~> 1.1)
163
+ cucumber (~> 1.1)
164
+ jdbc-sqlite3
165
+ jquery-rails
166
+ jruby-openssl
167
+ protected_attributes (~> 1.0.6)
168
+ pry
169
+ rails (~> 4.1.0)
170
+ rake (>= 0.9.2)
171
+ rspec-rails (>= 2.13.1, < 3)
172
+ sass-rails (= 4.0.3)
173
+ shoulda-context (~> 1.2.0)
174
+ shoulda-matchers!
175
+ sqlite3
176
+ therubyrhino
@@ -1,6 +1,22 @@
1
- require 'shoulda/matchers/version'
2
1
  require 'shoulda/matchers/assertion_error'
2
+ require 'shoulda/matchers/error'
3
3
  require 'shoulda/matchers/rails_shim'
4
+ require 'shoulda/matchers/warn'
5
+ require 'shoulda/matchers/version'
6
+
7
+ require 'shoulda/matchers/independent'
8
+
9
+ if defined?(ActiveModel)
10
+ require 'shoulda/matchers/active_model'
11
+ end
12
+
13
+ if defined?(ActiveRecord)
14
+ require 'shoulda/matchers/active_record'
15
+ end
16
+
17
+ if defined?(ActionController)
18
+ require 'shoulda/matchers/action_controller'
19
+ end
4
20
 
5
21
  if defined?(RSpec)
6
22
  require 'shoulda/matchers/integrations/rspec'
@@ -8,6 +8,8 @@ require 'shoulda/matchers/action_controller/route_matcher'
8
8
  require 'shoulda/matchers/action_controller/redirect_to_matcher'
9
9
  require 'shoulda/matchers/action_controller/render_template_matcher'
10
10
  require 'shoulda/matchers/action_controller/rescue_from_matcher'
11
+ require 'shoulda/matchers/action_controller/callback_matcher'
12
+ require 'shoulda/matchers/action_controller/strong_parameters_matcher'
11
13
 
12
14
  module Shoulda
13
15
  module Matchers
@@ -18,7 +20,7 @@ module Shoulda
18
20
  #
19
21
  # describe UsersController, 'on GET to show with a valid id' do
20
22
  # before(:each) do
21
- # get :show, :id => User.first.to_param
23
+ # get :show, id: User.first.to_param
22
24
  # end
23
25
  #
24
26
  # it { should respond_with(:success) }
@@ -26,7 +28,7 @@ module Shoulda
26
28
  # it { should not_set_the_flash) }
27
29
  #
28
30
  # it 'does something else really cool' do
29
- # assigns[:user].id.should == 1
31
+ # expect(assigns[:user].id).to eq 1
30
32
  # end
31
33
  # end
32
34
  #
@@ -0,0 +1,100 @@
1
+ module Shoulda # :nodoc:
2
+ module Matchers
3
+ module ActionController # :nodoc:
4
+ # Ensure a controller uses a given before_filter
5
+ #
6
+ # Example:
7
+ #
8
+ # it { should use_before_filter(:authenticate_user!) }
9
+ # it { should_not use_before_filter(:prevent_ssl) }
10
+ def use_before_filter(callback)
11
+ CallbackMatcher.new(callback, :before, :filter)
12
+ end
13
+
14
+ # Ensure a controller uses a given before_filter
15
+ #
16
+ # Example:
17
+ #
18
+ # it { should use_after_filter(:log_activity) }
19
+ # it { should_not use_after_filter(:destroy_user) }
20
+ def use_after_filter(callback)
21
+ CallbackMatcher.new(callback, :after, :filter)
22
+ end
23
+
24
+ # Ensure a controller uses a given before_action
25
+ #
26
+ # Example:
27
+ #
28
+ # it { should use_before_action(:authenticate_user!) }
29
+ # it { should_not use_before_action(:prevent_ssl) }
30
+ def use_before_action(callback)
31
+ CallbackMatcher.new(callback, :before, :action)
32
+ end
33
+
34
+ # Ensure a controller uses a given after_action
35
+ #
36
+ # Example:
37
+ #
38
+ # it { should use_after_action(:log_activity) }
39
+ # it { should_not use_after_action(:destroy_user) }
40
+ def use_after_action(callback)
41
+ CallbackMatcher.new(callback, :after, :action)
42
+ end
43
+
44
+ # Ensure a controller uses a given around_filter
45
+ #
46
+ # Example:
47
+ #
48
+ # it { should use_around_filter(:log_activity) }
49
+ # it { should_not use_around_filter(:destroy_user) }
50
+ def use_around_filter(callback)
51
+ CallbackMatcher.new(callback, :around, :filter)
52
+ end
53
+
54
+ # Ensure a controller uses a given around_action
55
+ #
56
+ # Example:
57
+ #
58
+ # it { should use_around_action(:log_activity) }
59
+ # it { should_not use_around_action(:destroy_user) }
60
+ def use_around_action(callback)
61
+ CallbackMatcher.new(callback, :around, :action)
62
+ end
63
+
64
+ class CallbackMatcher # :nodoc:
65
+ def initialize(method_name, kind, callback_type)
66
+ @method_name = method_name
67
+ @kind = kind
68
+ @callback_type = callback_type
69
+ end
70
+
71
+ def matches?(subject)
72
+ @subject = subject
73
+ callbacks.map(&:filter).include?(method_name)
74
+ end
75
+
76
+ def failure_message
77
+ "Expected that #{subject.name} would have :#{method_name} as a #{kind}_#{callback_type}"
78
+ end
79
+ alias failure_message_for_should failure_message
80
+
81
+ def failure_message_when_negated
82
+ "Expected that #{subject.name} would not have :#{method_name} as a #{kind}_#{callback_type}"
83
+ end
84
+ alias failure_message_for_should_not failure_message_when_negated
85
+
86
+ def description
87
+ "have :#{method_name} as a #{kind}_#{callback_type}"
88
+ end
89
+
90
+ private
91
+
92
+ def callbacks
93
+ subject._process_action_callbacks.select { |callback| callback.kind == kind }
94
+ end
95
+
96
+ attr_reader :method_name, :subject, :kind, :callback_type
97
+ end
98
+ end
99
+ end
100
+ end