shoulda-matchers 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/.travis.yml +11 -3
  2. data/Appraisals +3 -3
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +69 -70
  5. data/MIT-LICENSE +1 -1
  6. data/NEWS.md +22 -4
  7. data/README.md +3 -1
  8. data/Rakefile +9 -5
  9. data/features/step_definitions/rails_steps.rb +7 -7
  10. data/features/support/env.rb +1 -1
  11. data/gemfiles/3.0.gemfile +1 -1
  12. data/gemfiles/3.0.gemfile.lock +25 -22
  13. data/gemfiles/3.1.gemfile +1 -1
  14. data/gemfiles/3.1.gemfile.lock +27 -24
  15. data/gemfiles/3.2.gemfile +1 -1
  16. data/gemfiles/3.2.gemfile.lock +56 -52
  17. data/lib/shoulda/matchers/action_controller.rb +3 -2
  18. data/lib/shoulda/matchers/action_controller/assign_to_matcher.rb +10 -8
  19. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +2 -4
  20. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +3 -4
  21. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +3 -4
  22. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +6 -6
  23. data/lib/shoulda/matchers/action_controller/respond_with_content_type_matcher.rb +5 -2
  24. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +2 -2
  25. data/lib/shoulda/matchers/action_controller/route_matcher.rb +12 -12
  26. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -4
  27. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +10 -11
  28. data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +121 -0
  29. data/lib/shoulda/matchers/action_mailer/have_sent_email_matcher.rb +7 -4
  30. data/lib/shoulda/matchers/active_model.rb +1 -1
  31. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +8 -8
  32. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +5 -4
  33. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +3 -3
  34. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +2 -2
  35. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +0 -1
  36. data/lib/shoulda/matchers/active_model/helpers.rb +16 -7
  37. data/lib/shoulda/matchers/active_model/only_integer_matcher.rb +3 -3
  38. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +8 -6
  39. data/lib/shoulda/matchers/active_model/validate_format_of_matcher.rb +19 -10
  40. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +4 -4
  41. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +19 -21
  42. data/lib/shoulda/matchers/active_model/validation_matcher.rb +7 -7
  43. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +1 -1
  44. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +5 -5
  45. data/lib/shoulda/matchers/active_record/association_matcher.rb +3 -3
  46. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +11 -7
  47. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +2 -2
  48. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +5 -5
  49. data/lib/shoulda/matchers/active_record/query_the_database_matcher.rb +5 -2
  50. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +3 -3
  51. data/lib/shoulda/matchers/assertion_error.rb +4 -1
  52. data/lib/shoulda/matchers/independent/delegate_matcher.rb +17 -7
  53. data/lib/shoulda/matchers/integrations/rspec.rb +19 -33
  54. data/lib/shoulda/matchers/version.rb +1 -1
  55. data/shoulda-matchers.gemspec +6 -4
  56. data/spec/shoulda/matchers/action_controller/assign_to_matcher_spec.rb +66 -0
  57. data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +22 -0
  58. data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +42 -0
  59. data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +78 -0
  60. data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +58 -0
  61. data/spec/shoulda/matchers/action_controller/respond_with_content_type_matcher_spec.rb +31 -0
  62. data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +31 -0
  63. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +65 -0
  64. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +51 -0
  65. data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +153 -0
  66. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +142 -0
  67. data/spec/shoulda/matchers/action_mailer/have_sent_email_spec.rb +324 -0
  68. data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +111 -0
  69. data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +124 -0
  70. data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +43 -0
  71. data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +74 -0
  72. data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +171 -0
  73. data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +113 -0
  74. data/spec/shoulda/{active_model → matchers/active_model}/exception_message_finder_spec.rb +2 -2
  75. data/spec/shoulda/matchers/active_model/helpers_spec.rb +158 -0
  76. data/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb +52 -0
  77. data/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +41 -0
  78. data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +41 -0
  79. data/spec/shoulda/matchers/active_model/validate_format_of_matcher_spec.rb +75 -0
  80. data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +73 -0
  81. data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +127 -0
  82. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +175 -0
  83. data/spec/shoulda/{active_model → matchers/active_model}/validation_message_finder_spec.rb +0 -1
  84. data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +106 -0
  85. data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +534 -0
  86. data/spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +111 -0
  87. data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +78 -0
  88. data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +41 -0
  89. data/spec/shoulda/{active_record → matchers/active_record}/query_the_database_matcher_spec.rb +10 -10
  90. data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +86 -0
  91. data/spec/shoulda/{independent → matchers/independent}/delegate_matcher_spec.rb +55 -34
  92. data/spec/spec_helper.rb +1 -2
  93. data/spec/support/active_model_versions.rb +4 -0
  94. data/spec/support/activemodel_helpers.rb +19 -0
  95. data/spec/support/controller_builder.rb +38 -12
  96. data/spec/support/model_builder.rb +8 -2
  97. metadata +106 -98
  98. data/spec/fixtures/addresses.yml +0 -3
  99. data/spec/fixtures/friendships.yml +0 -0
  100. data/spec/fixtures/posts.yml +0 -5
  101. data/spec/fixtures/products.yml +0 -0
  102. data/spec/fixtures/taggings.yml +0 -0
  103. data/spec/fixtures/tags.yml +0 -9
  104. data/spec/fixtures/users.yml +0 -6
  105. data/spec/shoulda/action_controller/assign_to_matcher_spec.rb +0 -63
  106. data/spec/shoulda/action_controller/filter_param_matcher_spec.rb +0 -20
  107. data/spec/shoulda/action_controller/redirect_to_matcher_spec.rb +0 -40
  108. data/spec/shoulda/action_controller/render_template_matcher_spec.rb +0 -69
  109. data/spec/shoulda/action_controller/render_with_layout_matcher_spec.rb +0 -55
  110. data/spec/shoulda/action_controller/respond_with_content_type_matcher_spec.rb +0 -28
  111. data/spec/shoulda/action_controller/respond_with_matcher_spec.rb +0 -83
  112. data/spec/shoulda/action_controller/route_matcher_spec.rb +0 -65
  113. data/spec/shoulda/action_controller/set_session_matcher_spec.rb +0 -46
  114. data/spec/shoulda/action_controller/set_the_flash_matcher_spec.rb +0 -130
  115. data/spec/shoulda/action_mailer/have_sent_email_spec.rb +0 -333
  116. data/spec/shoulda/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -115
  117. data/spec/shoulda/active_model/allow_value_matcher_spec.rb +0 -131
  118. data/spec/shoulda/active_model/disallow_value_matcher_spec.rb +0 -65
  119. data/spec/shoulda/active_model/ensure_exclusion_of_matcher_spec.rb +0 -79
  120. data/spec/shoulda/active_model/ensure_inclusion_of_matcher_spec.rb +0 -181
  121. data/spec/shoulda/active_model/ensure_length_of_matcher_spec.rb +0 -138
  122. data/spec/shoulda/active_model/helpers_spec.rb +0 -129
  123. data/spec/shoulda/active_model/only_integer_matcher_spec.rb +0 -69
  124. data/spec/shoulda/active_model/validate_acceptance_of_matcher_spec.rb +0 -43
  125. data/spec/shoulda/active_model/validate_confirmation_of_matcher_spec.rb +0 -48
  126. data/spec/shoulda/active_model/validate_format_of_matcher_spec.rb +0 -79
  127. data/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb +0 -112
  128. data/spec/shoulda/active_model/validate_presence_of_matcher_spec.rb +0 -135
  129. data/spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb +0 -154
  130. data/spec/shoulda/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -84
  131. data/spec/shoulda/active_record/association_matcher_spec.rb +0 -642
  132. data/spec/shoulda/active_record/have_db_column_matcher_spec.rb +0 -185
  133. data/spec/shoulda/active_record/have_db_index_matcher_spec.rb +0 -105
  134. data/spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb +0 -46
  135. data/spec/shoulda/active_record/serialize_matcher_spec.rb +0 -81
