shoulda-matchers 3.1.3 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.hound/ruby.yml +336 -316
  3. data/.python-version +1 -0
  4. data/.rubocop.yml +3 -1
  5. data/.travis.yml +7 -6
  6. data/Appraisals +76 -44
  7. data/CONTRIBUTING.md +137 -66
  8. data/Gemfile +5 -5
  9. data/Gemfile.lock +30 -35
  10. data/MAINTAINING.md +250 -0
  11. data/MIT-LICENSE +1 -1
  12. data/NEWS.md +176 -4
  13. data/README.md +138 -200
  14. data/Rakefile +7 -0
  15. data/bin/setup +190 -0
  16. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +4 -0
  17. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -6
  18. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -17
  19. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +27 -0
  20. data/gemfiles/4.2.gemfile +21 -20
  21. data/gemfiles/4.2.gemfile.lock +143 -140
  22. data/gemfiles/5.0.gemfile +37 -0
  23. data/gemfiles/5.0.gemfile.lock +238 -0
  24. data/gemfiles/5.1.gemfile +38 -0
  25. data/gemfiles/5.1.gemfile.lock +254 -0
  26. data/gemfiles/5.2.gemfile +40 -0
  27. data/gemfiles/5.2.gemfile.lock +273 -0
  28. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +18 -6
  29. data/lib/shoulda/matchers/action_controller/permit_matcher.rb +6 -1
  30. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
  31. data/lib/shoulda/matchers/action_controller/route_matcher.rb +87 -27
  32. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +1 -0
  33. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +0 -4
  34. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +5 -0
  35. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +5 -0
  36. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +26 -11
  37. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +39 -4
  38. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +116 -47
  39. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +127 -38
  40. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +55 -37
  41. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +30 -1
  42. data/lib/shoulda/matchers/active_model/validation_matcher.rb +11 -4
  43. data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +11 -6
  44. data/lib/shoulda/matchers/active_record.rb +3 -0
  45. data/lib/shoulda/matchers/active_record/association_matcher.rb +172 -22
  46. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +1 -1
  47. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +11 -6
  48. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +46 -0
  49. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +51 -0
  50. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +268 -38
  51. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
  52. data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +111 -0
  53. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +207 -79
  54. data/lib/shoulda/matchers/doublespeak/object_double.rb +5 -1
  55. data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +100 -21
  56. data/lib/shoulda/matchers/rails_shim.rb +133 -52
  57. data/lib/shoulda/matchers/routing.rb +2 -2
  58. data/lib/shoulda/matchers/util.rb +23 -1
  59. data/lib/shoulda/matchers/util/word_wrap.rb +6 -2
  60. data/lib/shoulda/matchers/version.rb +1 -1
  61. data/script/install_gems_in_all_appraisals +3 -1
  62. data/script/run_all_tests +3 -1
  63. data/script/supported_ruby_versions +7 -0
  64. data/script/update_gem_in_all_appraisals +3 -1
  65. data/script/update_gems_in_all_appraisals +3 -1
  66. data/shoulda-matchers.gemspec +3 -3
  67. data/spec/acceptance/independent_matchers_spec.rb +2 -2
  68. data/spec/acceptance/multiple_libraries_integration_spec.rb +1 -1
  69. data/spec/acceptance/rails_integration_spec.rb +2 -2
  70. data/spec/spec_helper.rb +2 -3
  71. data/spec/support/acceptance/helpers.rb +2 -0
  72. data/spec/support/acceptance/helpers/command_helpers.rb +17 -4
  73. data/spec/support/acceptance/helpers/rails_migration_helpers.rb +21 -0
  74. data/spec/support/acceptance/helpers/step_helpers.rb +1 -1
  75. data/spec/support/tests/current_bundle.rb +3 -9
  76. data/spec/support/tests/filesystem.rb +2 -2
  77. data/spec/support/unit/attribute.rb +0 -2
  78. data/spec/support/unit/capture.rb +9 -3
  79. data/spec/support/unit/helpers/action_pack_versions.rb +22 -0
  80. data/spec/support/unit/helpers/active_model_versions.rb +4 -0
  81. data/spec/support/unit/helpers/active_record_versions.rb +22 -2
  82. data/spec/support/unit/helpers/active_resource_builder.rb +2 -2
  83. data/spec/support/unit/helpers/controller_builder.rb +1 -1
  84. data/spec/support/unit/helpers/message_helpers.rb +19 -0
  85. data/spec/support/unit/helpers/rails_versions.rb +14 -0
  86. data/spec/support/unit/matchers/fail_with_message_matcher.rb +7 -5
  87. data/spec/support/unit/matchers/print_warning_including.rb +21 -13
  88. data/spec/support/unit/model_creation_strategies/active_record.rb +1 -1
  89. data/spec/support/unit/model_creators/active_record.rb +0 -1
  90. data/spec/support/unit/model_creators/basic.rb +7 -2
  91. data/spec/support/unit/rails_application.rb +25 -0
  92. data/spec/support/unit/record_validating_confirmation_builder.rb +5 -2
  93. data/spec/support/unit/validation_matcher_scenario.rb +0 -2
  94. data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +18 -18
  95. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +33 -5
  96. data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +1 -1
  97. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +80 -78
  98. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +7 -9
  99. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +28 -4
  100. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +19 -1
  101. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +27 -4
  102. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +62 -5
  103. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +52 -18
  104. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +51 -4
  105. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +99 -71
  106. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +41 -15
  107. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +445 -15
  108. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +615 -93
  109. data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +169 -0
  110. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +167 -97
  111. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +2 -4
  112. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +152 -19
  113. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +258 -94
  114. data/spec/unit_spec_helper.rb +9 -1
  115. data/zeus.json +1 -1
  116. metadata +31 -16
  117. data/gemfiles/4.0.0.gemfile +0 -38
  118. data/gemfiles/4.0.0.gemfile.lock +0 -223
  119. data/gemfiles/4.0.1.gemfile +0 -38
  120. data/gemfiles/4.0.1.gemfile.lock +0 -225
  121. data/gemfiles/4.1.gemfile +0 -38
  122. data/gemfiles/4.1.gemfile.lock +0 -220
  123. data/script/SUPPORTED_VERSIONS +0 -1
