mcmire-shoulda-matchers 2.5.0 → 2.6.1.docs.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -0
  4. data/.yardopts +2 -1
  5. data/Appraisals +62 -22
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +3 -3
  8. data/NEWS.md +87 -4
  9. data/README.md +2 -2
  10. data/Rakefile +18 -0
  11. data/features/activemodel_integration.feature +15 -0
  12. data/features/rails_integration.feature +1 -1
  13. data/features/step_definitions/activemodel_steps.rb +21 -0
  14. data/features/step_definitions/rails_steps.rb +5 -4
  15. data/gemfiles/3.0.gemfile +6 -3
  16. data/gemfiles/3.0.gemfile.lock +14 -4
  17. data/gemfiles/3.1.gemfile +10 -4
  18. data/gemfiles/3.1.gemfile.lock +32 -5
  19. data/gemfiles/3.1_1.9.2.gemfile +21 -0
  20. data/gemfiles/3.1_1.9.2.gemfile.lock +191 -0
  21. data/gemfiles/3.2.gemfile +9 -4
  22. data/gemfiles/3.2.gemfile.lock +28 -5
  23. data/gemfiles/4.0.0.gemfile +11 -3
  24. data/gemfiles/4.0.0.gemfile.lock +42 -5
  25. data/gemfiles/4.0.1.gemfile +11 -3
  26. data/gemfiles/4.0.1.gemfile.lock +42 -5
  27. data/gemfiles/4.1.gemfile +37 -0
  28. data/gemfiles/4.1.gemfile.lock +216 -0
  29. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +202 -0
  30. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
  31. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +2 -1
  32. data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +165 -0
  33. data/lib/shoulda/matchers/action_controller.rb +2 -0
  34. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +26 -4
  35. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +6 -0
  36. data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +2 -0
  37. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +60 -18
  38. data/lib/shoulda/matchers/active_model/errors.rb +43 -1
  39. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +14 -3
  40. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +2 -1
  41. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +100 -45
  42. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +38 -5
  43. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +27 -20
  44. data/lib/shoulda/matchers/active_record/association_matcher.rb +12 -2
  45. data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +41 -0
  46. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +24 -1
  47. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +1 -1
  48. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
  49. data/lib/shoulda/matchers/active_record.rb +1 -0
  50. data/lib/shoulda/matchers/assertion_error.rb +8 -3
  51. data/lib/shoulda/matchers/doublespeak/double.rb +75 -0
  52. data/lib/shoulda/matchers/doublespeak/double_collection.rb +55 -0
  53. data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +28 -0
  54. data/lib/shoulda/matchers/doublespeak/object_double.rb +33 -0
  55. data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +31 -0
  56. data/lib/shoulda/matchers/doublespeak/structs.rb +10 -0
  57. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +35 -0
  58. data/lib/shoulda/matchers/doublespeak/world.rb +39 -0
  59. data/lib/shoulda/matchers/doublespeak.rb +28 -0
  60. data/lib/shoulda/matchers/error.rb +20 -1
  61. data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +35 -0
  62. data/lib/shoulda/matchers/independent/delegate_matcher.rb +293 -0
  63. data/lib/shoulda/matchers/independent.rb +10 -0
  64. data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +38 -0
  65. data/lib/shoulda/matchers/integrations/rspec.rb +13 -14
  66. data/lib/shoulda/matchers/integrations/test_unit.rb +19 -15
  67. data/lib/shoulda/matchers/integrations.rb +13 -0
  68. data/lib/shoulda/matchers/rails_shim.rb +16 -0
  69. data/lib/shoulda/matchers/version.rb +1 -1
  70. data/lib/shoulda/matchers.rb +15 -3
  71. data/spec/shoulda/matchers/action_controller/callback_matcher_spec.rb +82 -0
  72. data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +2 -2
  73. data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +5 -5
  74. data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +4 -4
  75. data/spec/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +38 -11
  76. data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +1 -1
  77. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +1 -1
  78. data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +6 -6
  79. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +314 -0
  80. data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +32 -0
  81. data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +553 -211
  82. data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +22 -0
  83. data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +38 -0
  84. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +42 -36
  85. data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +15 -1
  86. data/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +4 -0
  87. data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +4 -0
  88. data/spec/shoulda/matchers/doublespeak/double_collection_spec.rb +102 -0
  89. data/spec/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +21 -0
  90. data/spec/shoulda/matchers/doublespeak/double_spec.rb +144 -0
  91. data/spec/shoulda/matchers/doublespeak/object_double_spec.rb +77 -0
  92. data/spec/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +40 -0
  93. data/spec/shoulda/matchers/doublespeak/stub_implementation_spec.rb +88 -0
  94. data/spec/shoulda/matchers/doublespeak/world_spec.rb +88 -0
  95. data/spec/shoulda/matchers/doublespeak_spec.rb +19 -0
  96. data/spec/shoulda/matchers/independent/delegate_matcher/stubbed_target_spec.rb +43 -0
  97. data/spec/shoulda/matchers/independent/delegate_matcher_spec.rb +250 -0
  98. data/spec/spec_helper.rb +15 -0
  99. data/spec/support/activemodel_helpers.rb +6 -2
  100. data/spec/support/controller_builder.rb +29 -1
  101. data/spec/support/rails_versions.rb +4 -0
  102. data/spec/support/test_application.rb +1 -1
  103. metadata +59 -10