@@ -1,7 +1,6 @@
1
1
  module Shoulda # :nodoc:
2
2
  module Matchers
3
3
  module ActionController # :nodoc:
4
-
5
4
  # Ensures a controller redirected to the given url.
6
5
  #
7
6
  # Example:
@@ -13,7 +12,7 @@ module Shoulda # :nodoc:
13
12
  end
14
13
 
15
14
  class RedirectToMatcher # :nodoc:
16
- attr_reader :failure_message, :negative_failure_message
15
+ attr_reader :failure_message_for_should, :failure_message_for_should_not
17
16
 
18
17
  def initialize(url_or_description, context, &block)
19
18
  if block
@@ -45,10 +44,10 @@ module Shoulda # :nodoc:
45
44
  def redirects_to_url?
46
45
  begin
47
46
  @context.send(:assert_redirected_to, url)
48
- @negative_failure_message = "Didn't expect to redirect to #{url}"
47
+ @failure_message_for_should_not = "Didn't expect to redirect to #{url}"
49
48
  true
50
49
  rescue Shoulda::Matchers::AssertionError => error
51
- @failure_message = error.message
50
+ @failure_message_for_should = error.message
52
51
  false
53
52
  end
54
53
  end
@@ -1,7 +1,6 @@
1
1
  module Shoulda # :nodoc:
2
2
  module Matchers
3
3
  module ActionController # :nodoc:
4
-
5
4
  # Ensures a controller rendered the given template.
6
5
  #
7
6
  # Example:
@@ -21,7 +20,7 @@ module Shoulda # :nodoc:
21
20
  end
22
21
 
23
22
  class RenderTemplateMatcher # :nodoc:
24
- attr_reader :failure_message, :negative_failure_message
23
+ attr_reader :failure_message_for_should, :failure_message_for_should_not
25
24
 
26
25
  def initialize(options, message, context)
27
26
  @options = options
@@ -49,10 +48,10 @@ module Shoulda # :nodoc:
49
48
  def renders_template?
50
49
  begin
51
50
  @context.send(:assert_template, @options, @message)
52
- @negative_failure_message = "Didn't expect to render #{@template}"
51
+ @failure_message_for_should_not = "Didn't expect to render #{@template}"
53
52
  true
54
53
  rescue Shoulda::Matchers::AssertionError => error
55
- @failure_message = error.message
54
+ @failure_message_for_should = error.message
56
55
  false
57
56
  end
58
57
  end
@@ -33,18 +33,18 @@ module Shoulda # :nodoc:
33
33
  rendered_with_layout? && rendered_with_expected_layout?
34
34
  end
35
35
 
36
- def failure_message
36
+ def failure_message_for_should
37
37
  "Expected #{expectation}, but #{result}"
38
38
  end
39
39
 
40
- def negative_failure_message
40
+ def failure_message_for_should_not
41
41
  "Did not expect #{expectation}, but #{result}"
42
42
  end
43
43
 
44
44
  def description
45
- description = "render with "
45
+ description = 'render with '
46
46
  if @expected_layout.nil?
47
- description << "a layout"
47
+ description << 'a layout'
48
48
  else
49
49
  description << "the #{@expected_layout.inspect} layout"
50
50
  end
@@ -83,9 +83,9 @@ module Shoulda # :nodoc:
83
83
 
84
84
  def result
85
85
  if rendered_with_layout?
86
- "rendered with " + rendered_layouts.map(&:inspect).join(", ")
86
+ 'rendered with ' + rendered_layouts.map(&:inspect).join(', ')
87
87
  else
88
- "rendered without a layout"
88
+ 'rendered without a layout'
89
89
  end
90
90
  end
91
91
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support/deprecation'
2
+
1
3
  module Shoulda # :nodoc:
2
4
  module Matchers
3
5
  module ActionController # :nodoc:
@@ -23,6 +25,7 @@ module Shoulda # :nodoc:
23
25
 
24
26
  class RespondWithContentTypeMatcher # :nodoc:
25
27
  def initialize(content_type)
28
+ ActiveSupport::Deprecation.warn 'The respond_with_content_type matcher is deprecated and will be removed in 2.0'
26
29
  @content_type = look_up_content_type(content_type)
27
30
  end
28
31
 
@@ -35,11 +38,11 @@ module Shoulda # :nodoc:
35
38
  content_type_matches_regexp? || content_type_matches_string?
36
39
  end
37
40
 
