shoulda-matchers 3.0.0.rc1 → 3.0.0

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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -3
  3. data/Gemfile.lock +12 -41
  4. data/NEWS.md +118 -26
  5. data/README.md +34 -11
  6. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -0
  7. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +4 -0
  8. data/gemfiles/4.0.0.gemfile +2 -3
  9. data/gemfiles/4.0.0.gemfile.lock +47 -77
  10. data/gemfiles/4.0.1.gemfile +2 -3
  11. data/gemfiles/4.0.1.gemfile.lock +51 -79
  12. data/gemfiles/4.1.gemfile +2 -3
  13. data/gemfiles/4.1.gemfile.lock +73 -103
  14. data/gemfiles/4.2.gemfile +2 -3
  15. data/gemfiles/4.2.gemfile.lock +90 -124
  16. data/lib/shoulda/matchers.rb +1 -0
  17. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +6 -8
  18. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +1 -3
  19. data/lib/shoulda/matchers/action_controller/flash_store.rb +1 -8
  20. data/lib/shoulda/matchers/action_controller/permit_matcher.rb +140 -88
  21. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +2 -5
  22. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +5 -10
  23. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +2 -4
  24. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -3
  25. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +3 -5
  26. data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -7
  27. data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +35 -9
  28. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -3
  29. data/lib/shoulda/matchers/active_model.rb +57 -1
  30. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +2 -5
  31. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +162 -54
  32. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +5 -2
  33. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +1 -3
  34. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +24 -11
  35. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +4 -3
  36. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +0 -2
  37. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +4 -3
  38. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +2 -1
  39. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +15 -13
  40. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +3 -3
  41. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +3 -3
  42. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +4 -4
  43. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +8 -8
  44. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +8 -8
  45. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +12 -14
  46. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +10 -4
  47. data/lib/shoulda/matchers/active_model/validation_matcher.rb +0 -3
  48. data/lib/shoulda/matchers/active_model/validator.rb +0 -8
  49. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +4 -6
  50. data/lib/shoulda/matchers/active_record/association_matcher.rb +58 -43
  51. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +2 -2
  52. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +3 -5
  53. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +3 -5
  54. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +1 -4
  55. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +3 -5
  56. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +7 -7
  57. data/lib/shoulda/matchers/doublespeak/double.rb +10 -1
  58. data/lib/shoulda/matchers/doublespeak/double_collection.rb +13 -5
  59. data/lib/shoulda/matchers/doublespeak/method_call.rb +10 -1
  60. data/lib/shoulda/matchers/doublespeak/object_double.rb +2 -1
  61. data/lib/shoulda/matchers/doublespeak/world.rb +10 -0
  62. data/lib/shoulda/matchers/error.rb +4 -0
  63. data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +11 -10
  64. data/lib/shoulda/matchers/integrations/libraries.rb +1 -0
  65. data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
  66. data/lib/shoulda/matchers/integrations/libraries/active_model.rb +1 -1
  67. data/lib/shoulda/matchers/integrations/libraries/active_record.rb +1 -1
  68. data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -1
  69. data/lib/shoulda/matchers/integrations/libraries/routing.rb +27 -0
  70. data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
  71. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
  72. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
  73. data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
  74. data/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +2 -2
  75. data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
  76. data/lib/shoulda/matchers/routing.rb +10 -0
  77. data/lib/shoulda/matchers/version.rb +1 -1
  78. data/script/SUPPORTED_VERSIONS +1 -1
  79. data/spec/acceptance/independent_matchers_spec.rb +103 -42
  80. data/spec/doublespeak_spec_helper.rb +5 -1
  81. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +34 -11
  82. data/spec/support/acceptance/helpers/rspec_helpers.rb +9 -13
  83. data/spec/support/acceptance/helpers/step_helpers.rb +13 -0
  84. data/spec/support/acceptance/matchers/have_output.rb +1 -1
  85. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +1 -1
  86. data/spec/support/tests/command_runner.rb +5 -1
  87. data/spec/support/unit/helpers/active_record_versions.rb +0 -4
  88. data/spec/support/unit/shared_examples/set_session_or_flash.rb +8 -3
  89. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +198 -39
  90. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +269 -102
  91. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +24 -0
  92. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +118 -101
  93. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -82
  94. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +148 -121
  95. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +20 -8
  96. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +64 -183
  97. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +14 -0
  98. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +60 -0
  99. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +23 -7
  100. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +242 -0
  101. data/spec/unit_spec_helper.rb +4 -0
  102. data/tasks/documentation.rb +35 -0
  103. metadata +9 -8
  104. data/Guardfile +0 -5
  105. data/cucumber.yml +0 -1
  106. data/lib/shoulda/matchers/active_model/validator_with_captured_range_error.rb +0 -12