@@ -0,0 +1,38 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Integrations
4
+ # @private
5
+ module NUnitTestCaseDetection
6
+ def self.possible_test_case_constants
7
+ [
8
+ -> { ActiveSupport::TestCase },
9
+ -> { Minitest::Test },
10
+ -> { MiniTest::Unit::TestCase },
11
+ -> { Test::Unit::TestCase }
12
+ ]
13
+ end
14
+
15
+ def self.resolve_constant(future_constant)
16
+ future_constant.call
17
+ rescue NameError
18
+ nil
19
+ end
20
+
21
+ def self.detected_test_case_constants
22
+ possible_test_case_constants.
23
+ map { |future_constant| resolve_constant(future_constant) }.
24
+ compact
25
+ end
26
+
27
+ def self.test_case_constants
28
+ @_test_case_constants ||= detected_test_case_constants
29
+ end
30
+ end
31
+ end
32
+
33
+ # @private
34
+ def self.nunit_test_case_constants
35
+ Integrations::NUnitTestCaseDetection.test_case_constants
36
+ end
37
+ end
38
+ end
@@ -1,20 +1,19 @@
1
1
  # :enddoc:
2
- require 'rspec/core'
3
2
 
4
- RSpec.configure do |config|
5
- if defined?(::ActiveRecord)
6
- require 'shoulda/matchers/active_record'
7
- require 'shoulda/matchers/active_model'
8
- config.include Shoulda::Matchers::ActiveRecord
9
- config.include Shoulda::Matchers::ActiveModel
3
+ if RSpec.respond_to?(:configure)
4
+ RSpec.configure do |config|
5
+ config.include Shoulda::Matchers::Independent
10
6
 
11
- elsif defined?(::ActiveModel)
12
- require 'shoulda/matchers/active_model'
13
- config.include Shoulda::Matchers::ActiveModel
14
- end
7
+ if defined?(ActiveRecord)
8
+ config.include Shoulda::Matchers::ActiveRecord
9
+ end
10
+
11
+ if defined?(ActiveModel)
12
+ config.include Shoulda::Matchers::ActiveModel
13
+ end
15
14
 
16
- if defined?(::ActionController)
17
- require 'shoulda/matchers/action_controller'
18
- config.include Shoulda::Matchers::ActionController
15
+ if defined?(ActionController)
16
+ config.include Shoulda::Matchers::ActionController
17
+ end
19
18
  end
20
19
  end
@@ -1,6 +1,14 @@
1
- if defined?(ActionController) && defined?(ActionController::TestCase)
2
- require 'shoulda/matchers/action_controller'
1
+ # :enddoc:
2
+ require 'shoulda/matchers/integrations/nunit_test_case_detection'
3
3
 
4
+ Shoulda::Matchers.nunit_test_case_constants.each do |constant|
5
+ constant.class_eval do
6
+ include Shoulda::Matchers::Independent
7
+ extend Shoulda::Matchers::Independent
8
+ end
9
+ end
10
+
11
+ if defined?(ActionController::TestCase)
4
12
  ActionController::TestCase.class_eval do