38
- def failure_message
41
+ def failure_message_for_should
39
42
  "Expected #{expectation}"
40
43
  end
41
44
 
42
- def negative_failure_message
45
+ def failure_message_for_should_not
43
46
  "Did not expect #{expectation}"
44
47
  end
45
48
 
@@ -30,11 +30,11 @@ module Shoulda # :nodoc:
30
30
  correct_status_code? || correct_status_code_range?
31
31
  end
32
32
 
33
- def failure_message
33
+ def failure_message_for_should
34
34
  "Expected #{expectation}"
35
35
  end
36
36
 
37
- def negative_failure_message
37
+ def failure_message_for_should_not
38
38
  "Did not expect #{expectation}"
39
39
  end
40
40
 
@@ -11,16 +11,16 @@ module Shoulda # :nodoc:
11
11
  #
12
12
  # Examples:
13
13
  #
14
- # it { should route(:get, "/posts").
14
+ # it { should route(:get, '/posts').
15
15
  # to(:controller => :posts, :action => :index) }
16
- # it { should route(:get, "/posts/new").to(:action => :new) }
17
- # it { should route(:post, "/posts").to(:action => :create) }
18
- # it { should route(:get, "/posts/1").to(:action => :show, :id => 1) }
19
- # it { should route(:get, "/posts/1/edit").to(:action => :edit, :id => 1) }
20
- # it { should route(:put, "/posts/1").to(:action => :update, :id => 1) }
21
- # it { should route(:delete, "/posts/1").
16
+ # it { should route(:get, '/posts/new').to(:action => :new) }
17
+ # it { should route(:post, '/posts').to(:action => :create) }
18
+ # it { should route(:get, '/posts/1').to(:action => :show, :id => 1) }
19
+ # it { should route(:get, '/posts/1/edit').to(:action => :edit, :id => 1) }
20
+ # it { should route(:put, '/posts/1').to(:action => :update, :id => 1) }
21
+ # it { should route(:delete, '/posts/1').
22
22
  # to(:action => :destroy, :id => 1) }
23
- # it { should route(:get, "/users/1/posts/1").
23
+ # it { should route(:get, '/users/1/posts/1').
24
24
  # to(:action => :show, :id => 1, :user_id => 1) }
25
25
  def route(method, path)
26
26
  RouteMatcher.new(method, path, self)
@@ -33,7 +33,7 @@ module Shoulda # :nodoc:
33
33
  @context = context
34
34
  end
35
35
 
36
- attr_reader :failure_message, :negative_failure_message
36
+ attr_reader :failure_message_for_should, :failure_message_for_should_not
37
37
 
38
38
  def to(params)
39
39
  @params = stringify_params(params)
@@ -80,13 +80,13 @@ module Shoulda # :nodoc:
80
80
  { :method => @method, :path => @path },
81
81
  @params)
82
82
 
83
- @negative_failure_message = "Didn't expect to #{description}"
83
+ @failure_message_for_should_not = "Didn't expect to #{description}"
84
84
  true
85
85
  rescue ::ActionController::RoutingError => error
86
- @failure_message = error.message
86
+ @failure_message_for_should = error.message
87
87
  false
88
88
  rescue Shoulda::Matchers::AssertionError => error
89
- @failure_message = error.message
89
+ @failure_message_for_should = error.message
90
90
  false
91
91
  end
92
92
  end
@@ -32,11 +32,11 @@ module Shoulda # :nodoc:
32
32
  assigned_correct_value? || cleared_value?
33
33
  end
34
34
 
35
- def failure_message
35
+ def failure_message_for_should
36
36
  "Expected #{expectation}, but #{result}"
37
37
  end
38
38
 
39
- def negative_failure_message
39
+ def failure_message_for_should_not
40
40
  "Didn't expect #{expectation}, but #{result}"
41
41
  end
42
42
 
@@ -82,12 +82,11 @@ module Shoulda # :nodoc:
82
82
  if @value
83
83
  expectation << " to #{@value.inspect}"
84
84
  end
85
- expectation
86
85
  end
87
86
 
88
87
  def result
89
88
  if session.empty?
90
- "no session variables were set"
89
+ 'no session variables were set'
91
90
  else