@@ -10,7 +10,7 @@ module Shoulda
10
10
  include Integrations::Rails
11
11
 
12
12
  def integrate_with(test_framework)
13
- test_framework.include(matchers_module)
13
+ test_framework.include(matchers_module, type: :model)
14
14
  include_into(ActiveSupport::TestCase, matchers_module)
15
15
  end
16
16
 
@@ -11,7 +11,8 @@ module Shoulda
11
11
  SUB_LIBRARIES = [
12
12
  :active_model,
13
13
  :active_record,
14
- :action_controller
14
+ :action_controller,
15
+ :routing
15
16
  ]
16
17
 
17
18
  def integrate_with(test_framework)
@@ -0,0 +1,27 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Integrations
4
+ module Libraries
5
+ # @private
6
+ class Routing
7
+ Integrations.register_library(self, :routing)
8
+
9
+ include Integrations::Inclusion
10
+ include Integrations::Rails
11
+
12
+ def integrate_with(test_framework)
13
+ test_framework.include(matchers_module, type: :routing)
14
+
15
+ include_into(::ActionController::TestCase, matchers_module)
16
+ end
17
+
18
+ private
19
+
20
+ def matchers_module
21
+ Shoulda::Matchers::Routing
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -9,7 +9,7 @@ module Shoulda
9
9
  def validate!
10
10
  end
11
11
 
12
- def include(*modules)
12
+ def include(*modules, **options)
13
13
  test_case_class.include(*modules)
14
14
  end
15
15
 
@@ -9,7 +9,7 @@ module Shoulda
9
9
  def validate!
10
10
  end
11
11
 
12
- def include(*modules)
12
+ def include(*modules, **options)
13
13
  test_case_class.class_eval do
14
14
  include(*modules)
15
15
  extend(*modules)
@@ -10,7 +10,7 @@ module Shoulda
10
10
  def validate!
11
11
  end
12
12
 
13
- def include(*modules)
13
+ def include(*modules, **options)
14
14
  test_case_class.class_eval do
15
15
  include(*modules)
16
16
  extend(*modules)
@@ -23,7 +23,7 @@ end
23
23
  EOT
24
24
  end
25
25
 
26
- def include(*modules)
26
+ def include(*modules, **options)
27
27
  end
28
28
 
29
29
  def n_unit?
@@ -9,9 +9,9 @@ module Shoulda
9
9
  def validate!
10
10
  end
11
11
 
12
- def include(*modules)
12
+ def include(*modules, **options)
13
13
  ::RSpec.configure do |config|
14
- config.include(*modules)
14
+ config.include(*modules, **options)
15
15
  end
16
16
  end
17
17
 
@@ -9,7 +9,7 @@ module Shoulda
9
9
  def validate!
10
10
  end
11
11
 
12
- def include(*modules)
12
+ def include(*modules, **options)
13
13
  test_case_class.class_eval do
14
14
  include(*modules)
15
15
  extend(*modules)
