shoulda-matchers 2.7.0 → 2.8.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -3
- data/Appraisals +18 -0
- data/CONTRIBUTING.md +13 -29
- data/Gemfile +1 -4
- data/Gemfile.lock +2 -10
- data/NEWS.md +100 -14
- data/README.md +62 -58
- data/Rakefile +9 -16
- data/gemfiles/3.0.gemfile +11 -12
- data/gemfiles/3.0.gemfile.lock +15 -10
- data/gemfiles/3.1.gemfile +11 -12
- data/gemfiles/3.1.gemfile.lock +14 -10
- data/gemfiles/3.1_1.9.2.gemfile +12 -11
- data/gemfiles/3.1_1.9.2.gemfile.lock +14 -3
- data/gemfiles/3.2.gemfile +11 -12
- data/gemfiles/3.2.gemfile.lock +15 -10
- data/gemfiles/3.2_1.9.2.gemfile +12 -11
- data/gemfiles/3.2_1.9.2.gemfile.lock +14 -2
- data/gemfiles/4.0.0.gemfile +10 -12
- data/gemfiles/4.0.0.gemfile.lock +13 -10
- data/gemfiles/4.0.1.gemfile +10 -12
- data/gemfiles/4.0.1.gemfile.lock +13 -10
- data/gemfiles/4.1.gemfile +13 -15
- data/gemfiles/4.1.gemfile.lock +45 -50
- data/gemfiles/4.2.gemfile +36 -0
- data/gemfiles/4.2.gemfile.lock +245 -0
- data/lib/shoulda/matchers.rb +3 -1
- data/lib/shoulda/matchers/action_controller.rb +1 -1
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/route_params.rb +9 -4
- data/lib/shoulda/matchers/action_controller/{set_the_flash_matcher.rb → set_flash_matcher.rb} +34 -26
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +125 -69
- data/lib/shoulda/matchers/active_model.rb +1 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +18 -5
- data/lib/shoulda/matchers/active_model/exception_message_finder.rb +2 -2
- data/lib/shoulda/matchers/active_model/helpers.rb +4 -4
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +10 -3
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +3 -1
- data/lib/shoulda/matchers/active_model/{ensure_length_of_matcher.rb → validate_length_of_matcher.rb} +30 -20
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +21 -0
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -2
- data/lib/shoulda/matchers/active_record.rb +2 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +96 -2
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +3 -3
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +22 -2
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +30 -4
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +19 -3
- data/lib/shoulda/matchers/active_record/uniqueness.rb +14 -0
- data/lib/shoulda/matchers/active_record/uniqueness/model.rb +45 -0
- data/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +36 -0
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +50 -0
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +24 -0
- data/lib/shoulda/matchers/{active_model → active_record}/validate_uniqueness_of_matcher.rb +76 -16
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +117 -51
- data/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +1 -1
- data/lib/shoulda/matchers/matcher_context.rb +35 -0
- data/lib/shoulda/matchers/rails_shim.rb +23 -0
- data/lib/shoulda/matchers/util.rb +28 -0
- data/lib/shoulda/matchers/version.rb +1 -1
- data/script/SUPPORTED_VERSIONS +1 -1
- data/spec/acceptance/active_model_integration_spec.rb +20 -0
- data/spec/acceptance/independent_matchers_spec.rb +64 -0
- data/spec/acceptance/rails_integration_spec.rb +142 -0
- data/spec/acceptance_spec_helper.rb +23 -0
- data/spec/support/acceptance/helpers.rb +29 -0
- data/spec/support/acceptance/helpers/active_model_helpers.rb +11 -0
- data/spec/support/acceptance/helpers/array_helpers.rb +13 -0
- data/spec/support/acceptance/helpers/base_helpers.rb +14 -0
- data/spec/support/acceptance/helpers/command_helpers.rb +51 -0
- data/spec/support/acceptance/helpers/file_helpers.rb +19 -0
- data/spec/support/acceptance/helpers/gem_helpers.rb +31 -0
- data/spec/support/acceptance/helpers/minitest_helpers.rb +19 -0
- data/spec/support/acceptance/helpers/pluralization_helpers.rb +13 -0
- data/spec/support/acceptance/helpers/rails_version_helpers.rb +11 -0
- data/spec/support/acceptance/helpers/rspec_helpers.rb +26 -0
- data/spec/support/acceptance/helpers/ruby_version_helpers.rb +9 -0
- data/spec/support/acceptance/helpers/step_helpers.rb +117 -0
- data/spec/support/acceptance/matchers/have_output.rb +31 -0
- data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +55 -0
- data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +103 -0
- data/spec/support/tests/bundle.rb +94 -0
- data/spec/support/tests/command_runner.rb +214 -0
- data/spec/support/tests/filesystem.rb +77 -0
- data/spec/support/tests/version.rb +45 -0
- data/spec/support/unit/capture.rb +34 -0
- data/spec/support/unit/helpers/active_model_helpers.rb +25 -0
- data/spec/support/unit/helpers/active_model_versions.rb +20 -0
- data/spec/support/unit/helpers/active_resource_builder.rb +27 -0
- data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +15 -0
- data/spec/support/unit/helpers/class_builder.rb +72 -0
- data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +17 -0
- data/spec/support/unit/helpers/controller_builder.rb +91 -0
- data/spec/support/unit/helpers/i18n_faker.rb +15 -0
- data/spec/support/unit/helpers/mailer_builder.rb +12 -0
- data/spec/support/unit/helpers/model_builder.rb +102 -0
- data/spec/support/unit/helpers/rails_versions.rb +28 -0
- data/spec/support/unit/i18n.rb +7 -0
- data/spec/support/unit/matchers/deprecate.rb +60 -0
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +50 -0
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +50 -0
- data/spec/support/unit/matchers/print_warning_including.rb +59 -0
- data/spec/support/unit/rails_application.rb +110 -0
- data/spec/support/unit/record_builder_with_i18n_validation_message.rb +69 -0
- data/spec/support/unit/record_validating_confirmation_builder.rb +56 -0
- data/spec/support/unit/record_with_different_error_attribute_builder.rb +92 -0
- data/spec/support/{shared_examples → unit/shared_examples}/numerical_submatcher.rb +0 -2
- data/spec/support/{shared_examples → unit/shared_examples}/numerical_type_submatcher.rb +0 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/callback_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/filter_param_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/redirect_to_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_template_matcher_spec.rb +2 -4
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_with_layout_matcher_spec.rb +9 -6
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/rescue_from_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/respond_with_matcher_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +126 -0
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/route_params_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +167 -0
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +294 -0
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/strong_parameters_matcher_spec.rb +19 -11
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_value_matcher_spec.rb +49 -21
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/disallow_value_matcher_spec.rb +8 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/exception_message_finder_spec.rb +4 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/have_secure_password_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/helpers_spec.rb +7 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_absence_of_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_acceptance_of_matcher_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +63 -0
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_exclusion_of_matcher_spec.rb +5 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_inclusion_of_matcher_spec.rb +7 -14
- data/spec/{shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb → unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb} +43 -23
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_numericality_of_matcher_spec.rb +3 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_presence_of_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +127 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validation_message_finder_spec.rb +8 -6
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matcher_spec.rb +217 -26
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matchers/model_reflection_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/define_enum_for_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_column_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_index_matcher_spec.rb +8 -5
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_readonly_attributes_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/serialize_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_collection_spec.rb +29 -7
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_spec.rb +20 -10
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/object_double_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/proxy_implementation_spec.rb +13 -6
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/stub_implementation_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +77 -0
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak_spec.rb +11 -3
- data/spec/{shoulda → unit/shoulda}/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +1 -1
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +517 -0
- data/spec/unit_spec_helper.rb +66 -0
- data/spec/warnings_spy/partitioner.rb +10 -3
- data/spec/warnings_spy/reader.rb +9 -20
- data/spec/warnings_spy/reporter.rb +2 -1
- metadata +212 -149
- data/features/activemodel_integration.feature +0 -15
- data/features/rails_integration.feature +0 -160
- data/features/step_definitions/activemodel_steps.rb +0 -21
- data/features/step_definitions/rails_steps.rb +0 -227
- data/features/support/env.rb +0 -6
- data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -70
- data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -113
- data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +0 -153
- data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -47
- data/spec/shoulda/matchers/doublespeak/world_spec.rb +0 -70
- data/spec/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -309
- data/spec/spec_helper.rb +0 -42
- data/spec/support/active_model_versions.rb +0 -13
- data/spec/support/active_resource_builder.rb +0 -29
- data/spec/support/activemodel_helpers.rb +0 -23
- data/spec/support/capture_helpers.rb +0 -19
- data/spec/support/class_builder.rb +0 -46
- data/spec/support/controller_builder.rb +0 -102
- data/spec/support/fail_with_message_including_matcher.rb +0 -44
- data/spec/support/fail_with_message_matcher.rb +0 -44
- data/spec/support/i18n_faker.rb +0 -10
- data/spec/support/mailer_builder.rb +0 -10
- data/spec/support/model_builder.rb +0 -81
- data/spec/support/rails_versions.rb +0 -26
- data/spec/support/test_application.rb +0 -120
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActionController::CallbackMatcher do
|
3
|
+
describe Shoulda::Matchers::ActionController::CallbackMatcher, type: :controller do
|
4
4
|
shared_examples 'CallbackMatcher' do |kind, callback_type|
|
5
5
|
let(:kind) { kind }
|
6
6
|
let(:callback_type) { callback_type }
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActionController::FilterParamMatcher do
|
3
|
+
describe Shoulda::Matchers::ActionController::FilterParamMatcher, type: :controller do
|
4
4
|
it 'accepts filtering a filtered parameter' do
|
5
5
|
filter(:secret)
|
6
6
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActionController::RedirectToMatcher do
|
3
|
+
describe Shoulda::Matchers::ActionController::RedirectToMatcher, type: :controller do
|
4
4
|
context 'a controller that redirects' do
|
5
5
|
it 'accepts redirecting to that url' do
|
6
6
|
expect(controller_redirecting_to('/some/url')).to redirect_to('/some/url')
|
@@ -37,6 +37,6 @@ describe Shoulda::Matchers::ActionController::RedirectToMatcher do
|
|
37
37
|
it 'provides the correct description when provided a block' do
|
38
38
|
matcher = redirect_to('somewhere else') { '/some/other/url' }
|
39
39
|
|
40
|
-
expect(matcher.description).to eq 'redirect to somewhere else'
|
40
|
+
expect(matcher.description).to eq 'redirect to "somewhere else"'
|
41
41
|
end
|
42
42
|
end
|
data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_template_matcher_spec.rb
RENAMED
@@ -1,8 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
|
4
|
-
include ActionController::TemplateAssertions
|
1
|
+
require 'unit_spec_helper'
|
5
2
|
|
3
|
+
describe Shoulda::Matchers::ActionController::RenderTemplateMatcher, type: :controller do
|
6
4
|
context 'a controller that renders a template' do
|
7
5
|
it 'accepts rendering that template' do
|
8
6
|
expect(controller_with_show).to render_template(:show)
|
data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_with_layout_matcher_spec.rb
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
|
3
|
+
describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher, type: :controller do
|
4
4
|
include ActionController::TemplateAssertions
|
5
5
|
|
6
6
|
context 'a controller that renders with a layout' do
|
@@ -41,15 +41,18 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
|
|
41
41
|
|
42
42
|
context 'given a context with layouts' do
|
43
43
|
it 'accepts that layout in that context' do
|
44
|
-
|
44
|
+
context = Object.new
|
45
|
+
set_layout_in_context(context, 'happy')
|
45
46
|
|
46
|
-
expect(controller_without_layout).
|
47
|
+
expect(controller_without_layout).
|
48
|
+
to render_with_layout('happy').
|
49
|
+
in_context(context)
|
47
50
|
end
|
48
51
|
|
49
|
-
def
|
52
|
+
def set_layout_in_context(context, layout)
|
50
53
|
layouts = Hash.new(0)
|
51
54
|
layouts[layout] = 1
|
52
|
-
|
55
|
+
context.instance_variable_set(layouts_ivar, layouts)
|
53
56
|
end
|
54
57
|
|
55
58
|
def layouts_ivar
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActionController::RescueFromMatcher do
|
3
|
+
describe Shoulda::Matchers::ActionController::RescueFromMatcher, type: :controller do
|
4
4
|
context 'a controller that rescues from RuntimeError' do
|
5
5
|
it 'asserts controller is setup with rescue_from' do
|
6
6
|
expect(controller_with_rescue_from).to rescue_from RuntimeError
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActionController::RespondWithMatcher do
|
3
|
+
describe Shoulda::Matchers::ActionController::RespondWithMatcher, type: :controller do
|
4
4
|
statuses = { success: 200, redirect: 301, missing: 404, error: 500,
|
5
5
|
not_implemented: 501 }
|
6
6
|
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe 'Shoulda::Matchers::ActionController::RouteMatcher', type: :controller do
|
4
|
+
shared_examples_for 'a controller with a defined route' do
|
5
|
+
context 'when controller and action are specified as explicit options' do
|
6
|
+
it 'accepts' do
|
7
|
+
expect(controller_with_defined_routes).
|
8
|
+
to route(:get, "/#{controller_path}").
|
9
|
+
to(action: 'index')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'accepts a symbol controller' do
|
13
|
+
expect(controller_with_defined_routes).
|
14
|
+
to route(:get, "/#{controller_path}").
|
15
|
+
to(controller: controller_path.to_sym, action: 'index')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'accepts a symbol action' do
|
19
|
+
expect(controller_with_defined_routes).
|
20
|
+
to route(:get, "/#{controller_path}").
|
21
|
+
to(action: :index)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'rejects an undefined route' do
|
25
|
+
expect(controller_with_defined_routes).
|
26
|
+
not_to route(:get, '/non_existent_route').
|
27
|
+
to(action: 'non_existent')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'rejects a route for another controller' do
|
31
|
+
define_controller_with_defined_routes
|
32
|
+
other_controller = define_controller('Other').new
|
33
|
+
expect(other_controller).
|
34
|
+
not_to route(:get, "/#{controller_path}").
|
35
|
+
to(action: 'index')
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when route has parameters' do
|
39
|
+
it 'accepts a non-string parameter' do
|
40
|
+
expect(controller_with_defined_routes).
|
41
|
+
to route(:get, "/#{controller_path}/1").
|
42
|
+
to(action: 'show', id: 1)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'rejects a route for different parameters' do
|
46
|
+
expect(controller_with_defined_routes).
|
47
|
+
not_to route(:get, "/#{controller_path}/1").
|
48
|
+
to(action: 'show', some: 'other', params: 'here')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when controller and action are specified as a joined string' do
|
54
|
+
it 'accepts' do
|
55
|
+
expect(controller_with_defined_routes).
|
56
|
+
to route(:get, "/#{controller_path}").
|
57
|
+
to("#{controller_path}#index")
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when route has parameters' do
|
61
|
+
it 'accepts a non-string parameter' do
|
62
|
+
expect(controller_with_defined_routes).
|
63
|
+
to route(:get, "/#{controller_path}/1").
|
64
|
+
to("#{controller_path}#show", id: 1)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def controller_with_defined_routes
|
70
|
+
@_controller_with_defined_routes ||= begin
|
71
|
+
controller_class = define_controller(controller_name)
|
72
|
+
_controller_path = controller_path
|
73
|
+
|
74
|
+
setup_rails_controller_test(controller_class)
|
75
|
+
|
76
|
+
define_routes do
|
77
|
+
get "/#{_controller_path}", to: "#{_controller_path}#index"
|
78
|
+
get "/#{_controller_path}/:id", to: "#{_controller_path}#show"
|
79
|
+
end
|
80
|
+
|
81
|
+
controller
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def controller_path
|
86
|
+
controller_name.sub(/Controller$/, '').underscore
|
87
|
+
end
|
88
|
+
|
89
|
+
alias_method :define_controller_with_defined_routes,
|
90
|
+
:controller_with_defined_routes
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'given a controller with a defined glob url' do
|
94
|
+
it 'accepts glob route' do
|
95
|
+
controller_class = define_controller('Examples')
|
96
|
+
setup_rails_controller_test(controller_class)
|
97
|
+
|
98
|
+
define_routes do
|
99
|
+
get '/examples/*id', to: 'examples#example'
|
100
|
+
end
|
101
|
+
|
102
|
+
expect(controller).to route(:get, '/examples/foo/bar').
|
103
|
+
to(action: 'example', id: 'foo/bar')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'given a controller that is not namespaced' do
|
108
|
+
it_behaves_like 'a controller with a defined route' do
|
109
|
+
def controller_name
|
110
|
+
'ExamplesController'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'given a controller that is namespaced' do
|
116
|
+
it_behaves_like 'a controller with a defined route' do
|
117
|
+
before do
|
118
|
+
define_module('Admin')
|
119
|
+
end
|
120
|
+
|
121
|
+
def controller_name
|
122
|
+
'Admin::ExamplesController'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActionController::RouteParams do
|
3
|
+
describe Shoulda::Matchers::ActionController::RouteParams, type: :controller do
|
4
4
|
describe "#normalize" do
|
5
5
|
context "when the route parameters is a hash" do
|
6
6
|
it "stringifies the values in the hash" do
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActionController, type: :controller do
|
4
|
+
describe '#set_the_flash' do
|
5
|
+
it 'is deprecated in favor of #set_flash' do
|
6
|
+
expect { set_the_flash }.to deprecate(:set_the_flash, :set_flash)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'still works regardless' do
|
10
|
+
silence_warnings do
|
11
|
+
expect(controller_with_flash(notice: 'hi')).to set_the_flash
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#set_flash' do
|
17
|
+
it 'fails with unmatchable #to' do
|
18
|
+
expect { set_flash.to(1) }.to raise_error('cannot match against 1')
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'a controller that sets a flash message' do
|
22
|
+
it 'accepts setting any flash message' do
|
23
|
+
expect(controller_with_flash(notice: 'hi')).to set_flash
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'accepts setting the exact flash message' do
|
27
|
+
expect(controller_with_flash(notice: 'hi')).to set_flash.to('hi')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts setting a matched flash message' do
|
31
|
+
expect(controller_with_flash(notice: 'hello')).to set_flash.to(/he/)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'rejects setting a different flash message' do
|
35
|
+
expect(controller_with_flash(notice: 'hi')).
|
36
|
+
not_to set_flash.to('other')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'rejects setting a different pattern' do
|
40
|
+
expect(controller_with_flash(notice: 'hi')).
|
41
|
+
not_to set_flash.to(/other/)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'a controller that sets a flash.now message' do
|
46
|
+
it 'rejects setting any flash message' do
|
47
|
+
expect(controller_with_flash_now).not_to set_flash
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'accepts setting any flash.now message' do
|
51
|
+
expect(controller_with_flash_now).to set_flash.now
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'accepts setting the exact flash.now message' do
|
55
|
+
expect(controller_with_flash_now(notice: 'hi')).
|
56
|
+
to set_flash.now.to('hi')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'accepts setting a matched flash.now message' do
|
60
|
+
expect(controller_with_flash_now(notice: 'flasher')).
|
61
|
+
to set_flash.now.to(/lash/)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'rejects setting a different flash.now message' do
|
65
|
+
expect(controller_with_flash_now(notice: 'hi')).
|
66
|
+
not_to set_flash.now.to('other')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'rejects setting a different flash.now pattern' do
|
70
|
+
expect(controller_with_flash_now(notice: 'hi')).
|
71
|
+
not_to set_flash.now.to(/other/)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'a controller that sets flash messages for multiple keys' do
|
76
|
+
it 'accepts flash message for either key' do
|
77
|
+
controller = controller_with_flash(notice: 'one', alert: 'two')
|
78
|
+
|
79
|
+
expect(controller).to set_flash[:notice]
|
80
|
+
expect(controller).to set_flash[:alert]
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'rejects a flash message that is not one of the set keys' do
|
84
|
+
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
85
|
+
not_to set_flash[:warning]
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'accepts exact flash message of notice' do
|
89
|
+
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
90
|
+
to set_flash[:notice].to('one')
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'accepts setting a matched flash message of notice' do
|
94
|
+
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
95
|
+
to set_flash[:notice].to(/on/)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'rejects setting a different flash message of notice' do
|
99
|
+
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
100
|
+
not_to set_flash[:notice].to('other')
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'rejects setting a different pattern' do
|
104
|
+
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
105
|
+
not_to set_flash[:notice].to(/other/)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'a controller that sets flash and flash.now' do
|
110
|
+
it 'accepts setting any flash.now message' do
|
111
|
+
controller = build_fake_response do
|
112
|
+
flash.now[:notice] = 'value'
|
113
|
+
flash[:success] = 'great job'
|
114
|
+
end
|
115
|
+
|
116
|
+
expect(controller).to set_flash.now
|
117
|
+
expect(controller).to set_flash
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'accepts setting a matched flash.now message' do
|
121
|
+
controller = build_fake_response do
|
122
|
+
flash.now[:notice] = 'value'
|
123
|
+
flash[:success] = 'great job'
|
124
|
+
end
|
125
|
+
|
126
|
+
expect(controller).to set_flash.now.to(/value/)
|
127
|
+
expect(controller).to set_flash.to(/great/)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'rejects setting a different flash.now message' do
|
131
|
+
controller = build_fake_response do
|
132
|
+
flash.now[:notice] = 'value'
|
133
|
+
flash[:success] = 'great job'
|
134
|
+
end
|
135
|
+
|
136
|
+
expect(controller).not_to set_flash.now.to('other')
|
137
|
+
expect(controller).not_to set_flash.to('other')
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'a controller that does not set a flash message' do
|
142
|
+
it 'rejects setting any flash message' do
|
143
|
+
expect(controller_with_no_flashes).not_to set_flash
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def controller_with_no_flashes
|
149
|
+
build_fake_response
|
150
|
+
end
|
151
|
+
|
152
|
+
def controller_with_flash(flash_hash)
|
153
|
+
build_fake_response do
|
154
|
+
flash_hash.each do |key, value|
|
155
|
+
flash[key] = value
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def controller_with_flash_now(flash_hash = { notice: 'hi' })
|
161
|
+
build_fake_response do
|
162
|
+
flash_hash.each do |key, value|
|
163
|
+
flash.now[key] = value
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,294 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActionController, '#set_session', type: :controller do
|
4
|
+
context 'passing an argument to the initializer' do
|
5
|
+
it 'is deprecated in favor of using #[]' do
|
6
|
+
expectation = proc { set_session(:foo) }
|
7
|
+
|
8
|
+
expect(&expectation).to print_warning_including(
|
9
|
+
'Passing a key to set_session is deprecated'
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'still works regardless' do
|
14
|
+
silence_warnings do
|
15
|
+
expect(controller_with_session(var: 'hi')).to set_session(:var)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'a controller that sets a session variable' do
|
21
|
+
context 'without any qualifiers' do
|
22
|
+
it 'accepts' do
|
23
|
+
expect(controller_with_session(var: 'hi')).to set_session
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with #to' do
|
28
|
+
context 'given a static value' do
|
29
|
+
context 'when any key in session has the given value' do
|
30
|
+
it 'accepts' do
|
31
|
+
expect(controller_with_session(var: 'hi')).
|
32
|
+
to set_session.to('hi')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'accepts given nil' do
|
36
|
+
silence_warnings do
|
37
|
+
expect(controller_with_session(var: nil)).
|
38
|
+
to set_session.to(nil)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'accepts given false' do
|
43
|
+
expect(controller_with_session(var: false)).
|
44
|
+
to set_session.to(false)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when no key in session has the given value' do
|
49
|
+
it 'rejects' do
|
50
|
+
expect(controller_with_session(var: 'hi')).
|
51
|
+
not_to set_session.to('different')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'given a dynamic value' do
|
57
|
+
context 'when any key in session has the given value' do
|
58
|
+
it 'accepts' do
|
59
|
+
context = double(expected: 'hi')
|
60
|
+
expect(controller_with_session(var: 'hi')).
|
61
|
+
to set_session.in_context(context).to { expected }
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'accepts given nil' do
|
65
|
+
silence_warnings do
|
66
|
+
context = double(expected: nil)
|
67
|
+
expect(controller_with_session(var: nil)).
|
68
|
+
to set_session.in_context(context).to { expected }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'accepts given false' do
|
73
|
+
context = double(expected: false)
|
74
|
+
expect(controller_with_session(var: false)).
|
75
|
+
to set_session.in_context(context).to { expected }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when no key in session has the given value' do
|
80
|
+
it 'rejects' do
|
81
|
+
context = double(expected: 'different')
|
82
|
+
expect(controller_with_session(var: 'hi')).
|
83
|
+
not_to set_session.in_context(context).to { expected }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'given a regexp' do
|
89
|
+
context 'when any value in session matches the regexp' do
|
90
|
+
it 'accepts' do
|
91
|
+
expect(controller_with_session(var: 'hello')).
|
92
|
+
to set_session.to(/ello/)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when no value in session matches the regexp' do
|
97
|
+
it 'rejects' do
|
98
|
+
expect(controller_with_session(var: 'hello')).
|
99
|
+
not_to set_session.to(/different/)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'with #[]' do
|
106
|
+
context 'when the given key is present in session' do
|
107
|
+
it 'accepts' do
|
108
|
+
expect(controller_with_session(var: 'hi')).to set_session[:var]
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'accepts when expected key is a string' do
|
112
|
+
expect(controller_with_session(var: 'hi')).to set_session['var']
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when the given key is not present in session' do
|
117
|
+
it 'rejects' do
|
118
|
+
expect(controller_with_session(var: 'hi')).not_to set_session[:other]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'with #[] + #to' do
|
124
|
+
context 'given a static value' do
|
125
|
+
context 'when the given key and value are present in session' do
|
126
|
+
it 'accepts' do
|
127
|
+
expect(controller_with_session(var: 'hi')).
|
128
|
+
to set_session[:var].to('hi')
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'accepts given nil' do
|
132
|
+
silence_warnings do
|
133
|
+
expect(controller_with_session(var: nil)).
|
134
|
+
to set_session[:var].to(nil)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'accepts given false' do
|
139
|
+
expect(controller_with_session(var: false)).
|
140
|
+
to set_session[:var].to(false)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when the given key is present in session but not the given value' do
|
145
|
+
it 'rejects' do
|
146
|
+
expect(controller_with_session(var: 'hi')).
|
147
|
+
not_to set_session[:var].to('other')
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'rejects given nil' do
|
151
|
+
expect(controller_with_session(var: 'hi')).
|
152
|
+
not_to set_session[:var].to(nil)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'when the given key is not present in session' do
|
157
|
+
it 'accepts given nil' do
|
158
|
+
silence_warnings do
|
159
|
+
expect(controller_with_session(var: 'hi')).
|
160
|
+
to set_session[:other].to(nil)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'rejects given false' do
|
165
|
+
expect(controller_with_session(var: false)).
|
166
|
+
not_to set_session[:other].to(false)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'given a dynamic value' do
|
172
|
+
context 'when the given key and value are present in session' do
|
173
|
+
it 'accepts' do
|
174
|
+
context = double(expected: 'value')
|
175
|
+
|
176
|
+
expect(controller_with_session(var: 'value')).
|
177
|
+
to set_session[:var].in_context(context).to { expected }
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'accepts given nil' do
|
181
|
+
silence_warnings do
|
182
|
+
context = double(expected: nil)
|
183
|
+
|
184
|
+
expect(controller_with_session(var: nil)).
|
185
|
+
to set_session[:var].in_context(context).to { expected }
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'accepts given false' do
|
190
|
+
context = double(expected: false)
|
191
|
+
|
192
|
+
expect(controller_with_session(var: false)).
|
193
|
+
to set_session[:var].in_context(context).to { expected }
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when the given key is present in session but not the given value' do
|
198
|
+
it 'rejects given nil' do
|
199
|
+
context = double(expected: nil)
|
200
|
+
|
201
|
+
expect(controller_with_session(var: 'hi')).
|
202
|
+
not_to set_session[:var].in_context(context).to { expected }
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'rejects given false' do
|
206
|
+
context = double(expected: false)
|
207
|
+
|
208
|
+
expect(controller_with_session(var: 'hi')).
|
209
|
+
not_to set_session[:var].in_context(context).to { expected }
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'when the given key is not present in session' do
|
214
|
+
it 'rejects' do
|
215
|
+
context = double(expected: 'other')
|
216
|
+
|
217
|
+
expect(controller_with_session(var: 'unexpected')).
|
218
|
+
not_to set_session[:var].in_context(context).to { expected }
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'accepts given nil' do
|
222
|
+
silence_warnings do
|
223
|
+
context = double(expected: nil)
|
224
|
+
|
225
|
+
expect(controller_with_session(var: 'hi')).
|
226
|
+
to set_session[:other].in_context(context).to { expected }
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'rejects given false' do
|
231
|
+
context = double(expected: false)
|
232
|
+
|
233
|
+
expect(controller_with_session(var: false)).
|
234
|
+
not_to set_session[:other].in_context(context).to { expected }
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context 'a controller that does not set any session variables' do
|
242
|
+
context 'without any qualifiers' do
|
243
|
+
it 'rejects' do
|
244
|
+
expect(controller_without_session).not_to set_session
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
context 'with #[]' do
|
249
|
+
it 'rejects' do
|
250
|
+
expect(controller_without_session).
|
251
|
+
not_to set_session['any key']
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'with #to' do
|
256
|
+
it 'rejects' do
|
257
|
+
expect(controller_without_session).
|
258
|
+
not_to set_session.to('any value')
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'with #[] + #to' do
|
263
|
+
it 'rejects' do
|
264
|
+
expect(controller_without_session).
|
265
|
+
not_to set_session['any key'].to('any value')
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'prints a warning when using .to(nil) to assert that a variable is unset' do
|
269
|
+
expectation = proc do
|
270
|
+
expect(controller_without_session).to set_session['any key'].to(nil)
|
271
|
+
end
|
272
|
+
|
273
|
+
expected_warning = <<EOT
|
274
|
+
Using `should set_session[...].to(nil)` to assert that a variable is unset is deprecated.
|
275
|
+
Please use `should_not set_session[...]` instead.
|
276
|
+
EOT
|
277
|
+
|
278
|
+
expect(&expectation).to print_warning_including(expected_warning)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def controller_without_session
|
284
|
+
build_fake_response
|
285
|
+
end
|
286
|
+
|
287
|
+
def controller_with_session(session_hash)
|
288
|
+
build_fake_response do
|
289
|
+
session_hash.each do |key, value|
|
290
|
+
session[key] = value
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|