5
13
  include Shoulda::Matchers::ActionController
6
14
  extend Shoulda::Matchers::ActionController
@@ -11,20 +19,16 @@ if defined?(ActionController) && defined?(ActionController::TestCase)
11
19
  end
12
20
  end
13
21
 
14
- if defined?(ActiveRecord) && defined?(ActiveSupport::TestCase)
15
- require 'shoulda/matchers/active_record'
16
-
22
+ if defined?(ActiveSupport::TestCase)
17
23
  ActiveSupport::TestCase.class_eval do
18
- include Shoulda::Matchers::ActiveRecord
19
- extend Shoulda::Matchers::ActiveRecord
20
- end
21
- end
22
-
23
- if defined?(ActiveModel) && defined?(ActiveSupport::TestCase)
24
- require 'shoulda/matchers/active_model'
24
+ if defined?(Shoulda::Matchers::ActiveRecord)
25
+ include Shoulda::Matchers::ActiveRecord
26
+ extend Shoulda::Matchers::ActiveRecord
27
+ end
25
28
 
26
- ActiveSupport::TestCase.class_eval do
27
- include Shoulda::Matchers::ActiveModel
28
- extend Shoulda::Matchers::ActiveModel
29
+ if defined?(Shoulda::Matchers::ActiveModel)
30
+ include Shoulda::Matchers::ActiveModel
31
+ extend Shoulda::Matchers::ActiveModel
32
+ end
29
33
  end
30
34
  end
@@ -0,0 +1,13 @@
1
+ module Shoulda
2
+ module Matchers
3
+ # @private
4
+ module Integrations
5
+ end
6
+ end
7
+ end
8
+
9
+ if defined?(RSpec)
10
+ require 'shoulda/matchers/integrations/rspec'
11
+ end
12
+
13
+ require 'shoulda/matchers/integrations/test_unit'
@@ -34,6 +34,14 @@ module Shoulda
34
34
  end
35
35
  end
36
36
 
37
+ def self.verb_for_update
38
+ if action_pack_gte_4_1?
39
+ :patch
40
+ else
41
+ :put
42
+ end
43
+ end
44
+
37
45
  def self.active_record_major_version
38
46
  ::ActiveRecord::VERSION::MAJOR
39
47
  end
@@ -45,6 +53,14 @@ module Shoulda
45
53
  def self.action_pack_major_version
46
54
  ::ActionPack::VERSION::MAJOR
47
55
  end
56
+
57
+ def self.action_pack_gte_4_1?
58
+ Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
59
+ end
60
+
61
+ def self.action_pack_version
62
+ Gem::Version.new(::ActionPack::VERSION::STRING)
63
+ end
48
64
  end
49
65
  end
50
66
  end
@@ -1,6 +1,6 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  # @private
4
- VERSION = '2.5.0'.freeze
4
+ VERSION = '2.6.1.docs.1'.freeze
5
5
  end
6
6
  end
@@ -1,11 +1,23 @@
1
1
  require 'shoulda/matchers/assertion_error'
2
+ require 'shoulda/matchers/doublespeak'
2
3
  require 'shoulda/matchers/error'
3
4
  require 'shoulda/matchers/rails_shim'
4
5
  require 'shoulda/matchers/warn'
5
6
  require 'shoulda/matchers/version'
6
7
 
7
- if defined?(RSpec)
8
- require 'shoulda/matchers/integrations/rspec'
8
+ require 'shoulda/matchers/independent'
9
+
10
+ if defined?(ActiveModel)
11
+ require 'shoulda/matchers/active_model'
12
+ end
13
+
14
+ if defined?(ActiveRecord)
15
+ require 'shoulda/matchers/active_record'
9
16
  end
10
17
 