@@ -0,0 +1,10 @@
1
+ module Shoulda
2
+ module Matchers
3
+ # @private
4
+ module Routing
5
+ def route(method, path)
6
+ ActionController::RouteMatcher.new(method, path, self)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,6 +1,6 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  # @private
4
- VERSION = '3.0.0.rc1'.freeze
4
+ VERSION = '3.0.0'.freeze
5
5
  end
6
6
  end
@@ -1 +1 @@
1
- 2.0.0 2.1.5
1
+ 2.0.0 2.1.6 2.2.3
@@ -1,64 +1,125 @@
1
1
  require 'acceptance_spec_helper'
2
2
 
3
- describe 'shoulda-matchers has independent matchers' do
4
- context 'specifically delegate_method' do
5
- specify 'and integrates with a Ruby application that uses the default test framework' do
6
- create_generic_bundler_project
7
-
8
- updating_bundle do
9
- add_minitest_to_project
10
- add_shoulda_context_to_project(manually: true)
11
- add_shoulda_matchers_to_project(
12
- test_frameworks: [default_test_framework],
13
- manually: true
14
- )
3
+ describe 'shoulda-matchers has independent matchers, specifically delegate_method' do
4
+ specify 'and integrates with a Ruby application that uses the default test framework' do
5
+ create_generic_bundler_project
6
+
7
+ updating_bundle do
8
+ add_minitest_to_project
9
+ add_shoulda_context_to_project(manually: true)
10
+ add_shoulda_matchers_to_project(
11
+ test_frameworks: [default_test_framework],
12
+ manually: true
13
+ )
14
+ end
15
+
16
+ write_file 'lib/post_office.rb', <<-FILE
17
+ class PostOffice
15
18
  end
19
+ FILE
20
+
21
+ write_file 'lib/courier.rb', <<-FILE
22
+ require 'forwardable'
16
23
 
17
- write_file 'lib/post_office.rb', <<-FILE
18
- class PostOffice
24
+ class Courier
25
+ extend Forwardable
26
+
27
+ def_delegators :post_office, :deliver
28
+
29
+ attr_reader :post_office
30
+
31
+ def initialize(post_office)
32
+ @post_office = post_office
33
+ end
34
+ end
35
+ FILE
36
+
37
+ write_n_unit_test 'test/courier_test.rb' do |test_case_superclass|
38
+ <<-FILE
39
+ require 'test_helper'
40
+ require 'courier'
41
+ require 'post_office'
42
+
43
+ class CourierTest < #{test_case_superclass}
44
+ subject { Courier.new(post_office) }
45
+
46
+ should delegate_method(:deliver).to(:post_office)
47
+
48
+ def post_office
49
+ PostOffice.new
50
+ end
19
51
  end
20
52
  FILE
53
+ end
21
54
 
22
- write_file 'lib/courier.rb', <<-FILE
23
- require 'forwardable'
55
+ result = run_n_unit_tests('test/courier_test.rb')
24
56
 
25
- class Courier
26
- extend Forwardable
57
+ expect(result).to indicate_number_of_tests_was_run(1)
58
+ expect(result).to have_output(
59
+ 'Courier should delegate #deliver to #post_office object'
60
+ )
61
+ end
27
62
 
28
- def_delegators :post_office, :deliver
63
+ specify 'and integrates with a Ruby application that uses RSpec' do
64
+ create_generic_bundler_project
29
65
 
30
- attr_reader :post_office
66
+ updating_bundle do
67
+ add_rspec_to_project
68
+ add_shoulda_matchers_to_project(
69
+ manually: true,
70
+ with_configuration: false
71
+ )
72
+ write_file 'spec/spec_helper.rb', <<-FILE
73
+ require 'shoulda/matchers/independent'
31
74
 
32
- def initialize(post_office)
33
- @post_office = post_office
34
- end
75
+ RSpec.configure do |config|
76
+ config.include(Shoulda::Matchers::Independent)
35
77
  end
36
78
  FILE