92
91
  "the session was #{session.inspect}"
93
92
  end
@@ -8,9 +8,9 @@ module Shoulda # :nodoc:
8
8
  # Example:
9
9
  #
10
10
  # it { should set_the_flash }
11
- # it { should set_the_flash.to("Thank you for placing this order.") }
11
+ # it { should set_the_flash.to('Thank you for placing this order.') }
12
12
  # it { should set_the_flash.to(/created/i) }
13
- # it { should set_the_flash[:alert].to("Password doesn't match") }
13
+ # it { should set_the_flash[:alert].to('Password does not match') }
14
14
  # it { should set_the_flash.to(/logged in/i).now }
15
15
  # it { should_not set_the_flash }
16
16
  def set_the_flash
@@ -22,8 +22,6 @@ module Shoulda # :nodoc:
22
22
  @options = {}
23
23
  end
24
24
 
25
- attr_reader :failure_message, :negative_failure_message
26
-
27
25
  def to(value)
28
26
  if !value.is_a?(String) && !value.is_a?(Regexp)
29
27
  raise "cannot match against #{value.inspect}"
@@ -53,11 +51,11 @@ module Shoulda # :nodoc:
53
51
  description
54
52
  end
55
53
 
56
- def failure_message
54
+ def failure_message_for_should
57
55
  "Expected #{expectation}"
58
56
  end
59
57
 
60
- def negative_failure_message
58
+ def failure_message_for_should_not
61
59
  "Did not expect #{expectation}"
62
60
  end
63
61
 
@@ -96,7 +94,8 @@ module Shoulda # :nodoc:
96
94
  @flash
97
95
  else
98
96
  @flash = @controller.flash.dup
99
- @flash.instance_variable_set(:@used, @controller.flash.instance_variable_get(:@used).dup)
97
+ used = @controller.flash.instance_variable_get(:@used).dup
98
+ @flash.instance_variable_set(:@used, used)
100
99
  sweep_flash_if_necessary
101
100
  @flash
102
101
  end
@@ -117,7 +116,7 @@ module Shoulda # :nodoc:
117
116
 
118
117
  def flash_description
119
118
  if flash.blank?
120
- "no flash was set"
119
+ 'no flash was set'
121
120
  else
122
121
  "was #{flash.inspect}"
123
122
  end
@@ -129,9 +128,9 @@ module Shoulda # :nodoc:
129
128
 
130
129
  def pretty_now
131
130
  if @options[:now]
132
- ".now"
131
+ '.now'
133
132
  else
134
- ""
133
+ ''
135
134
  end
136
135
  end
137
136
 
@@ -139,7 +138,7 @@ module Shoulda # :nodoc:
139
138
  if @options[:key]
140
139
  "[:#{@options[:key]}]"
141
140
  else
142
- ""
141
+ ''
143
142
  end
144
143
  end
145
144
  end