11
- require 'shoulda/matchers/integrations/test_unit'
18
+ if defined?(ActionController)
19
+ require 'shoulda/matchers/action_controller'
20
+ end
21
+
22
+ require 'shoulda/matchers/integrations'
23
+
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shoulda::Matchers::ActionController::CallbackMatcher do
4
+ shared_examples 'CallbackMatcher' do |kind, callback_type|
5
+ let(:kind) { kind }
6
+ let(:callback_type) { callback_type }
7
+ let(:method_name) { :authenticate_user! }
8
+ let(:matcher) { described_class.new(method_name, kind, callback_type) }
9
+ let(:controller) { define_controller('HookController').new }
10
+
11
+ def match
12
+ __send__("use_#{kind}_#{callback_type}", method_name)
13
+ end
14
+
15
+ it "matches when a #{kind} hook is in place" do
16
+ add_callback(kind, callback_type, method_name)
17
+
18
+ expect(controller).to match
19
+ end
20
+
21
+ it "does not match when a #{kind} hook is missing" do
22
+ expect(controller).not_to match
23
+ end
24
+
25
+ describe 'description' do
26
+ it 'includes the filter kind and name' do
27
+ expect(matcher.description).to eq "have #{method_name.inspect} as a #{kind}_#{callback_type}"
28
+ end
29
+ end
30
+
31
+ describe 'failure message' do
32
+ it 'includes the filter kind and name that was expected' do
33
+ message = "Expected that HookController would have #{method_name.inspect} as a #{kind}_#{callback_type}"
34
+
35
+ expect {
36
+ expect(controller).to send("use_#{kind}_#{callback_type}", method_name)
37
+ }.to fail_with_message(message)
38
+ end
39
+ end
40
+
41
+ describe 'failure message when negated' do
42
+ it 'includes the filter kind and name that was expected' do
43
+ add_callback(kind, callback_type, method_name)
44
+ message = "Expected that HookController would not have #{method_name.inspect} as a #{kind}_#{callback_type}"
45
+
46
+ expect { expect(controller).not_to match }.to fail_with_message(message)
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def add_callback(kind, callback_type, callback)
53
+ controller.class.__send__("#{kind}_#{callback_type}", callback)
54
+ end
55
+ end
56
+
57
+ describe '#use_before_filter' do
58
+ it_behaves_like 'CallbackMatcher', :before, :filter
59
+ end
60
+
61
+ describe '#use_after_filter' do
62
+ it_behaves_like 'CallbackMatcher', :after, :filter
63
+ end
64
+
65
+ describe '#use_around_filter' do
66
+ it_behaves_like 'CallbackMatcher', :around, :filter
67
+ end
68
+
69
+ if rails_4_x?
70
+ describe '#use_before_action' do
71
+ it_behaves_like 'CallbackMatcher', :before, :action
72
+ end
73
+
74
+ describe '#use_after_action' do
75
+ it_behaves_like 'CallbackMatcher', :after, :action
76
+ end
77
+
78
+ describe '#use_around_action' do
79
+ it_behaves_like 'CallbackMatcher', :around, :action
80
+ end
81
+ end
82
+ end
@@ -22,13 +22,13 @@ describe Shoulda::Matchers::ActionController::RedirectToMatcher do
22
22
  end
23
23
 
24
24
  def controller_redirecting_to(url)
25
- build_response { redirect_to url }
25
+ build_fake_response { redirect_to url }
26
26
  end
27
27
  end
28
28
 
29
29
  context 'a controller that does not redirect' do
30
30
  it 'rejects redirecting to a url' do
31
- controller = build_response { render text: 'hello' }
31
+ controller = build_fake_response { render text: 'hello' }
32
32
 
33
33
  expect(controller).not_to redirect_to('/some/url')
34
34
  end
@@ -21,7 +21,7 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
21
21
  end
22
22
 
23
23
  def controller_with_show
24
- build_response(action: 'show') { render }
24
+ build_fake_response(action: 'show') { render }
25
25
  end
26
26
  end
27
27
 
@@ -47,13 +47,13 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
47
47
  end
48
48
 
49
49
  def controller_with_customer_partial
50
- build_response(partial: '_customer') { render partial: 'customer' }
50
+ build_fake_response(partial: '_customer') { render partial: 'customer' }
51
51
  end
52
52
  end
53
53
 
54
54
  context 'a controller that does not render partials' do
55
55
  it 'accepts not rendering a partial' do
56
- controller = build_response(action: 'show') { render }
56
+ controller = build_fake_response(action: 'show') { render }
57
57
 
58
58
  expect(controller).to render_template(partial: false)
59
59
  end
@@ -61,7 +61,7 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
61
61
 
62
62
  context 'a controller that renders a partial several times' do
63
63
  it 'accepts rendering that partial twice' do