79
+ end
80
+
81
+ write_file 'lib/post_office.rb', <<-FILE
82
+ class PostOffice
83
+ end
84
+ FILE
37
85
 
38
- write_n_unit_test 'test/courier_test.rb' do |test_case_superclass|
39
- <<-FILE
40
- require 'test_helper'
41
- require 'courier'
42
- require 'post_office'
86
+ write_file 'lib/courier.rb', <<-FILE
87
+ require 'forwardable'
43
88
 
44
- class CourierTest < #{test_case_superclass}
45
- subject { Courier.new(post_office) }
89
+ class Courier
90
+ extend Forwardable
46
91
 
47
- should delegate_method(:deliver).to(:post_office)
92
+ def_delegators :post_office, :deliver
48
93
 
49
- def post_office
50
- PostOffice.new
51
- end
52
- end
53
- FILE
94
+ attr_reader :post_office
95
+
96
+ def initialize(post_office)
97
+ @post_office = post_office
98
+ end
54
99
  end
100
+ FILE
55
101
 
56
- result = run_n_unit_tests('test/courier_test.rb')
102
+ write_file 'spec/courier_spec.rb', <<-FILE
103
+ require 'spec_helper'
104
+ require 'courier'
105
+ require 'post_office'
57
106
 
58
- expect(result).to indicate_number_of_tests_was_run(1)
59
- expect(result).to have_output(
60
- 'Courier should delegate #deliver to #post_office object'
61
- )
62
- end
107
+ describe Courier do
108
+ subject { Courier.new(post_office) }
109
+
110
+ it { should delegate_method(:deliver).to(:post_office) }
111
+
112
+ def post_office
113
+ PostOffice.new
114
+ end
115
+ end
116
+ FILE
117
+
118
+ result = run_rspec_tests('spec/courier_spec.rb')
119
+
120
+ expect(result).to indicate_number_of_tests_was_run(1)
121
+ expect(result).to have_output(
122
+ /Courier\s+should delegate #deliver to #post_office object/
123
+ )
63
124
  end
64
125
  end
@@ -1,4 +1,4 @@
1
- require 'shoulda-matchers'
1
+ require 'shoulda/matchers/doublespeak'
2
2
 
3
3
  PROJECT_ROOT = File.expand_path('../..', __FILE__)
4
4
  $LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
@@ -10,5 +10,9 @@ RSpec.configure do |config|
10
10
  c.syntax = :expect
11
11
  end
12
12
 
13
+ if config.files_to_run.one?
14
+ config.default_formatter = 'doc'
15
+ end
16
+
13
17
  config.mock_with :rspec
14
18
  end
@@ -16,7 +16,10 @@ module AcceptanceTests
16
16
 
17
17
  def call
18
18
  add_gem 'shoulda-matchers', gem_options
19
- configure_test_helper_files
19
+
20
+ unless options[:with_configuration] === false
21
+ configure_test_helper_files
22
+ end
20
23
  end
21
24
 
22
25
  protected
@@ -48,8 +51,10 @@ module AcceptanceTests
48
51
  def each_test_helper_file
49
52
  options[:test_frameworks].each do |test_framework|
50
53
  libraries = options.fetch(:libraries, [])
51
- test_helper_file = test_helper_file_for(test_framework, libraries)
52
- yield test_helper_file, test_framework, libraries
54
+
55
+ test_helper_files_for(test_framework, libraries).each do |test_helper_file|
56
+ yield test_helper_file, test_framework, libraries
57
+ end
53
58
  end
54
59
  end
55
60
 
@@ -85,16 +90,26 @@ module AcceptanceTests
85
90
  libraries.map { |library| "with.library :#{library}" }.join("\n")
86
91
  end
87
92
 
