mcmire-shoulda-matchers 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +32 -0
- data/.yardopts +7 -0
- data/Appraisals +45 -0
- data/CONTRIBUTING.md +41 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +166 -0
- data/MIT-LICENSE +22 -0
- data/NEWS.md +299 -0
- data/README.md +163 -0
- data/Rakefile +116 -0
- data/doc_config/gh-pages/index.html.erb +9 -0
- data/doc_config/yard/setup.rb +22 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +5967 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +12 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/global.css +45 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +69 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/style.css +283 -0
- data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +32 -0
- data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +1 -0
- data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +8 -0
- data/doc_config/yard/templates/default/fulldoc/html/js/app.js +300 -0
- data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +1 -0
- data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +289 -0
- data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +6 -0
- data/doc_config/yard/templates/default/fulldoc/html/setup.rb +8 -0
- data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +14 -0
- data/doc_config/yard/templates/default/layout/html/fonts.erb +1 -0
- data/doc_config/yard/templates/default/layout/html/layout.erb +23 -0
- data/doc_config/yard/templates/default/layout/html/search.erb +13 -0
- data/doc_config/yard/templates/default/layout/html/setup.rb +8 -0
- data/doc_config/yard/templates/default/method_details/html/source.erb +10 -0
- data/doc_config/yard/templates/default/module/html/box_info.erb +31 -0
- data/features/rails_integration.feature +113 -0
- data/features/step_definitions/rails_steps.rb +162 -0
- data/features/support/env.rb +5 -0
- data/gemfiles/3.0.gemfile +24 -0
- data/gemfiles/3.0.gemfile.lock +150 -0
- data/gemfiles/3.1.gemfile +27 -0
- data/gemfiles/3.1.gemfile.lock +173 -0
- data/gemfiles/3.2.gemfile +27 -0
- data/gemfiles/3.2.gemfile.lock +171 -0
- data/gemfiles/4.0.0.gemfile +28 -0
- data/gemfiles/4.0.0.gemfile.lock +172 -0
- data/gemfiles/4.0.1.gemfile +28 -0
- data/gemfiles/4.0.1.gemfile.lock +172 -0
- data/lib/shoulda-matchers.rb +1 -0
- data/lib/shoulda/matchers.rb +11 -0
- data/lib/shoulda/matchers/action_controller.rb +17 -0
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +64 -0
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +97 -0
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +81 -0
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +117 -0
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +114 -0
- data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +154 -0
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +116 -0
- data/lib/shoulda/matchers/action_controller/route_params.rb +48 -0
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +164 -0
- data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +296 -0
- data/lib/shoulda/matchers/active_model.rb +30 -0
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +167 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +314 -0
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +46 -0
- data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +160 -0
- data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +417 -0
- data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +337 -0
- data/lib/shoulda/matchers/active_model/errors.rb +10 -0
- data/lib/shoulda/matchers/active_model/exception_message_finder.rb +58 -0
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +92 -0
- data/lib/shoulda/matchers/active_model/helpers.rb +46 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +75 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +27 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +41 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +27 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +26 -0
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +112 -0
- data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +77 -0
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +121 -0
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +380 -0
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +89 -0
- data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +372 -0
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +97 -0
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +69 -0
- data/lib/shoulda/matchers/active_record.rb +22 -0
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +204 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +901 -0
- data/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
- data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +41 -0
- data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +41 -0
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +81 -0
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +65 -0
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +94 -0
- data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +41 -0
- data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +41 -0
- data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +63 -0
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +261 -0
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +149 -0
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +72 -0
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +181 -0
- data/lib/shoulda/matchers/assertion_error.rb +19 -0
- data/lib/shoulda/matchers/error.rb +6 -0
- data/lib/shoulda/matchers/integrations/rspec.rb +20 -0
- data/lib/shoulda/matchers/integrations/test_unit.rb +30 -0
- data/lib/shoulda/matchers/rails_shim.rb +50 -0
- data/lib/shoulda/matchers/version.rb +6 -0
- data/lib/shoulda/matchers/warn.rb +8 -0
- data/shoulda-matchers.gemspec +23 -0
- data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +22 -0
- data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +42 -0
- data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +78 -0
- data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +63 -0
- data/spec/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +63 -0
- data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +31 -0
- data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +70 -0
- data/spec/shoulda/matchers/action_controller/route_params_spec.rb +30 -0
- data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +51 -0
- data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +153 -0
- data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +111 -0
- data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +170 -0
- data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +81 -0
- data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +95 -0
- data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +320 -0
- data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +166 -0
- data/spec/shoulda/matchers/active_model/exception_message_finder_spec.rb +111 -0
- data/spec/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +20 -0
- data/spec/shoulda/matchers/active_model/helpers_spec.rb +158 -0
- data/spec/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +169 -0
- data/spec/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +59 -0
- data/spec/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +59 -0
- data/spec/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +57 -0
- data/spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +139 -0
- data/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +41 -0
- data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +47 -0
- data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +331 -0
- data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +180 -0
- data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +398 -0
- data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +127 -0
- data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +107 -0
- data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +860 -0
- data/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +247 -0
- data/spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +111 -0
- data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +78 -0
- data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +41 -0
- data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +86 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/active_model_versions.rb +13 -0
- data/spec/support/active_resource_builder.rb +29 -0
- data/spec/support/activemodel_helpers.rb +19 -0
- data/spec/support/capture_helpers.rb +19 -0
- data/spec/support/class_builder.rb +42 -0
- data/spec/support/controller_builder.rb +74 -0
- data/spec/support/fail_with_message_including_matcher.rb +33 -0
- data/spec/support/fail_with_message_matcher.rb +32 -0
- data/spec/support/i18n_faker.rb +10 -0
- data/spec/support/mailer_builder.rb +10 -0
- data/spec/support/model_builder.rb +81 -0
- data/spec/support/rails_versions.rb +18 -0
- data/spec/support/shared_examples/numerical_submatcher.rb +19 -0
- data/spec/support/shared_examples/numerical_type_submatcher.rb +17 -0
- data/spec/support/test_application.rb +120 -0
- data/yard.watchr +5 -0
- metadata +281 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
|
4
|
+
include ActionController::TemplateAssertions
|
5
|
+
|
6
|
+
context 'a controller that renders with a layout' do
|
7
|
+
it 'accepts rendering with any layout' do
|
8
|
+
expect(controller_with_wide_layout).to render_with_layout
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'accepts rendering with that layout' do
|
12
|
+
expect(controller_with_wide_layout).to render_with_layout(:wide)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'rejects rendering with another layout' do
|
16
|
+
expect(controller_with_wide_layout).not_to render_with_layout(:other)
|
17
|
+
end
|
18
|
+
|
19
|
+
def controller_with_wide_layout
|
20
|
+
create_view('layouts/wide.html.erb', 'some content, <%= yield %>')
|
21
|
+
build_response { render layout: 'wide' }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'a controller that renders without a layout' do
|
26
|
+
|
27
|
+
it 'rejects rendering with a layout' do
|
28
|
+
controller_without_layout = build_response { render layout: false }
|
29
|
+
|
30
|
+
expect(controller_without_layout).not_to render_with_layout
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'a controller that renders a partial' do
|
35
|
+
it 'rejects rendering with a layout' do
|
36
|
+
controller_with_partial = build_response { render partial: 'partial' }
|
37
|
+
|
38
|
+
expect(controller_with_partial).not_to render_with_layout
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'given a context with layouts' do
|
43
|
+
it 'accepts that layout in that context' do
|
44
|
+
set_in_context_layout('happy')
|
45
|
+
|
46
|
+
expect(controller_without_layout).to render_with_layout('happy').in_context(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_in_context_layout(layout)
|
50
|
+
layouts = Hash.new(0)
|
51
|
+
layouts[layout] = 1
|
52
|
+
self.instance_variable_set(layouts_ivar, layouts)
|
53
|
+
end
|
54
|
+
|
55
|
+
def layouts_ivar
|
56
|
+
Shoulda::Matchers::RailsShim.layouts_ivar
|
57
|
+
end
|
58
|
+
|
59
|
+
def controller_without_layout
|
60
|
+
build_response { render layout: false }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActionController::RescueFromMatcher do
|
4
|
+
context 'a controller that rescues from RuntimeError' do
|
5
|
+
it "asserts controller is setup with rescue_from" do
|
6
|
+
expect(controller_with_rescue_from).to rescue_from RuntimeError
|
7
|
+
end
|
8
|
+
|
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)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "asserts rescue_from was not set up with incorrect handler method" do
|
15
|
+
expect(controller_with_rescue_from_and_method).not_to rescue_from(RuntimeError).with(:other_method)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "asserts the controller responds to the handler method" do
|
19
|
+
matcher = rescue_from(RuntimeError).with(:error_method)
|
20
|
+
expect(matcher.matches?(controller_with_rescue_from_and_invalid_method)).to eq false
|
21
|
+
expect(matcher.failure_message).to match(/does not respond to/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'without a handler method' do
|
26
|
+
it "the handler method is not included in the description" do
|
27
|
+
matcher = rescue_from(RuntimeError)
|
28
|
+
expect(matcher.matches?(controller_with_rescue_from)).to eq true
|
29
|
+
expect(matcher.description).not_to match(/with #/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'a controller that does not rescue from RuntimeError' do
|
35
|
+
it "asserts controller is not setup with rescue_from" do
|
36
|
+
matcher = rescue_from RuntimeError
|
37
|
+
expect(define_controller("RandomController")).not_to matcher
|
38
|
+
expect(matcher.failure_message_when_negated).to match(/Did not expect \w+ to rescue from/)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def controller_with_rescue_from
|
43
|
+
define_controller "RescueRuntimeError" do
|
44
|
+
rescue_from(RuntimeError) {}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def controller_with_rescue_from_and_invalid_method
|
49
|
+
define_controller "RescueRuntimeErrorWithMethod" do
|
50
|
+
rescue_from RuntimeError, with: :error_method
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def controller_with_rescue_from_and_method
|
55
|
+
controller = controller_with_rescue_from_and_invalid_method
|
56
|
+
class << controller
|
57
|
+
def error_method
|
58
|
+
true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
controller
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActionController::RespondWithMatcher do
|
4
|
+
statuses = { success: 200, redirect: 301, missing: 404, error: 500,
|
5
|
+
not_implemented: 501 }
|
6
|
+
|
7
|
+
statuses.each do |human_name, numeric_code|
|
8
|
+
context "a controller responding with #{human_name}" do
|
9
|
+
it 'accepts responding with a numeric response code' do
|
10
|
+
expect(controller_with_status(numeric_code)).to respond_with(numeric_code)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'accepts responding with a symbol response code' do
|
14
|
+
expect(controller_with_status(numeric_code)).to respond_with(human_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'rejects responding with another status' do
|
18
|
+
another_status = statuses.except(human_name).keys.first
|
19
|
+
|
20
|
+
expect(controller_with_status(numeric_code)).
|
21
|
+
not_to respond_with(another_status)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def controller_with_status(status)
|
27
|
+
build_response do
|
28
|
+
render text: 'text', status: status
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActionController::RouteMatcher, type: :controller do
|
4
|
+
context 'given a controller with a defined glob url' do
|
5
|
+
it 'accepts glob route' do
|
6
|
+
controller = define_controller('Examples').new
|
7
|
+
|
8
|
+
define_routes do
|
9
|
+
get 'examples/*id', to: 'examples#example'
|
10
|
+
end
|
11
|
+
|
12
|
+
expect(controller).to route(:get, '/examples/foo/bar').
|
13
|
+
to(action: 'example', id: 'foo/bar')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'given a controller with a defined route' do
|
18
|
+
|
19
|
+
it 'accepts routing the correct path to the correct parameters' do
|
20
|
+
expect(route_examples_to_examples).to route(:get, '/examples/1').
|
21
|
+
to(action: 'example', id: '1')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'accepts a symbol controller' do
|
25
|
+
route_examples_to_examples
|
26
|
+
expect(Object.new).to route(:get, '/examples/1').
|
27
|
+
to(controller: :examples, action: 'example', id: '1')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts a symbol action' do
|
31
|
+
expect(route_examples_to_examples).to route(:get, '/examples/1').
|
32
|
+
to(action: :example, id: '1')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'accepts a non-string parameter' do
|
36
|
+
expect(route_examples_to_examples).to route(:get, '/examples/1').
|
37
|
+
to(action: 'example', id: 1)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'rejects an undefined route' do
|
41
|
+
expect(route_examples_to_examples).
|
42
|
+
not_to route(:get, '/bad_route').to(var: 'value')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'rejects a route for another controller' do
|
46
|
+
route_examples_to_examples
|
47
|
+
other = define_controller('Other').new
|
48
|
+
expect(other).not_to route(:get, '/examples/1').
|
49
|
+
to(action: 'example', id: '1')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'rejects a route for different parameters' do
|
53
|
+
expect(route_examples_to_examples).not_to route(:get, '/examples/1').
|
54
|
+
to(action: 'other', id: '1')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "accepts a string as first parameter" do
|
58
|
+
expect(route_examples_to_examples).to route(:get, '/examples/1').
|
59
|
+
to("examples#example", id: '1')
|
60
|
+
end
|
61
|
+
|
62
|
+
def route_examples_to_examples
|
63
|
+
define_routes do
|
64
|
+
get 'examples/:id', to: 'examples#example'
|
65
|
+
end
|
66
|
+
|
67
|
+
define_controller('Examples').new
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActionController::RouteParams do
|
4
|
+
describe "#normalize" do
|
5
|
+
context "when the route parameters is a hash" do
|
6
|
+
it "stringifies the values in the hash" do
|
7
|
+
expect(build_route_params(controller: :examples, action: 'example', id: '1').normalize).
|
8
|
+
to eq({ controller: "examples", action: "example", id: "1" })
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when the route parameters is a string and a hash" do
|
13
|
+
it "produces a hash of route parameters" do
|
14
|
+
expect(build_route_params("examples#example", id: '1').normalize).
|
15
|
+
to eq({ controller: "examples", action: "example", id: "1" })
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when the route params is a string" do
|
20
|
+
it "produces a hash of route params" do
|
21
|
+
expect(build_route_params("examples#index").normalize).
|
22
|
+
to eq({ controller: "examples", action: "index"})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_route_params(*params)
|
28
|
+
Shoulda::Matchers::ActionController::RouteParams.new(params)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActionController::SetSessionMatcher do
|
4
|
+
context 'a controller that sets a session variable' do
|
5
|
+
it 'accepts assigning to that variable' do
|
6
|
+
expect(controller_with_session(var: 'hi')).to set_session(:var)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'accepts assigning the correct value to that variable' do
|
10
|
+
expect(controller_with_session(var: 'hi')).to set_session(:var).to('hi')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'rejects assigning another value to that variable' do
|
14
|
+
expect(controller_with_session(var: 'hi')).not_to set_session(:var).to('other')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'rejects assigning to another variable' do
|
18
|
+
expect(controller_with_session(var: 'hi')).not_to set_session(:other)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'accepts assigning nil to another variable' do
|
22
|
+
expect(controller_with_session(var: 'hi')).to set_session(:other).to(nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'accepts assigning false to that variable' do
|
26
|
+
expect(controller_with_session(var: false)).to set_session(:var).to(false)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'accepts assigning to the same value in the test context' do
|
30
|
+
expected = 'value'
|
31
|
+
|
32
|
+
expect(controller_with_session(var: expected)).
|
33
|
+
to set_session(:var).in_context(self).to { expected }
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'rejects assigning to the another value in the test context' do
|
37
|
+
expected = 'other'
|
38
|
+
|
39
|
+
expect(controller_with_session(var: 'unexpected')).
|
40
|
+
not_to set_session(:var).in_context(self).to { expected }
|
41
|
+
end
|
42
|
+
|
43
|
+
def controller_with_session(session_hash)
|
44
|
+
build_response do
|
45
|
+
session_hash.each do |key, value|
|
46
|
+
session[key] = value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
|
4
|
+
it 'fails with unmatchable #to' do
|
5
|
+
expect { set_the_flash.to(1) }.to raise_error('cannot match against 1')
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'a controller that sets a flash message' do
|
9
|
+
it 'accepts setting any flash message' do
|
10
|
+
expect(controller_with_flash(notice: 'hi')).to set_the_flash
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'accepts setting the exact flash message' do
|
14
|
+
expect(controller_with_flash(notice: 'hi')).to set_the_flash.to('hi')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'accepts setting a matched flash message' do
|
18
|
+
expect(controller_with_flash(notice: 'hello')).to set_the_flash.to(/he/)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'rejects setting a different flash message' do
|
22
|
+
expect(controller_with_flash(notice: 'hi')).
|
23
|
+
not_to set_the_flash.to('other')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'rejects setting a different pattern' do
|
27
|
+
expect(controller_with_flash(notice: 'hi')).
|
28
|
+
not_to set_the_flash.to(/other/)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'a controller that sets a flash.now message' do
|
33
|
+
it 'rejects setting any flash message' do
|
34
|
+
expect(controller_with_flash_now).not_to set_the_flash
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'accepts setting any flash.now message' do
|
38
|
+
expect(controller_with_flash_now).to set_the_flash.now
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'accepts setting the exact flash.now message' do
|
42
|
+
expect(controller_with_flash_now(notice: 'hi')).
|
43
|
+
to set_the_flash.now.to('hi')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'accepts setting a matched flash.now message' do
|
47
|
+
expect(controller_with_flash_now(notice: 'flasher')).
|
48
|
+
to set_the_flash.now.to(/lash/)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'rejects setting a different flash.now message' do
|
52
|
+
expect(controller_with_flash_now(notice: 'hi')).
|
53
|
+
not_to set_the_flash.now.to('other')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'rejects setting a different flash.now pattern' do
|
57
|
+
expect(controller_with_flash_now(notice: 'hi')).
|
58
|
+
not_to set_the_flash.now.to(/other/)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'a controller that sets flash messages for multiple keys' do
|
63
|
+
it 'accepts flash message for either key' do
|
64
|
+
controller = controller_with_flash(notice: 'one', alert: 'two')
|
65
|
+
|
66
|
+
expect(controller).to set_the_flash[:notice]
|
67
|
+
expect(controller).to set_the_flash[:alert]
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'rejects a flash message that is not one of the set keys' do
|
71
|
+
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
72
|
+
not_to set_the_flash[:warning]
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'accepts exact flash message of notice' do
|
76
|
+
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
77
|
+
to set_the_flash[:notice].to('one')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'accepts setting a matched flash message of notice' do
|
81
|
+
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
82
|
+
to set_the_flash[:notice].to(/on/)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'rejects setting a different flash message of notice' do
|
86
|
+
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
87
|
+
not_to set_the_flash[:notice].to('other')
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'rejects setting a different pattern' do
|
91
|
+
expect(controller_with_flash(notice: 'one', alert: 'two')).
|
92
|
+
not_to set_the_flash[:notice].to(/other/)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'a controller that sets flash and flash.now' do
|
97
|
+
it 'accepts setting any flash.now message' do
|
98
|
+
controller = build_response do
|
99
|
+
flash.now[:notice] = 'value'
|
100
|
+
flash[:success] = 'great job'
|
101
|
+
end
|
102
|
+
|
103
|
+
expect(controller).to set_the_flash.now
|
104
|
+
expect(controller).to set_the_flash
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'accepts setting a matched flash.now message' do
|
108
|
+
controller = build_response do
|
109
|
+
flash.now[:notice] = 'value'
|
110
|
+
flash[:success] = 'great job'
|
111
|
+
end
|
112
|
+
|
113
|
+
expect(controller).to set_the_flash.now.to(/value/)
|
114
|
+
expect(controller).to set_the_flash.to(/great/)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'rejects setting a different flash.now message' do
|
118
|
+
controller = build_response do
|
119
|
+
flash.now[:notice] = 'value'
|
120
|
+
flash[:success] = 'great job'
|
121
|
+
end
|
122
|
+
|
123
|
+
expect(controller).not_to set_the_flash.now.to('other')
|
124
|
+
expect(controller).not_to set_the_flash.to('other')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'a controller that does not set a flash message' do
|
129
|
+
it 'rejects setting any flash message' do
|
130
|
+
expect(controller_with_no_flashes).not_to set_the_flash
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def controller_with_no_flashes
|
135
|
+
build_response
|
136
|
+
end
|
137
|
+
|
138
|
+
def controller_with_flash(flash_hash)
|
139
|
+
build_response do
|
140
|
+
flash_hash.each do |key, value|
|
141
|
+
flash[key] = value
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def controller_with_flash_now(flash_hash = { notice: 'hi' })
|
147
|
+
build_response do
|
148
|
+
flash_hash.each do |key, value|
|
149
|
+
flash.now[key] = value
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|