@@ -1,10 +1,14 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  # @private
4
- def self.word_wrap(document, options = {})
5
- Document.new(document, options).wrap
4
+ module WordWrap
5
+ def word_wrap(document, options = {})
6
+ Document.new(document, options).wrap
7
+ end
6
8
  end
7
9
 
10
+ extend WordWrap
11
+
8
12
  # @private
9
13
  class Document
10
14
  def initialize(document, indent: 0)
@@ -1,6 +1,6 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  # @private
4
- VERSION = '3.1.3'.freeze
4
+ VERSION = '4.0.0.rc1'.freeze
5
5
  end
6
6
  end
@@ -1,6 +1,8 @@
1
1
  #!/bin/bash
2
2
 
3
- SUPPORTED_VERSIONS=$(<script/SUPPORTED_VERSIONS)
3
+ set -euo pipefail
4
+
5
+ SUPPORTED_VERSIONS=$(script/supported_ruby_versions)
4
6
 
5
7
  install-gems-for-version() {
6
8
  local version="$1"
@@ -1,6 +1,8 @@
1
1
  #!/bin/bash
2
2
 
3
- SUPPORTED_VERSIONS=$(<script/SUPPORTED_VERSIONS)
3
+ set -euo pipefail
4
+
5
+ SUPPORTED_VERSIONS=$(script/supported_ruby_versions)
4
6
 
5
7
  run-tests-for-version() {
6
8
  local version="$1"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yaml'
4
+
5
+ travis_config_path = File.expand_path('../../.travis.yml', __FILE__)
6
+ travis_config = YAML.load_file(travis_config_path)
7
+ puts travis_config.fetch('rvm').join(' ')
@@ -1,6 +1,8 @@
1
1
  #!/bin/bash
2
2
 
3
- SUPPORTED_VERSIONS=$(<script/SUPPORTED_VERSIONS)
3
+ set -euo pipefail
4
+
5
+ SUPPORTED_VERSIONS=$(script/supported_ruby_versions)
4
6
  gem="$1"
5
7
 
6
8
  update-gem-for-version() {
@@ -1,6 +1,8 @@
1
1
  #!/bin/bash
2
2
 
3
- SUPPORTED_VERSIONS=$(<script/SUPPORTED_VERSIONS)
3
+ set -euo pipefail
4
+
5
+ SUPPORTED_VERSIONS=$(script/supported_ruby_versions)
4
6
 
5
7
  update-gems-for-version() {
6
8
  local version="$1"
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  "Matt Jankowski", "Stafford Brunk", "Elliot Winkler"]
9
9
  s.date = Time.now.strftime("%Y-%m-%d")
10
10
  s.email = "support@thoughtbot.com"
11
- s.homepage = "http://thoughtbot.com/community/"
11
+ s.homepage = "https://matchers.shoulda.io/"
12
12
  s.summary = "Making tests easy on the fingers and eyes"
13
13
  s.license = "MIT"
14
14
  s.description = "Making tests easy on the fingers and eyes"
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.required_ruby_version = '>= 2.0.0'
22
- s.add_dependency('activesupport', '>= 4.0.0')
21
+ s.required_ruby_version = '>= 2.2.0'
22
+ s.add_dependency('activesupport', '>= 4.2.0')
23
23
  end
@@ -56,7 +56,7 @@ describe 'shoulda-matchers has independent matchers, specifically delegate_metho
56
56
 
57
57
  expect(result).to indicate_number_of_tests_was_run(1)
58
58
  expect(result).to have_output(
59
- 'Courier should delegate #deliver to #post_office object'
59
+ 'Courier should delegate #deliver to the #post_office object'
60
60
  )
61
61
  end
62
62
 
@@ -119,7 +119,7 @@ describe 'shoulda-matchers has independent matchers, specifically delegate_metho
119
119
 
120
120
  expect(result).to indicate_number_of_tests_was_run(1)
121
121
  expect(result).to have_output(
122
- /Courier\s+should delegate #deliver to #post_office object/
122
+ /Courier\s+should delegate #deliver to the #post_office object/
123
123
  )
124
124
  end
125
125
  end
@@ -5,7 +5,7 @@ describe 'shoulda-matchers integrates with multiple libraries' do
5
5
  create_rails_application
6
6
 
7
7
  write_file 'db/migrate/1_create_users.rb', <<-FILE
8
- class CreateUsers < ActiveRecord::Migration
8
+ class CreateUsers < #{migration_class_name}
9
9
  def self.up
10
10
  create_table :users do |t|
11
11
  t.string :name
@@ -5,7 +5,7 @@ describe 'shoulda-matchers integrates with Rails' do
5
5
  create_rails_application
6
6
 
7
7
  write_file 'db/migrate/1_create_users.rb', <<-FILE
8
- class CreateUsers < ActiveRecord::Migration
8
+ class CreateUsers < #{migration_class_name}
9
9
  def self.up
10
10
  create_table :users do |t|
11
11
  t.string :name
@@ -26,7 +26,7 @@ describe 'shoulda-matchers integrates with Rails' do
26
26
  class ExamplesController < ApplicationController
27
27
  def show
28
28
  @example = 'hello'
29
- render nothing: true
29
+ head :ok
30
30
  end
31
31
  end
32
32
  FILE
@@ -7,15 +7,14 @@ require 'pry-byebug'
7
7
  require 'rspec'
8
8
 
9
9
  RSpec.configure do |config|
10
- config.order = :random
11
-
12
10
  config.expect_with :rspec do |c|
13
11
  c.syntax = :expect
14
12
  end
15
13
 
14
+ config.order = :random
16
15
  config.default_formatter = 'doc'
17
-
18
16
  config.mock_with :rspec
17
+ config.example_status_persistence_file_path = 'spec/examples.txt'
19
18
  end
20
19
 
21
20
  $VERBOSE = true
@@ -3,6 +3,7 @@ require_relative 'helpers/base_helpers'
3
3
  require_relative 'helpers/command_helpers'
4
4
  require_relative 'helpers/gem_helpers'
5
5
  require_relative 'helpers/n_unit_helpers'
6
+ require_relative 'helpers/rails_migration_helpers'
6
7
  require_relative 'helpers/rails_version_helpers'
7
8
  require_relative 'helpers/rspec_helpers'
8
9
  require_relative 'helpers/ruby_version_helpers'
@@ -23,6 +24,7 @@ module AcceptanceTests
23
24
  include CommandHelpers
24
25
  include GemHelpers
25
26
  include NUnitHelpers
27
+ include RailsMigrationHelpers
26
28
  include RailsVersionHelpers
27
29
  include RspecHelpers
28
30
  include RubyVersionHelpers
@@ -20,11 +20,8 @@ module AcceptanceTests
20
20
  end
21
21
  end
22
22
 
23
- def run_command_within_bundle(*args)
23
+ def run_command_isolated_from_bundle(*args)
24
24
  run_command(*args) do |runner|
25
- runner.command_prefix = 'bundle exec'
26
- runner.env['BUNDLE_GEMFILE'] = fs.find_in_project('Gemfile').to_s
27
-
28
25
  runner.around_command do |run_command|
29
26
  Bundler.with_clean_env(&run_command)
30
27
  end
@@ -33,6 +30,22 @@ module AcceptanceTests
33
30
  end
34
31
  end
35
32
 
33
+ def run_command_isolated_from_bundle!(*args)
34
+ run_command_isolated_from_bundle(*args) do |runner|
35
+ runner.run_successfully = true
36
+ yield runner if block_given?
37
+ end
38
+ end
39
+
40
+ def run_command_within_bundle(*args)
41
+ run_command_isolated_from_bundle(*args) do |runner|
42
+ runner.command_prefix = 'bundle exec'
43
+ runner.env['BUNDLE_GEMFILE'] = fs.find_in_project('Gemfile').to_s
44
+
45
+ yield runner if block_given?
46
+ end
47
+ end
48
+
36
49
  def run_command_within_bundle!(*args)
37
50
  run_command_within_bundle(*args) do |runner|
38
51
  runner.run_successfully = true
@@ -0,0 +1,21 @@
1
+ require_relative 'gem_helpers'
2
+
3
+ module AcceptanceTests
4
+ module RailsMigrationHelpers
5
+ include RailsVersionHelpers
6
+
7
+ def migration_class_name
8
+ if rails_version >= 5
9
+ "ActiveRecord::Migration[#{rails_version_for_migration}]"
10
+ else
11
+ 'ActiveRecord::Migration'
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def rails_version_for_migration
18
+ rails_version.to_s.split('.')[0..1].join('.')
19
+ end
20
+ end
21
+ end
@@ -20,7 +20,7 @@ module AcceptanceTests
20
20
  def create_generic_bundler_project
21
21
  fs.clean
22
22
  fs.create
23
- run_command! 'bundle init'
23
+ run_command_isolated_from_bundle! 'bundle init'
24
24
  end
25
25
 
26
26
  def add_shoulda_matchers_to_project(options = {})
@@ -32,18 +32,12 @@ EOT
32
32
  available_appraisals.sort.last
33
33
  end
34
34
 
35
- private
36
-
37
35
  def available_appraisals
38
- appraisals = []
39
-
40
- Appraisal::File.each do |appraisal|
41
- appraisals << appraisal.name
42
- end
43
-
44
- appraisals
36
+ Appraisal::AppraisalFile.each.map(&:name)
45
37
  end
46
38
 
39
+ private
40
+
47
41
  def current_appraisal
48
42
  if appraisal_in_use?
49
43
  File.basename(path, ".gemfile")
@@ -2,9 +2,9 @@ require 'fileutils'
2
2
 
3
3
  module Tests
4
4
  class Filesystem
5
- PROJECT_NAME = 'test-project'
5
+ PROJECT_NAME = 'test-project'.freeze
6
6
  ROOT_DIRECTORY = Pathname.new('../../../..').expand_path(__FILE__)
7
- TEMP_DIRECTORY = ROOT_DIRECTORY.join('tmp/acceptance')
7
+ TEMP_DIRECTORY = Pathname.new('/tmp/shoulda-matchers-acceptance')
8
8
  PROJECT_DIRECTORY = TEMP_DIRECTORY.join(PROJECT_NAME)
9
9
 
10
10
  def root_directory
@@ -1,7 +1,5 @@
1
1
  module UnitTests
2
2
  class Attribute
3
- attr_reader :name, :column_type, :column_options
4
-
5
3
  DEFAULT_COLUMN_TYPE = :string
6
4
  DEFAULT_COLUMN_OPTIONS = {
7
5
  null: false,
@@ -2,7 +2,9 @@ module Kernel
2
2
  # #capture, #silence_stream, and #silence_stderr are deprecated after Rails
3
3
  # 4.2 and will be removed in 5.0, so just override them completely here
4
4
 
5
- undef_method :capture
5
+ if method_defined?(:capture)
6
+ undef_method :capture
7
+ end
6
8
 
7
9
  def capture(stream)
8
10
  stream = stream.to_s
@@ -20,7 +22,9 @@ module Kernel
20
22
  stream_io.reopen(origin_stream)
21
23
  end
22
24
 
23
- undef_method :silence_stream
25
+ if method_defined?(:silence_stream)
26
+ undef_method :silence_stream
27
+ end
24
28
 
25
29
  def silence_stream(stream)
26
30
  old_stream = stream.dup
@@ -32,7 +36,9 @@ module Kernel
32
36
  old_stream.close
33
37
  end
34
38
 
35
- undef_method :silence_stderr
39
+ if method_defined?(:silence_stderr)
40
+ undef_method :silence_stderr
41
+ end
36
42
 
37
43
  def silence_stderr
38
44
  silence_stream(STDERR) { yield }
@@ -0,0 +1,22 @@
1
+ module UnitTests
2
+ module ActionPackVersions
3
+ extend self
4
+
5
+ def self.configure_example_group(example_group)
6
+ example_group.include(self)
7
+ example_group.extend(self)
8
+ end
9
+
10
+ def action_pack_gte_5?
11
+ action_pack_version >= 5
12
+ end
13
+
14
+ def action_pack_lt_5?
15
+ action_pack_version < 5
16
+ end
17
+
18
+ def action_pack_version
19
+ Tests::Version.new(ActionPack::VERSION::STRING)
20
+ end
21
+ end
22
+ end
@@ -21,6 +21,10 @@ module UnitTests
21
21
  ::ActiveModel::VERSION::MAJOR == 4
22
22
  end
23
23
 
24
+ def active_model_supports_absence_validation?
25
+ active_model_version >= 4
26
+ end
27
+
24
28
  def active_model_supports_strict?
25
29
  active_model_version >= 3.2
26
30
  end
@@ -9,16 +9,36 @@ module UnitTests
9
9
  Tests::Version.new(::ActiveRecord::VERSION::STRING)
10
10
  end
11
11
 
12
- def active_record_supports_enum?
13
- defined?(::ActiveRecord::Enum)
12
+ def active_record_enum_supports_prefix_and_suffix?
13
+ active_record_version >= 5
14
14
  end
15
15
 
16
16
  def active_record_supports_has_secure_password?
17
17
  active_record_version >= 3.1
18
18
  end
19
19
 
20
+ def active_record_supports_has_secure_token?
21
+ active_record_version >= 5.0
22
+ end
23
+
20
24
  def active_record_supports_array_columns?
21
25
  active_record_version > 4.2
22
26
  end
27
+
28
+ def active_record_supports_relations?
29
+ active_record_version >= 4
30
+ end
31
+
32
+ def active_record_supports_more_dependent_options?
33
+ active_record_version >= 4
34
+ end
35
+
36
+ def active_record_uniqueness_supports_array_columns?
37
+ active_record_version < 5
38
+ end
39
+
40
+ def active_record_supports_optional_for_associations?
41
+ active_record_version >= 5
42
+ end
23
43
  end
24
44
  end
@@ -1,8 +1,8 @@
1
- require 'active_resource'
2
-
3
1
  module UnitTests
4
2
  module ActiveResourceBuilder
5
3
  def self.configure_example_group(example_group)
4
+ require 'active_resource'
5
+
6
6
  example_group.include ActiveResourceBuilder
7
7
 
8
8
  example_group.after do
@@ -22,7 +22,7 @@ module UnitTests
22
22
  def build_fake_response(opts = {}, &block)
23
23
  action = opts[:action] || 'example'
24
24
  partial = opts[:partial] || '_partial'
25
- block ||= lambda { render nothing: true }
25
+ block ||= lambda { head :ok }
26
26
  controller_class = define_controller('Examples') do
27
27
  layout false
28
28
  define_method(action, &block)
@@ -0,0 +1,19 @@
1
+ module UnitTests
2
+ module MessageHelpers
3
+ include Shoulda::Matchers::WordWrap
4
+
5
+ def self.configure_example_group(example_group)
6
+ example_group.include(self)
7
+ end
8
+
9
+ def format_message(message, one_line: false)
10
+ stripped_message = message.strip_heredoc.strip
11
+
12
+ if one_line
13
+ stripped_message.tr("\n", " ").squeeze(" ")
14
+ else
15
+ word_wrap(stripped_message)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,7 @@
1
1
  module UnitTests
2
2
  module RailsVersions
3
+ extend self
4
+
3
5
  def self.configure_example_group(example_group)
4
6
  example_group.include(self)
5
7
  example_group.extend(self)
@@ -17,6 +19,10 @@ module UnitTests
17
19
  rails_version =~ '~> 4.0'
18
20
  end
19
21
 
22
+ def rails_lte_4?
23
+ rails_version <= 4
24
+ end
25
+
20
26
  def rails_gte_4_1?
21
27
  rails_version >= 4.1
22
28
  end
@@ -24,5 +30,13 @@ module UnitTests
24
30
  def rails_gte_4_2?
25
31
  rails_version >= 4.2
26
32
  end
33
+
34
+ def rails_lt_5?
35
+ rails_version < 5
36
+ end
37
+
38
+ def rails_5_x?
39
+ rails_version =~ '~> 5.0'
40
+ end
27
41
  end
28
42
  end