88
- def test_helper_file_for(test_framework, libraries)
89
- if integrates_with_rails?(test_framework, libraries) ||
90
- integrates_with_nunit?(test_framework)
91
- 'test/test_helper.rb'
92
- elsif integrates_with_rspec?(test_framework)
93
- spec_helper_file_path
93
+ def test_helper_files_for(test_framework, libraries)
94
+ files = []
95
+
96
+ if integrates_with_nunit_and_rails?(test_framework, libraries) ||
97
+ integrates_with_nunit_only?(test_framework)
98
+ files << 'test/test_helper.rb'
94
99
  end
100
+
101
+ if integrates_with_rspec?(test_framework)
102
+ if bundle.includes?('rspec-rails')
103
+ files << 'spec/rails_helper.rb'
104
+ else
105
+ files << 'spec/spec_helper.rb'
106
+ end
107
+ end
108
+
109
+ files
95
110
  end
96
111
 
97
- def integrates_with_nunit?(test_framework)
112
+ def integrates_with_nunit_only?(test_framework)
98
113
  nunit_frameworks = [:test_unit, :minitest, :minitest_4, :minitest_5]
99
114
  nunit_frameworks.include?(test_framework)
100
115
  end
@@ -103,8 +118,16 @@ module AcceptanceTests
103
118
  test_framework == :rspec
104
119
  end
105
120
 
106
- def integrates_with_rails?(test_framework, libraries)
121
+ def integrates_with_rspec_rails_3_x?(test_framework, libraries)
122
+ integrates_with_rails?(libraries) && rspec_rails_version >= 3
123
+ end
124
+
125
+ def integrates_with_nunit_and_rails?(test_framework, libraries)
107
126
  test_framework.nil? && libraries.include?(:rails)
108
127
  end
128
+
129
+ def integrates_with_rails?(libraries)
130
+ libraries.include?(:rails)
131
+ end
109
132
  end
110
133
  end
@@ -4,25 +4,21 @@ module AcceptanceTests
4
4
  module RspecHelpers
5
5
  include GemHelpers
6
6
 
7
- def rspec_rails_version
8
- bundle_version_of('rspec-rails')
7
+ def rspec_core_version
8
+ bundle_version_of('rspec-core')
9
9
  end
10
10
 
11
- def add_rspec_file(path, content)
12
- content = "require '#{spec_helper_require_path}'\n#{content}"
13
- write_file path, content
11
+ def rspec_expectations_version
12
+ bundle_version_of('rspec-expectations')
14
13
  end
15
14
 
16
- def spec_helper_require_path
17
- if rspec_rails_version >= 3
18
- 'rails_helper'
19
- else
20
- 'spec_helper'
21
- end
15
+ def rspec_rails_version
16
+ bundle_version_of('rspec-rails')
22
17
  end
23
18
 
24
- def spec_helper_file_path
25
- "spec/#{spec_helper_require_path}.rb"
19
+ def add_rspec_file(path, content)
20
+ content = "require 'rails_helper'\n#{content}"
21
+ write_file path, content
26
22
  end
27
23
  end
28
24
  end
@@ -90,12 +90,25 @@ module AcceptanceTests
90
90
  FILE
91
91
  end
92
92
 
93
+ def add_rspec_to_project
94
+ add_gem 'rspec-core', rspec_core_version
95
+ add_gem 'rspec-expectations', rspec_expectations_version
96
+ append_to_file 'spec/spec_helper.rb', <<-FILE
97
+ require 'rspec/core'
98
+ require 'rspec/expectations'
99
+ FILE
100
+ end
101
+
93
102
  def add_rspec_rails_to_project!
94
103
  add_gem 'rspec-rails', rspec_rails_version
95
104
  run_command_within_bundle!('rails g rspec:install')
96
105
  remove_from_file '.rspec', '--warnings'
97
106
  end
98
107
 
108
+ def run_rspec_tests(*paths)
109
+ run_command_within_bundle 'rspec --format documentation --backtrace', *paths
110
+ end
111
+
99
112
  def run_rspec_suite
100
113
  run_rake_tasks('spec', env: { SPEC_OPTS: '-fd' })
101
114
  end