64
- controller = build_response(partial: '_customer') do
64
+ controller = build_fake_response(partial: '_customer') do
65
65
  render partial: 'customer', collection: [1,2]
66
66
  end
67
67
 
@@ -71,7 +71,7 @@ describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
71
71
 
72
72
  context 'a controller that does not render a template' do
73
73
  it 'rejects rendering a template' do
74
- expect(build_response { render nothing: true }).
74
+ expect(build_fake_response { render nothing: true }).
75
75
  not_to render_template(:show)
76
76
  end
77
77
  end
@@ -18,14 +18,14 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
18
18
 
19
19
  def controller_with_wide_layout
20
20
  create_view('layouts/wide.html.erb', 'some content, <%= yield %>')
21
- build_response { render layout: 'wide' }
21
+ build_fake_response { render layout: 'wide' }
22
22
  end
23
23
  end
24
24
 
25
25
  context 'a controller that renders without a layout' do
26
26
 
27
27
  it 'rejects rendering with a layout' do
28
- controller_without_layout = build_response { render layout: false }
28
+ controller_without_layout = build_fake_response { render layout: false }
29
29
 
30
30
  expect(controller_without_layout).not_to render_with_layout
31
31
  end
@@ -33,7 +33,7 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
33
33
 
34
34
  context 'a controller that renders a partial' do
35
35
  it 'rejects rendering with a layout' do
36
- controller_with_partial = build_response { render partial: 'partial' }
36
+ controller_with_partial = build_fake_response { render partial: 'partial' }
37
37
 
38
38
  expect(controller_with_partial).not_to render_with_layout
39
39
  end
@@ -57,7 +57,7 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
57
57
  end
58
58
 
59
59
  def controller_without_layout
60
- build_response { render layout: false }
60
+ build_fake_response { render layout: false }
61
61
  end
62
62
  end
63
63
  end
@@ -2,20 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  describe Shoulda::Matchers::ActionController::RescueFromMatcher do
4
4
  context 'a controller that rescues from RuntimeError' do
5
- it "asserts controller is setup with rescue_from" do
5
+ it 'asserts controller is setup with rescue_from' do
6
6
  expect(controller_with_rescue_from).to rescue_from RuntimeError
7
7
  end
8
8
 
9
9
  context 'with a handler method' do
10
- it "asserts rescue_from was set up with handler method" do
11
- expect(controller_with_rescue_from_and_method).to rescue_from(RuntimeError).with(:error_method)
10
+ it 'asserts rescue_from can find the handler when it is public' do
11
+ controller = controller_with_rescue_from_and_method(:public)
12
+ check_rescue_with_method_for(controller)
12
13
  end
13
14
 
14
- it "asserts rescue_from was not set up with incorrect handler method" do
15
+ it 'asserts rescue_from can find the handler when it is protected' do
16
+ controller = controller_with_rescue_from_and_method(:protected)
17
+ check_rescue_with_method_for(controller)
18
+ end
19
+
20
+ it 'asserts rescue_from can find the handler when it is private' do
21
+ controller = controller_with_rescue_from_and_method(:private)
22
+ check_rescue_with_method_for(controller)
23
+ end
24
+
25
+ it 'asserts rescue_from was not set up with incorrect handler method' do
15
26
  expect(controller_with_rescue_from_and_method).not_to rescue_from(RuntimeError).with(:other_method)
16
27
  end
17
28
 
18
- it "asserts the controller responds to the handler method" do
29
+ it 'asserts the controller responds to the handler method' do
19
30
  matcher = rescue_from(RuntimeError).with(:error_method)
20
31
  expect(matcher.matches?(controller_with_rescue_from_and_invalid_method)).to eq false
21
32
  expect(matcher.failure_message).to match(/does not respond to/)
@@ -23,7 +34,7 @@ describe Shoulda::Matchers::ActionController::RescueFromMatcher do
23
34
  end
24
35
 
25
36
  context 'without a handler method' do
26
- it "the handler method is not included in the description" do
37
+ it 'the handler method is not included in the description' do
27
38
  matcher = rescue_from(RuntimeError)
28
39
  expect(matcher.matches?(controller_with_rescue_from)).to eq true
