ultra-fast-box 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/shoulda-matchers-8.0.1/LICENSE +22 -0
- data/shoulda-matchers-8.0.1/README.md +567 -0
- data/shoulda-matchers-8.0.1/docs/errors/NonCaseSwappableValueError.md +111 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/callback_matcher.rb +121 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +70 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/flash_store.rb +86 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/permit_matcher.rb +445 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +96 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/render_template_matcher.rb +84 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +145 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +115 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +148 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/route_matcher.rb +207 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/route_params.rb +62 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/session_store.rb +34 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +228 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_session_matcher.rb +163 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +107 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller.rb +24 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +45 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_does_not_exist_error.rb +23 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +232 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +62 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +40 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +48 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/successful_check.rb +14 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/successful_setting.rb +14 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher.rb +695 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/comparison_matcher.rb +157 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +78 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/errors.rb +52 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +125 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/helpers.rb +37 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +45 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +67 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +45 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +44 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb +71 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/submatchers.rb +53 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/allow_blank.rb +26 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/allow_nil.rb +26 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb +101 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +21 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers.rb +14 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +180 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +128 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_comparison_of_matcher.rb +567 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +185 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +272 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +664 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +575 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +711 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +428 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +62 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_matcher.rb +195 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_message_finder.rb +63 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validator.rb +127 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model.rb +96 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +217 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matcher.rb +2134 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +74 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +62 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +41 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +105 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +101 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +89 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +142 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +71 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +41 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +76 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +42 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +65 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +784 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/encrypt_matcher.rb +174 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_attached_matcher.rb +343 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +366 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +287 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +104 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +95 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +83 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +132 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/normalize_matcher.rb +151 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/serialize_matcher.rb +203 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/model.rb +58 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +39 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +49 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +55 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness.rb +14 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1197 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record.rb +37 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/configuration.rb +31 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double.rb +103 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double_collection.rb +60 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +31 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/method_call.rb +44 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/object_double.rb +43 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +32 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/stub_implementation.rb +31 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/world.rb +63 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak.rb +38 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/error.rb +29 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +15 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent/delegate_method_matcher.rb +540 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent.rb +11 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/configuration.rb +70 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/configuration_error.rb +9 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/inclusion.rb +20 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/action_controller.rb +33 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/active_model.rb +26 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/active_record.rb +26 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/missing_library.rb +19 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/rails.rb +31 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/routing.rb +29 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries.rb +16 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/rails.rb +12 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/registry.rb +28 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +37 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +36 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +37 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +40 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +29 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +36 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks.rb +16 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations.rb +43 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/matcher_collection.rb +99 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/matcher_context.rb +36 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/rails_shim.rb +190 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/routing.rb +10 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/util/word_wrap.rb +211 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/util.rb +110 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/version.rb +6 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/warn.rb +28 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers.rb +25 -0
- data/shoulda-matchers-8.0.1/lib/shoulda-matchers.rb +1 -0
- data/shoulda-matchers-8.0.1/shoulda-matchers.gemspec +43 -0
- data/ultra-fast-box.gemspec +12 -0
- metadata +179 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
|
|
3
|
+
module Shoulda
|
|
4
|
+
module Matchers
|
|
5
|
+
module ActionController
|
|
6
|
+
# The `set_flash` matcher is used to make assertions about the
|
|
7
|
+
# `flash` hash.
|
|
8
|
+
#
|
|
9
|
+
# class PostsController < ApplicationController
|
|
10
|
+
# def index
|
|
11
|
+
# flash[:foo] = 'A candy bar'
|
|
12
|
+
# end
|
|
13
|
+
#
|
|
14
|
+
# def destroy
|
|
15
|
+
# end
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# # RSpec
|
|
19
|
+
# RSpec.describe PostsController, type: :controller do
|
|
20
|
+
# describe 'GET #index' do
|
|
21
|
+
# before { get :index }
|
|
22
|
+
#
|
|
23
|
+
# it { should set_flash }
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# describe 'DELETE #destroy' do
|
|
27
|
+
# before { delete :destroy }
|
|
28
|
+
#
|
|
29
|
+
# it { should_not set_flash }
|
|
30
|
+
# end
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# # Minitest (Shoulda)
|
|
34
|
+
# class PostsControllerTest < ActionController::TestCase
|
|
35
|
+
# context 'GET #index' do
|
|
36
|
+
# setup { get :index }
|
|
37
|
+
#
|
|
38
|
+
# should set_flash
|
|
39
|
+
# end
|
|
40
|
+
#
|
|
41
|
+
# context 'DELETE #destroy' do
|
|
42
|
+
# setup { delete :destroy }
|
|
43
|
+
#
|
|
44
|
+
# should_not set_flash
|
|
45
|
+
# end
|
|
46
|
+
# end
|
|
47
|
+
#
|
|
48
|
+
# #### Qualifiers
|
|
49
|
+
#
|
|
50
|
+
# ##### []
|
|
51
|
+
#
|
|
52
|
+
# Use `[]` to narrow the scope of the matcher to a particular key.
|
|
53
|
+
#
|
|
54
|
+
# class PostsController < ApplicationController
|
|
55
|
+
# def index
|
|
56
|
+
# flash[:foo] = 'A candy bar'
|
|
57
|
+
# end
|
|
58
|
+
# end
|
|
59
|
+
#
|
|
60
|
+
# # RSpec
|
|
61
|
+
# RSpec.describe PostsController, type: :controller do
|
|
62
|
+
# describe 'GET #index' do
|
|
63
|
+
# before { get :index }
|
|
64
|
+
#
|
|
65
|
+
# it { should set_flash[:foo] }
|
|
66
|
+
# it { should_not set_flash[:bar] }
|
|
67
|
+
# end
|
|
68
|
+
# end
|
|
69
|
+
#
|
|
70
|
+
# # Minitest (Shoulda)
|
|
71
|
+
# class PostsControllerTest < ActionController::TestCase
|
|
72
|
+
# context 'GET #index' do
|
|
73
|
+
# setup { get :show }
|
|
74
|
+
#
|
|
75
|
+
# should set_flash[:foo]
|
|
76
|
+
# should_not set_flash[:bar]
|
|
77
|
+
# end
|
|
78
|
+
# end
|
|
79
|
+
#
|
|
80
|
+
# ##### to
|
|
81
|
+
#
|
|
82
|
+
# Use `to` to assert that some key was set to a particular value, or that
|
|
83
|
+
# some key matches a particular regex.
|
|
84
|
+
#
|
|
85
|
+
# class PostsController < ApplicationController
|
|
86
|
+
# def index
|
|
87
|
+
# flash[:foo] = 'A candy bar'
|
|
88
|
+
# end
|
|
89
|
+
# end
|
|
90
|
+
#
|
|
91
|
+
# # RSpec
|
|
92
|
+
# RSpec.describe PostsController, type: :controller do
|
|
93
|
+
# describe 'GET #index' do
|
|
94
|
+
# before { get :index }
|
|
95
|
+
#
|
|
96
|
+
# it { should set_flash.to('A candy bar') }
|
|
97
|
+
# it { should set_flash.to(/bar/) }
|
|
98
|
+
# it { should set_flash[:foo].to('bar') }
|
|
99
|
+
# it { should_not set_flash[:foo].to('something else') }
|
|
100
|
+
# end
|
|
101
|
+
# end
|
|
102
|
+
#
|
|
103
|
+
# # Minitest (Shoulda)
|
|
104
|
+
# class PostsControllerTest < ActionController::TestCase
|
|
105
|
+
# context 'GET #index' do
|
|
106
|
+
# setup { get :show }
|
|
107
|
+
#
|
|
108
|
+
# should set_flash.to('A candy bar')
|
|
109
|
+
# should set_flash.to(/bar/)
|
|
110
|
+
# should set_flash[:foo].to('bar')
|
|
111
|
+
# should_not set_flash[:foo].to('something else')
|
|
112
|
+
# end
|
|
113
|
+
# end
|
|
114
|
+
#
|
|
115
|
+
# ##### now
|
|
116
|
+
#
|
|
117
|
+
# Use `now` to change the scope of the matcher to use the "now" hash
|
|
118
|
+
# instead of the usual "future" hash.
|
|
119
|
+
#
|
|
120
|
+
# class PostsController < ApplicationController
|
|
121
|
+
# def show
|
|
122
|
+
# flash.now[:foo] = 'bar'
|
|
123
|
+
# end
|
|
124
|
+
# end
|
|
125
|
+
#
|
|
126
|
+
# # RSpec
|
|
127
|
+
# RSpec.describe PostsController, type: :controller do
|
|
128
|
+
# describe 'GET #show' do
|
|
129
|
+
# before { get :show }
|
|
130
|
+
#
|
|
131
|
+
# it { should set_flash.now }
|
|
132
|
+
# it { should set_flash.now[:foo] }
|
|
133
|
+
# it { should set_flash.now[:foo].to('bar') }
|
|
134
|
+
# end
|
|
135
|
+
# end
|
|
136
|
+
#
|
|
137
|
+
# # Minitest (Shoulda)
|
|
138
|
+
# class PostsControllerTest < ActionController::TestCase
|
|
139
|
+
# context 'GET #index' do
|
|
140
|
+
# setup { get :show }
|
|
141
|
+
#
|
|
142
|
+
# should set_flash.now
|
|
143
|
+
# should set_flash.now[:foo]
|
|
144
|
+
# should set_flash.now[:foo].to('bar')
|
|
145
|
+
# end
|
|
146
|
+
# end
|
|
147
|
+
#
|
|
148
|
+
# @return [SetFlashMatcher]
|
|
149
|
+
#
|
|
150
|
+
def set_flash
|
|
151
|
+
SetFlashMatcher.new.in_context(self)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# @private
|
|
155
|
+
class SetFlashMatcher
|
|
156
|
+
extend Forwardable
|
|
157
|
+
|
|
158
|
+
def_delegators :underlying_matcher,
|
|
159
|
+
:description,
|
|
160
|
+
:matches?,
|
|
161
|
+
:failure_message,
|
|
162
|
+
:failure_message_when_negated
|
|
163
|
+
alias_method \
|
|
164
|
+
:failure_message_for_should,
|
|
165
|
+
:failure_message
|
|
166
|
+
alias_method \
|
|
167
|
+
:failure_message_for_should_not,
|
|
168
|
+
:failure_message_when_negated
|
|
169
|
+
|
|
170
|
+
def initialize
|
|
171
|
+
store = FlashStore.future
|
|
172
|
+
@underlying_matcher = SetSessionOrFlashMatcher.new(store)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def now
|
|
176
|
+
if key || expected_value
|
|
177
|
+
raise QualifierOrderError
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
store = FlashStore.now
|
|
181
|
+
@underlying_matcher = SetSessionOrFlashMatcher.new(store)
|
|
182
|
+
self
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def in_context(context)
|
|
186
|
+
underlying_matcher.in_context(context)
|
|
187
|
+
self
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def [](key)
|
|
191
|
+
@key = key
|
|
192
|
+
underlying_matcher[key]
|
|
193
|
+
self
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def to(expected_value = nil, &block)
|
|
197
|
+
@expected_value = expected_value
|
|
198
|
+
underlying_matcher.to(expected_value, &block)
|
|
199
|
+
self
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
protected
|
|
203
|
+
|
|
204
|
+
attr_reader :underlying_matcher, :key, :expected_value
|
|
205
|
+
|
|
206
|
+
# @private
|
|
207
|
+
class QualifierOrderError < StandardError
|
|
208
|
+
def message
|
|
209
|
+
<<-MESSAGE.strip
|
|
210
|
+
Using `set_flash` with the `now` qualifier and specifying `now` after other
|
|
211
|
+
qualifiers is no longer allowed.
|
|
212
|
+
|
|
213
|
+
You'll want to use `now` immediately after `set_flash`. For instance:
|
|
214
|
+
|
|
215
|
+
# Valid
|
|
216
|
+
should set_flash.now[:foo]
|
|
217
|
+
should set_flash.now[:foo].to('bar')
|
|
218
|
+
|
|
219
|
+
# Invalid
|
|
220
|
+
should set_flash[:foo].now
|
|
221
|
+
should set_flash[:foo].to('bar').now
|
|
222
|
+
MESSAGE
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
|
|
3
|
+
module Shoulda
|
|
4
|
+
module Matchers
|
|
5
|
+
module ActionController
|
|
6
|
+
# The `set_session` matcher is used to make assertions about the
|
|
7
|
+
# `session` hash.
|
|
8
|
+
#
|
|
9
|
+
# class PostsController < ApplicationController
|
|
10
|
+
# def index
|
|
11
|
+
# session[:foo] = 'A candy bar'
|
|
12
|
+
# end
|
|
13
|
+
#
|
|
14
|
+
# def destroy
|
|
15
|
+
# end
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# # RSpec
|
|
19
|
+
# RSpec.describe PostsController, type: :controller do
|
|
20
|
+
# describe 'GET #index' do
|
|
21
|
+
# before { get :index }
|
|
22
|
+
#
|
|
23
|
+
# it { should set_session }
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# describe 'DELETE #destroy' do
|
|
27
|
+
# before { delete :destroy }
|
|
28
|
+
#
|
|
29
|
+
# it { should_not set_session }
|
|
30
|
+
# end
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# # Minitest (Shoulda)
|
|
34
|
+
# class PostsControllerTest < ActionController::TestCase
|
|
35
|
+
# context 'GET #index' do
|
|
36
|
+
# setup { get :index }
|
|
37
|
+
#
|
|
38
|
+
# should set_session
|
|
39
|
+
# end
|
|
40
|
+
#
|
|
41
|
+
# context 'DELETE #destroy' do
|
|
42
|
+
# setup { delete :destroy }
|
|
43
|
+
#
|
|
44
|
+
# should_not set_session
|
|
45
|
+
# end
|
|
46
|
+
# end
|
|
47
|
+
#
|
|
48
|
+
# #### Qualifiers
|
|
49
|
+
#
|
|
50
|
+
# ##### []
|
|
51
|
+
#
|
|
52
|
+
# Use `[]` to narrow the scope of the matcher to a particular key.
|
|
53
|
+
#
|
|
54
|
+
# class PostsController < ApplicationController
|
|
55
|
+
# def index
|
|
56
|
+
# session[:foo] = 'A candy bar'
|
|
57
|
+
# end
|
|
58
|
+
# end
|
|
59
|
+
#
|
|
60
|
+
# # RSpec
|
|
61
|
+
# RSpec.describe PostsController, type: :controller do
|
|
62
|
+
# describe 'GET #index' do
|
|
63
|
+
# before { get :index }
|
|
64
|
+
#
|
|
65
|
+
# it { should set_session[:foo] }
|
|
66
|
+
# it { should_not set_session[:bar] }
|
|
67
|
+
# end
|
|
68
|
+
# end
|
|
69
|
+
#
|
|
70
|
+
# # Minitest (Shoulda)
|
|
71
|
+
# class PostsControllerTest < ActionController::TestCase
|
|
72
|
+
# context 'GET #index' do
|
|
73
|
+
# setup { get :show }
|
|
74
|
+
#
|
|
75
|
+
# should set_session[:foo]
|
|
76
|
+
# should_not set_session[:bar]
|
|
77
|
+
# end
|
|
78
|
+
# end
|
|
79
|
+
#
|
|
80
|
+
# ##### to
|
|
81
|
+
#
|
|
82
|
+
# Use `to` to assert that some key was set to a particular value, or that
|
|
83
|
+
# some key matches a particular regex.
|
|
84
|
+
#
|
|
85
|
+
# class PostsController < ApplicationController
|
|
86
|
+
# def index
|
|
87
|
+
# session[:foo] = 'A candy bar'
|
|
88
|
+
# end
|
|
89
|
+
# end
|
|
90
|
+
#
|
|
91
|
+
# # RSpec
|
|
92
|
+
# RSpec.describe PostsController, type: :controller do
|
|
93
|
+
# describe 'GET #index' do
|
|
94
|
+
# before { get :index }
|
|
95
|
+
#
|
|
96
|
+
# it { should set_session.to('A candy bar') }
|
|
97
|
+
# it { should set_session.to(/bar/) }
|
|
98
|
+
# it { should set_session[:foo].to('bar') }
|
|
99
|
+
# it { should_not set_session[:foo].to('something else') }
|
|
100
|
+
# end
|
|
101
|
+
# end
|
|
102
|
+
#
|
|
103
|
+
# # Minitest (Shoulda)
|
|
104
|
+
# class PostsControllerTest < ActionController::TestCase
|
|
105
|
+
# context 'GET #index' do
|
|
106
|
+
# setup { get :show }
|
|
107
|
+
#
|
|
108
|
+
# should set_session.to('A candy bar')
|
|
109
|
+
# should set_session.to(/bar/)
|
|
110
|
+
# should set_session[:foo].to('bar')
|
|
111
|
+
# should_not set_session[:foo].to('something else')
|
|
112
|
+
# end
|
|
113
|
+
# end
|
|
114
|
+
#
|
|
115
|
+
# @return [SetSessionMatcher]
|
|
116
|
+
#
|
|
117
|
+
def set_session
|
|
118
|
+
SetSessionMatcher.new.in_context(self)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# @private
|
|
122
|
+
class SetSessionMatcher
|
|
123
|
+
extend Forwardable
|
|
124
|
+
|
|
125
|
+
def_delegators :underlying_matcher,
|
|
126
|
+
:description,
|
|
127
|
+
:matches?,
|
|
128
|
+
:failure_message,
|
|
129
|
+
:failure_message_when_negated
|
|
130
|
+
alias_method \
|
|
131
|
+
:failure_message_for_should,
|
|
132
|
+
:failure_message
|
|
133
|
+
alias_method \
|
|
134
|
+
:failure_message_for_should_not,
|
|
135
|
+
:failure_message_when_negated
|
|
136
|
+
|
|
137
|
+
def initialize
|
|
138
|
+
store = SessionStore.new
|
|
139
|
+
@underlying_matcher = SetSessionOrFlashMatcher.new(store)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def in_context(context)
|
|
143
|
+
underlying_matcher.in_context(context)
|
|
144
|
+
self
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def [](key)
|
|
148
|
+
underlying_matcher[key]
|
|
149
|
+
self
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def to(expected_value = nil, &block)
|
|
153
|
+
underlying_matcher.to(expected_value, &block)
|
|
154
|
+
self
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
protected
|
|
158
|
+
|
|
159
|
+
attr_reader :underlying_matcher
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActionController
|
|
4
|
+
# @private
|
|
5
|
+
class SetSessionOrFlashMatcher
|
|
6
|
+
def initialize(store)
|
|
7
|
+
@store = store
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def in_context(context)
|
|
11
|
+
@context = context
|
|
12
|
+
self
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def [](key)
|
|
16
|
+
@key = key
|
|
17
|
+
self
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to(expected_value = nil, &block)
|
|
21
|
+
if block
|
|
22
|
+
unless context_set?
|
|
23
|
+
message = 'When specifying a value as a block, a context must be'\
|
|
24
|
+
' specified beforehand,'\
|
|
25
|
+
" e.g., #{store.name}.in_context(context).to { ... }"
|
|
26
|
+
raise ArgumentError, message
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
@expected_value = context.instance_eval(&block)
|
|
30
|
+
else
|
|
31
|
+
@expected_value = expected_value
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
self
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def description
|
|
38
|
+
"should #{expectation_description}"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def matches?(controller)
|
|
42
|
+
@controller = store.controller = controller
|
|
43
|
+
!store.empty? && key_matches? && expected_value_matches?
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def failure_message
|
|
47
|
+
"Expected #{controller.class} to #{expectation_description},"\
|
|
48
|
+
' but it did not'
|
|
49
|
+
end
|
|
50
|
+
alias_method :failure_message_for_should, :failure_message
|
|
51
|
+
|
|
52
|
+
def failure_message_when_negated
|
|
53
|
+
"Expected #{controller.class} not to #{expectation_description},"\
|
|
54
|
+
' but it did'
|
|
55
|
+
end
|
|
56
|
+
alias_method :failure_message_for_should_not,
|
|
57
|
+
:failure_message_when_negated
|
|
58
|
+
|
|
59
|
+
protected
|
|
60
|
+
|
|
61
|
+
attr_reader :store, :context, :key, :expected_value, :controller
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def context_set?
|
|
66
|
+
defined?(@context)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def key_set?
|
|
70
|
+
defined?(@key)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def expected_value_set?
|
|
74
|
+
defined?(@expected_value)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def key_matches?
|
|
78
|
+
!key_set? || store.has_key?(key)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def expected_value_matches?
|
|
82
|
+
!expected_value_set? || store.has_value?(expected_value)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def expectation_description
|
|
86
|
+
String.new('set').tap do |string|
|
|
87
|
+
string <<
|
|
88
|
+
if key_set?
|
|
89
|
+
" #{store.name}[#{key.inspect}]"
|
|
90
|
+
else
|
|
91
|
+
" any key in #{store.name}"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
if expected_value_set?
|
|
95
|
+
string <<
|
|
96
|
+
if expected_value.is_a?(Regexp)
|
|
97
|
+
" to a value matching #{expected_value.inspect}"
|
|
98
|
+
else
|
|
99
|
+
" to #{expected_value.inspect}"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'shoulda/matchers/action_controller/filter_param_matcher'
|
|
2
|
+
require 'shoulda/matchers/action_controller/route_params'
|
|
3
|
+
require 'shoulda/matchers/action_controller/set_flash_matcher'
|
|
4
|
+
require 'shoulda/matchers/action_controller/render_with_layout_matcher'
|
|
5
|
+
require 'shoulda/matchers/action_controller/respond_with_matcher'
|
|
6
|
+
require 'shoulda/matchers/action_controller/set_session_matcher'
|
|
7
|
+
require 'shoulda/matchers/action_controller/route_matcher'
|
|
8
|
+
require 'shoulda/matchers/action_controller/redirect_to_matcher'
|
|
9
|
+
require 'shoulda/matchers/action_controller/render_template_matcher'
|
|
10
|
+
require 'shoulda/matchers/action_controller/rescue_from_matcher'
|
|
11
|
+
require 'shoulda/matchers/action_controller/callback_matcher'
|
|
12
|
+
require 'shoulda/matchers/action_controller/permit_matcher'
|
|
13
|
+
require 'shoulda/matchers/action_controller/set_session_or_flash_matcher'
|
|
14
|
+
require 'shoulda/matchers/action_controller/flash_store'
|
|
15
|
+
require 'shoulda/matchers/action_controller/session_store'
|
|
16
|
+
|
|
17
|
+
module Shoulda
|
|
18
|
+
module Matchers
|
|
19
|
+
# This module provides matchers that are used to test behavior within
|
|
20
|
+
# controllers.
|
|
21
|
+
module ActionController
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
class AllowValueMatcher
|
|
5
|
+
# @private
|
|
6
|
+
class AttributeChangedValueError < Shoulda::Matchers::Error
|
|
7
|
+
attr_accessor :matcher_name, :model, :attribute_name, :value_written,
|
|
8
|
+
:value_read
|
|
9
|
+
|
|
10
|
+
def message
|
|
11
|
+
Shoulda::Matchers.word_wrap <<-MESSAGE
|
|
12
|
+
The #{matcher_name} matcher attempted to set :#{attribute_name} on
|
|
13
|
+
#{model.name} to #{value_written.inspect}, but when the attribute was
|
|
14
|
+
read back, it had stored #{value_read.inspect} instead.
|
|
15
|
+
|
|
16
|
+
This creates a problem because it means that the model is behaving in a
|
|
17
|
+
way that is interfering with the test -- there's a mismatch between the
|
|
18
|
+
test that you wrote and test that we actually ran.
|
|
19
|
+
|
|
20
|
+
There are a couple of reasons why this could be happening:
|
|
21
|
+
|
|
22
|
+
* ActiveRecord is typecasting the incoming value.
|
|
23
|
+
* The writer method for :#{attribute_name} has been overridden so that
|
|
24
|
+
incoming values are changed in some way.
|
|
25
|
+
|
|
26
|
+
If this exception makes sense to you and you wish to bypass it, try
|
|
27
|
+
adding the `ignoring_interference_by_writer` qualifier onto the end of
|
|
28
|
+
your matcher. If the test still does not pass after that, then you may
|
|
29
|
+
need to do something different.
|
|
30
|
+
|
|
31
|
+
If you need help, feel free to ask a question on the shoulda-matchers
|
|
32
|
+
issues list:
|
|
33
|
+
|
|
34
|
+
https://github.com/thoughtbot/shoulda-matchers/issues
|
|
35
|
+
MESSAGE
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def successful?
|
|
39
|
+
false
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
class AllowValueMatcher
|
|
5
|
+
# @private
|
|
6
|
+
class AttributeDoesNotExistError < Shoulda::Matchers::Error
|
|
7
|
+
attr_accessor :model, :attribute_name, :value
|
|
8
|
+
|
|
9
|
+
def message
|
|
10
|
+
Shoulda::Matchers.word_wrap <<-MESSAGE
|
|
11
|
+
The matcher attempted to set :#{attribute_name} on the #{model.name} to
|
|
12
|
+
#{value.inspect}, but that attribute does not exist.
|
|
13
|
+
MESSAGE
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def successful?
|
|
17
|
+
false
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|