@@ -0,0 +1,121 @@
1
+ require 'bourne'
2
+ require 'active_support/deprecation'
3
+ begin
4
+ require 'strong_parameters'
5
+ rescue LoadError
6
+ end
7
+
8
+ module Shoulda
9
+ module Matchers
10
+ module ActionController
11
+ def permit(*attributes)
12
+ attributes_and_context = attributes + [self]
13
+ StrongParametersMatcher.new(*attributes_and_context)
14
+ end
15
+
16
+ class StrongParametersMatcher
17
+ def initialize(*attributes_and_context)
18
+ ActiveSupport::Deprecation.warn 'The strong_parameters matcher is deprecated and will be removed in 2.0'
19
+ @attributes = attributes_and_context[0...-1]
20
+ @context = attributes_and_context.last
21
+ @permitted_params = []
22
+ end
23
+
24
+ def for(action, options = {})
25
+ @action = action
26
+ @verb = options[:verb] || verb_for_action
27
+ self
28
+ end
29
+
30
+ def in_context(context)
31
+ @context = context
32
+ self
33
+ end
34
+
35
+ def matches?(controller = nil)
36
+ simulate_controller_action && parameters_difference.empty?
37
+ end
38
+
39
+ def does_not_match?(controller = nil)
40
+ simulate_controller_action && parameters_difference.present?
41
+ end
42
+
43
+ def failure_message
44
+ "Expected controller to permit #{parameters_difference.to_sentence}, but it did not."
45
+ end
46
+
47
+ def negative_failure_message
48
+ "Expected controller not to permit #{parameters_difference.to_sentence}, but it did."
49
+ end
50
+
51
+ private
52
+ attr_reader :verb, :action, :attributes, :context
53
+ attr_accessor :permitted_params
54
+
55
+ def simulate_controller_action
56
+ ensure_action_and_verb_present!
57
+ model_attrs = stubbed_model_attributes
58
+
59
+ context.send(verb, action)
60
+
61
+ verify_permit_call(model_attrs)
62
+ end
63
+
64
+ def verify_permit_call(model_attrs)
65
+ matcher = Mocha::API::HaveReceived.new(:permit).with do |*params|
66
+ self.permitted_params = params
67
+ end
68
+
69
+ matcher.matches?(model_attrs)
70
+ rescue Mocha::ExpectationError
71
+ false
72
+ end
73
+
74
+ def parameters_difference
75
+ attributes - permitted_params
76
+ end
77
+
78
+ def stubbed_model_attributes
79
+ extend Mocha::API
80
+
81
+ model_attrs = ::ActionController::Parameters.new(arbitrary_attributes)
82
+ model_attrs.stubs(:permit)
83
+ ::ActionController::Parameters.any_instance.stubs(:[]).returns(model_attrs)
84
+
85
+ model_attrs
86
+ end
87
+
88
+ def ensure_action_and_verb_present!
89
+ if action.blank?
90
+ raise ActionNotDefinedError
91
+ end
92
+ if verb.blank?
93
+ raise VerbNotDefinedError
94
+ end
95
+ end
96
+
97
+ def arbitrary_attributes
98
+ {:any_key => 'any_value'}
99
+ end
100
+
101
+ def verb_for_action
102
+ verb_lookup = { :create => :post, :update => :put }
103
+ verb_lookup[action]
104
+ end
105
+ end
106
+
107
+ class StrongParametersMatcher::ActionNotDefinedError < StandardError
108
+ def message
109
+ 'You must specify the controller action using the #for method.'
110
+ end
111
+ end
112
+
113
+ class StrongParametersMatcher::VerbNotDefinedError < StandardError
114
+ def message
115
+ 'You must specify an HTTP verb when using a non-RESTful action.' +
116
+ ' e.g. for(:authorize, :verb => :post)'
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -1,3 +1,5 @@
1
+ require 'active_support/deprecation'
2
+
1
3
  module Shoulda # :nodoc:
2
4
  module Matchers
3
5
  module ActionMailer # :nodoc:
@@ -24,6 +26,7 @@ module Shoulda # :nodoc:
24
26
  class HaveSentEmailMatcher # :nodoc:
25
27
 
26
28
  def initialize(context)
29
+ ActiveSupport::Deprecation.warn 'The have_sent_email matcher is deprecated and will be removed in 2.0'
27
30
  @context = context
28
31
  end
29
32
 
@@ -106,16 +109,16 @@ module Shoulda # :nodoc:
106
109
  end
107
110
  end
108
111
 
109
- def failure_message
112
+ def failure_message_for_should
110
113
  "Expected #{expectation}"
111
114
  end
112
115
 
113
- def negative_failure_message
116
+ def failure_message_for_should_not
114
117
  "Did not expect #{expectation}"
115
118
  end
116
119
 
117
120
  def description
118
- description = "send an email"
121
+ description = 'send an email'
119
122
  description << " with a subject of #{@email_subject.inspect}" if @email_subject
120
123
  description << " containing #{@body.inspect}" if @body
121
124
  if @parts
@@ -136,7 +139,7 @@ module Shoulda # :nodoc:
136
139
  private
137
140
 
138
141
  def expectation
139
- expectation = "sent email"
142
+ expectation = 'sent email'
140
143
  expectation << " with subject #{@email_subject.inspect}" if @subject_failed
141
144
  expectation << " with body #{@body.inspect}" if @body_failed
142
145
  @parts.each do |_, body, content_type|