29
40
  expect(matcher.description).not_to match(/with #/)
@@ -32,32 +43,48 @@ describe Shoulda::Matchers::ActionController::RescueFromMatcher do
32
43
  end
33
44
 
34
45
  context 'a controller that does not rescue from RuntimeError' do
35
- it "asserts controller is not setup with rescue_from" do
46
+ it 'asserts controller is not setup with rescue_from' do
36
47
  matcher = rescue_from RuntimeError
37
- expect(define_controller("RandomController")).not_to matcher
48
+ expect(define_controller('RandomController')).not_to matcher
38
49
  expect(matcher.failure_message_when_negated).to match(/Did not expect \w+ to rescue from/)
39
50
  end
40
51
  end
41
52
 
53
+ def check_rescue_with_method_for(controller)
54
+ expect(controller).to rescue_from(RuntimeError).with(:error_method)
55
+ end
56
+
42
57
  def controller_with_rescue_from
43
- define_controller "RescueRuntimeError" do
58
+ define_controller 'RescueRuntimeError' do
44
59
  rescue_from(RuntimeError) {}
45
60
  end
46
61
  end
47
62
 
48
63
  def controller_with_rescue_from_and_invalid_method
49
- define_controller "RescueRuntimeErrorWithMethod" do
64
+ define_controller 'RescueRuntimeErrorWithMethod' do
50
65
  rescue_from RuntimeError, with: :error_method
51
66
  end
52
67
  end
53
68
 
54
- def controller_with_rescue_from_and_method
69
+ def controller_with_rescue_from_and_method(access = :public)
55
70
  controller = controller_with_rescue_from_and_invalid_method
56
71
  class << controller
57
72
  def error_method
58
73
  true
59
74
  end
60
75
  end
76
+
77
+ case access
78
+ when :protected
79
+ class << controller
80
+ protected :error_method
81
+ end
82
+ when :private
83
+ class << controller
84
+ private :error_method
85
+ end
86
+ end
87
+
61
88
  controller
62
89
  end
63
90
  end
@@ -24,7 +24,7 @@ describe Shoulda::Matchers::ActionController::RespondWithMatcher do
24
24
  end
25
25
 
26
26
  def controller_with_status(status)
27
- build_response do
27
+ build_fake_response do
28
28
  render text: 'text', status: status
29
29
  end
30
30
  end
@@ -41,7 +41,7 @@ describe Shoulda::Matchers::ActionController::SetSessionMatcher do
41
41
  end
42
42
 
43
43
  def controller_with_session(session_hash)
44
- build_response do
44
+ build_fake_response do
45
45
  session_hash.each do |key, value|
46
46
  session[key] = value
47
47
  end
@@ -95,7 +95,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
95
95
 
96
96
  context 'a controller that sets flash and flash.now' do
97
97
  it 'accepts setting any flash.now message' do
98
- controller = build_response do
98
+ controller = build_fake_response do
99
99
  flash.now[:notice] = 'value'
100
100
  flash[:success] = 'great job'
101
101
  end
@@ -105,7 +105,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
105
105
  end
106
106
 
107
107
  it 'accepts setting a matched flash.now message' do
108
- controller = build_response do
108
+ controller = build_fake_response do
109
109
  flash.now[:notice] = 'value'
110
110
  flash[:success] = 'great job'
111
111
  end
@@ -115,7 +115,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
115
115
  end
116
116
 
117
117
  it 'rejects setting a different flash.now message' do
118
- controller = build_response do
118
+ controller = build_fake_response do
119
119
  flash.now[:notice] = 'value'
120
120
  flash[:success] = 'great job'
121
121
  end
@@ -132,11 +132,11 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
132
132
  end
133
133
 
134
134
  def controller_with_no_flashes
135
- build_response
135
+ build_fake_response
136
136
  end
137
137
 
138
138
  def controller_with_flash(flash_hash)
139
- build_response do
139
+ build_fake_response do
140
140
  flash_hash.each do |key, value|
141
141
  flash[key] = value
142
142
  end
@@ -144,7 +144,7 @@ describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
144
144
  end
145
145
 
146
146
  def controller_with_flash_now(flash_hash = { notice: 'hi' })
147
- build_response do
147
+ build_fake_response do
148
148
  flash_hash.each do |key, value|
149
149
  flash.now[key] = value
150
150
  end