shoulda-matchers 4.0.0.rc1 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +72 -40
  4. data/lib/shoulda/matchers/action_controller.rb +2 -0
  5. data/lib/shoulda/matchers/active_model.rb +2 -3
  6. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +1 -0
  7. data/lib/shoulda/matchers/active_record.rb +2 -0
  8. data/lib/shoulda/matchers/active_record/association_matcher.rb +34 -0
  9. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +27 -4
  10. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +27 -4
  11. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1 -1
  12. data/lib/shoulda/matchers/independent.rb +2 -1
  13. data/lib/shoulda/matchers/rails_shim.rb +5 -9
  14. data/lib/shoulda/matchers/version.rb +1 -1
  15. data/lib/shoulda/matchers/warn.rb +1 -0
  16. data/shoulda-matchers.gemspec +11 -3
  17. metadata +13 -340
  18. data/.gitignore +0 -12
  19. data/.hound.yml +0 -3
  20. data/.hound/ruby.yml +0 -1062
  21. data/.python-version +0 -1
  22. data/.rubocop.yml +0 -15
  23. data/.travis.yml +0 -21
  24. data/.yardopts +0 -10
  25. data/Appraisals +0 -105
  26. data/CONTRIBUTING.md +0 -172
  27. data/Gemfile +0 -15
  28. data/Gemfile.lock +0 -59
  29. data/MAINTAINING.md +0 -250
  30. data/NEWS.md +0 -1235
  31. data/Rakefile +0 -46
  32. data/bin/setup +0 -190
  33. data/custom_plan.rb +0 -104
  34. data/doc_config/gh-pages/index.html.erb +0 -9
  35. data/doc_config/yard/setup.rb +0 -22
  36. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
  37. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
  38. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -66
  39. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
  40. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
  41. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -26
  42. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
  43. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
  44. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -281
  45. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
  46. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
  47. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
  48. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -35
  49. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
  50. data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
  51. data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
  52. data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
  53. data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
  54. data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
  55. data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
  56. data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
  57. data/gemfiles/4.2.gemfile +0 -39
  58. data/gemfiles/4.2.gemfile.lock +0 -246
  59. data/gemfiles/5.0.gemfile +0 -37
  60. data/gemfiles/5.0.gemfile.lock +0 -238
  61. data/gemfiles/5.1.gemfile +0 -38
  62. data/gemfiles/5.1.gemfile.lock +0 -254
  63. data/gemfiles/5.2.gemfile +0 -40
  64. data/gemfiles/5.2.gemfile.lock +0 -273
  65. data/script/install_gems_in_all_appraisals +0 -16
  66. data/script/run_all_tests +0 -16
  67. data/script/supported_ruby_versions +0 -7
  68. data/script/update_gem_in_all_appraisals +0 -17
  69. data/script/update_gems_in_all_appraisals +0 -16
  70. data/spec/acceptance/active_model_integration_spec.rb +0 -23
  71. data/spec/acceptance/independent_matchers_spec.rb +0 -125
  72. data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
  73. data/spec/acceptance/rails_integration_spec.rb +0 -156
  74. data/spec/acceptance_spec_helper.rb +0 -23
  75. data/spec/doublespeak_spec_helper.rb +0 -2
  76. data/spec/report_warnings.rb +0 -7
  77. data/spec/spec_helper.rb +0 -20
  78. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
  79. data/spec/support/acceptance/helpers.rb +0 -33
  80. data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
  81. data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
  82. data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
  83. data/spec/support/acceptance/helpers/command_helpers.rb +0 -68
  84. data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
  85. data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
  86. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
  87. data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
  88. data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
  89. data/spec/support/acceptance/helpers/rails_migration_helpers.rb +0 -21
  90. data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
  91. data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
  92. data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
  93. data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
  94. data/spec/support/acceptance/matchers/have_output.rb +0 -31
  95. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
  96. data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
  97. data/spec/support/tests/bundle.rb +0 -94
  98. data/spec/support/tests/command_runner.rb +0 -230
  99. data/spec/support/tests/current_bundle.rb +0 -55
  100. data/spec/support/tests/database.rb +0 -28
  101. data/spec/support/tests/database_adapters/postgresql.rb +0 -25
  102. data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
  103. data/spec/support/tests/database_configuration.rb +0 -33
  104. data/spec/support/tests/database_configuration_registry.rb +0 -28
  105. data/spec/support/tests/filesystem.rb +0 -100
  106. data/spec/support/tests/version.rb +0 -45
  107. data/spec/support/unit/active_record/create_table.rb +0 -54
  108. data/spec/support/unit/attribute.rb +0 -45
  109. data/spec/support/unit/capture.rb +0 -46
  110. data/spec/support/unit/change_value.rb +0 -111
  111. data/spec/support/unit/create_model_arguments/basic.rb +0 -135
  112. data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
  113. data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
  114. data/spec/support/unit/helpers/action_pack_versions.rb +0 -22
  115. data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
  116. data/spec/support/unit/helpers/active_model_versions.rb +0 -32
  117. data/spec/support/unit/helpers/active_record_versions.rb +0 -44
  118. data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
  119. data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
  120. data/spec/support/unit/helpers/class_builder.rb +0 -90
  121. data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
  122. data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
  123. data/spec/support/unit/helpers/controller_builder.rb +0 -63
  124. data/spec/support/unit/helpers/database_helpers.rb +0 -20
  125. data/spec/support/unit/helpers/i18n_faker.rb +0 -15
  126. data/spec/support/unit/helpers/mailer_builder.rb +0 -12
  127. data/spec/support/unit/helpers/message_helpers.rb +0 -19
  128. data/spec/support/unit/helpers/model_builder.rb +0 -114
  129. data/spec/support/unit/helpers/rails_versions.rb +0 -42
  130. data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
  131. data/spec/support/unit/i18n.rb +0 -7
  132. data/spec/support/unit/load_environment.rb +0 -12
  133. data/spec/support/unit/matchers/deprecate.rb +0 -60
  134. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
  135. data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -64
  136. data/spec/support/unit/matchers/print_warning_including.rb +0 -67
  137. data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
  138. data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
  139. data/spec/support/unit/model_creators.rb +0 -19
  140. data/spec/support/unit/model_creators/active_model.rb +0 -39
  141. data/spec/support/unit/model_creators/active_record.rb +0 -42
  142. data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
  143. data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
  144. data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
  145. data/spec/support/unit/model_creators/basic.rb +0 -102
  146. data/spec/support/unit/rails_application.rb +0 -151
  147. data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
  148. data/spec/support/unit/record_validating_confirmation_builder.rb +0 -54
  149. data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
  150. data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
  151. data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
  152. data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
  153. data/spec/support/unit/validation_matcher_scenario.rb +0 -60
  154. data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
  155. data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
  156. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -629
  157. data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
  158. data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
  159. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
  160. data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
  161. data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
  162. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
  163. data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
  164. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
  165. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
  166. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
  167. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -117
  168. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -829
  169. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
  170. data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
  171. data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
  172. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -290
  173. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -109
  174. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -172
  175. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -264
  176. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1049
  177. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -335
  178. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1865
  179. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -406
  180. data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
  181. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1672
  182. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
  183. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -690
  184. data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
  185. data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
  186. data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
  187. data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +0 -169
  188. data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
  189. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1682
  190. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
  191. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
  192. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
  193. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
  194. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
  195. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
  196. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -78
  197. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
  198. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
  199. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -650
  200. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -406
  201. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
  202. data/spec/unit_spec_helper.rb +0 -54
  203. data/spec/warnings_spy.rb +0 -64
  204. data/spec/warnings_spy/filesystem.rb +0 -45
  205. data/spec/warnings_spy/partitioner.rb +0 -36
  206. data/spec/warnings_spy/reader.rb +0 -53
  207. data/spec/warnings_spy/reporter.rb +0 -88
  208. data/tasks/documentation.rb +0 -199
  209. data/zeus.json +0 -11
@@ -1,28 +0,0 @@
1
- require_relative 'database_configuration'
2
-
3
- module Tests
4
- class Database
5
- NAME = 'shoulda-matchers-test'
6
- ADAPTER_NAME = ENV.fetch('DATABASE_ADAPTER', 'sqlite3').to_sym
7
-
8
- include Singleton
9
-
10
- attr_reader :config
11
-
12
- def initialize
13
- @config = Tests::DatabaseConfiguration.for(NAME, ADAPTER_NAME)
14
- end
15
-
16
- def name
17
- config.database
18
- end
19
-
20
- def adapter_name
21
- config.adapter
22
- end
23
-
24
- def adapter_class
25
- config.adapter_class
26
- end
27
- end
28
- end
@@ -1,25 +0,0 @@
1
- module Tests
2
- module DatabaseAdapters
3
- class PostgreSQL
4
- def self.name
5
- :postgresql
6
- end
7
-
8
- attr_reader :database
9
-
10
- def initialize(database)
11
- @database = database
12
- end
13
-
14
- def adapter
15
- self.class.name
16
- end
17
-
18
- def require_dependencies
19
- require 'pg'
20
- end
21
- end
22
-
23
- DatabaseConfigurationRegistry.instance.register(PostgreSQL)
24
- end
25
- end
@@ -1,26 +0,0 @@
1
- module Tests
2
- module DatabaseAdapters
3
- class SQLite3
4
- def self.name
5
- :sqlite3
6
- end
7
-
8
- def initialize(_database)
9
- end
10
-
11
- def adapter
12
- self.class.name
13
- end
14
-
15
- def database
16
- 'db/db.sqlite3'
17
- end
18
-
19
- def require_dependencies
20
- require 'sqlite3'
21
- end
22
- end
23
-
24
- DatabaseConfigurationRegistry.instance.register(SQLite3)
25
- end
26
- end
@@ -1,33 +0,0 @@
1
- require_relative 'database_configuration_registry'
2
- require 'delegate'
3
-
4
- module Tests
5
- class DatabaseConfiguration < SimpleDelegator
6
- ENVIRONMENTS = %w(development test production)
7
-
8
- attr_reader :adapter_class
9
-
10
- def self.for(database_name, adapter_name)
11
- config_class = DatabaseConfigurationRegistry.instance.get(adapter_name)
12
- config = config_class.new(database_name)
13
- new(config)
14
- end
15
-
16
- def initialize(config)
17
- @adapter_class = config.class.to_s.split('::').last
18
- super(config)
19
- end
20
-
21
- def to_hash
22
- ENVIRONMENTS.each_with_object({}) do |env, config_as_hash|
23
- config_as_hash[env] = inner_config_as_hash
24
- end
25
- end
26
-
27
- private
28
-
29
- def inner_config_as_hash
30
- { 'adapter' => adapter.to_s, 'database' => database.to_s }
31
- end
32
- end
33
- end
@@ -1,28 +0,0 @@
1
- require 'singleton'
2
-
3
- module Tests
4
- class DatabaseConfigurationRegistry
5
- include Singleton
6
-
7
- def initialize
8
- @registry = {}
9
- end
10
-
11
- def register(config_class)
12
- registry[config_class.name] = config_class
13
- end
14
-
15
- def get(name)
16
- registry.fetch(name) do
17
- raise KeyError, "No such adapter registered: #{name}"
18
- end
19
- end
20
-
21
- protected
22
-
23
- attr_reader :registry
24
- end
25
- end
26
-
27
- require_relative 'database_adapters/postgresql'
28
- require_relative 'database_adapters/sqlite3'
@@ -1,100 +0,0 @@
1
- require 'fileutils'
2
-
3
- module Tests
4
- class Filesystem
5
- PROJECT_NAME = 'test-project'.freeze
6
- ROOT_DIRECTORY = Pathname.new('../../../..').expand_path(__FILE__)
7
- TEMP_DIRECTORY = Pathname.new('/tmp/shoulda-matchers-acceptance')
8
- PROJECT_DIRECTORY = TEMP_DIRECTORY.join(PROJECT_NAME)
9
-
10
- def root_directory
11
- ROOT_DIRECTORY
12
- end
13
-
14
- def temp_directory
15
- TEMP_DIRECTORY
16
- end
17
-
18
- def project_directory
19
- PROJECT_DIRECTORY
20
- end
21
-
22
- def wrap(path)
23
- if path.is_a?(Pathname)
24
- path
25
- else
26
- find_in_project(path)
27
- end
28
- end
29
-
30
- def within_project(&block)
31
- Dir.chdir(project_directory, &block)
32
- end
33
-
34
- def clean
35
- if temp_directory.exist?
36
- temp_directory.rmtree
37
- end
38
- end
39
-
40
- def create
41
- project_directory.mkpath
42
- end
43
-
44
- def find_in_project(path)
45
- project_directory.join(path)
46
- end
47
-
48
- def open(path, *args, &block)
49
- find_in_project(path).open(*args, &block)
50
- end
51
-
52
- def read(path)
53
- find_in_project(path).read
54
- end
55
-
56
- def write(path, content)
57
- pathname = wrap(path)
58
- create_parents_of(pathname)
59
- pathname.open('w') { |f| f.write(content) }
60
- end
61
-
62
- def create_parents_of(path)
63
- wrap(path).dirname.mkpath
64
- end
65
-
66
- def append_to_file(path, content, options = {})
67
- create_parents_of(path)
68
- open(path, 'a') { |f| f.puts(content + "\n") }
69
- end
70
-
71
- def remove_from_file(path, pattern)
72
- unless pattern.is_a?(Regexp)
73
- pattern = Regexp.new('^' + Regexp.escape(pattern) + '$')
74
- end
75
-
76
- transform(path) do |lines|
77
- lines.reject { |line| line =~ pattern }
78
- end
79
- end
80
-
81
- def comment_lines_matching(path, pattern)
82
- transform(path) do |lines|
83
- lines.map do |line|
84
- if line =~ pattern
85
- "###{line}"
86
- else
87
- line
88
- end
89
- end
90
- end
91
- end
92
-
93
- def transform(path)
94
- content = read(path)
95
- lines = content.split(/\n/)
96
- transformed_lines = yield lines
97
- write(path, transformed_lines.join("\n") + "\n")
98
- end
99
- end
100
- end
@@ -1,45 +0,0 @@
1
- module Tests
2
- class Version
3
- def initialize(version)
4
- @version = Gem::Version.new(version.to_s + '')
5
- end
6
-
7
- def <(other_version)
8
- compare?(:<, other_version)
9
- end
10
-
11
- def <=(other_version)
12
- compare?(:<=, other_version)
13
- end
14
-
15
- def ==(other_version)
16
- compare?(:==, other_version)
17
- end
18
-
19
- def >=(other_version)
20
- compare?(:>=, other_version)
21
- end
22
-
23
- def >(other_version)
24
- compare?(:>, other_version)
25
- end
26
-
27
- def =~(other_version)
28
- Gem::Requirement.new(other_version).satisfied_by?(version)
29
- end
30
-
31
- def to_s
32
- version.to_s
33
- end
34
-
35
- protected
36
-
37
- attr_reader :version
38
-
39
- private
40
-
41
- def compare?(op, other_version)
42
- Gem::Requirement.new("#{op} #{other_version}").satisfied_by?(version)
43
- end
44
- end
45
- end
@@ -1,54 +0,0 @@
1
- module UnitTests
2
- module ActiveRecord
3
- class CreateTable
4
- def self.call(table_name, columns)
5
- new(table_name, columns).call
6
- end
7
-
8
- def initialize(table_name, columns)
9
- @table_name = table_name
10
- @columns = columns
11
- end
12
-
13
- def call
14
- if columns.key?(:id) && columns[:id] == false
15
- columns.delete(:id)
16
- UnitTests::ModelBuilder.create_table(
17
- table_name,
18
- id: false,
19
- &method(:add_columns_to_table)
20
- )
21
- else
22
- UnitTests::ModelBuilder.create_table(
23
- table_name,
24
- &method(:add_columns_to_table)
25
- )
26
- end
27
- end
28
-
29
- protected
30
-
31
- attr_reader :table_name, :columns
32
-
33
- private
34
-
35
- def add_columns_to_table(table)
36
- columns.each do |column_name, column_specification|
37
- add_column_to_table(table, column_name, column_specification)
38
- end
39
- end
40
-
41
- def add_column_to_table(table, column_name, column_specification)
42
- if column_specification.is_a?(Hash)
43
- column_type = column_specification.fetch(:type)
44
- column_options = column_specification.fetch(:options, {})
45
- else
46
- column_type = column_specification
47
- column_options = {}
48
- end
49
-
50
- table.column(column_name, column_type, column_options)
51
- end
52
- end
53
- end
54
- end
@@ -1,45 +0,0 @@
1
- module UnitTests
2
- class Attribute
3
- DEFAULT_COLUMN_TYPE = :string
4
- DEFAULT_COLUMN_OPTIONS = {
5
- null: false,
6
- array: false
7
- }
8
-
9
- def initialize(args)
10
- @args = args
11
- end
12
-
13
- def name
14
- args.fetch(:name)
15
- end
16
-
17
- def column_type
18
- args.fetch(:column_type, DEFAULT_COLUMN_TYPE)
19
- end
20
-
21
- def column_options
22
- DEFAULT_COLUMN_OPTIONS.
23
- merge(args.fetch(:column_options, {})).
24
- merge(type: column_type)
25
- end
26
-
27
- def array?
28
- column_options[:array]
29
- end
30
-
31
- def default_value
32
- args.fetch(:default_value) do
33
- if column_options[:null]
34
- nil
35
- else
36
- Shoulda::Matchers::Util.dummy_value_for(value_type, array: array?)
37
- end
38
- end
39
- end
40
-
41
- protected
42
-
43
- attr_reader :args
44
- end
45
- end
@@ -1,46 +0,0 @@
1
- module Kernel
2
- # #capture, #silence_stream, and #silence_stderr are deprecated after Rails
3
- # 4.2 and will be removed in 5.0, so just override them completely here
4
-
5
- if method_defined?(:capture)
6
- undef_method :capture
7
- end
8
-
9
- def capture(stream)
10
- stream = stream.to_s
11
- captured_stream = Tempfile.new(stream)
12
- stream_io = eval("$#{stream}")
13
- origin_stream = stream_io.dup
14
- stream_io.reopen(captured_stream)
15
-
16
- yield
17
-
18
- stream_io.rewind
19
- return captured_stream.read
20
- ensure
21
- captured_stream.unlink
22
- stream_io.reopen(origin_stream)
23
- end
24
-
25
- if method_defined?(:silence_stream)
26
- undef_method :silence_stream
27
- end
28
-
29
- def silence_stream(stream)
30
- old_stream = stream.dup
31
- stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
32
- stream.sync = true
33
- yield
34
- ensure
35
- stream.reopen(old_stream)
36
- old_stream.close
37
- end
38
-
39
- if method_defined?(:silence_stderr)
40
- undef_method :silence_stderr
41
- end
42
-
43
- def silence_stderr
44
- silence_stream(STDERR) { yield }
45
- end
46
- end
@@ -1,111 +0,0 @@
1
- module UnitTests
2
- class ChangeValue
3
- def self.call(column_type, value, value_changer)
4
- new(column_type, value, value_changer).call
5
- end
6
-
7
- def initialize(column_type, value, value_changer)
8
- @column_type = column_type
9
- @value = value
10
- @value_changer = value_changer
11
- end
12
-
13
- def call
14
- if value_changer.is_a?(Proc)
15
- value_changer.call(value)
16
- elsif respond_to?(value_changer, true)
17
- send(value_changer)
18
- else
19
- value.public_send(value_changer)
20
- end
21
- end
22
-
23
- protected
24
-
25
- attr_reader :column_type, :value, :value_changer
26
-
27
- private
28
-
29
- def previous_value
30
- if value.is_a?(String)
31
- value[0..-2] + (value[-1].ord - 1).chr
32
- else
33
- value - 1
34
- end
35
- end
36
-
37
- def next_value
38
- if value.is_a?(Array)
39
- value + [value.first.class.new]
40
- elsif value.respond_to?(:next)
41
- value.next
42
- else
43
- value + 1
44
- end
45
- end
46
-
47
- def next_next_value
48
- change_value(change_value(value, :next_value), :next_value)
49
- end
50
-
51
- def next_value_or_numeric_value
52
- if value
53
- change_value(value, :next_value)
54
- else
55
- change_value(value, :numeric_value)
56
- end
57
- end
58
-
59
- def next_value_or_non_numeric_value
60
- if value
61
- change_value(value, :next_value)
62
- else
63
- change_value(value, :non_numeric_value)
64
- end
65
- end
66
-
67
- def never_falsy
68
- value || dummy_value_for_column
69
- end
70
-
71
- def truthy_or_numeric
72
- value || 1
73
- end
74
-
75
- def never_blank
76
- value.presence || dummy_value_for_column
77
- end
78
-
79
- def nil_to_blank
80
- value || ''
81
- end
82
-
83
- def always_nil
84
- nil
85
- end
86
-
87
- def add_character
88
- value + 'a'
89
- end
90
-
91
- def remove_character
92
- value.chop
93
- end
94
-
95
- def numeric_value
96
- '1'
97
- end
98
-
99
- def non_numeric_value
100
- 'a'
101
- end
102
-
103
- def change_value(value, value_changer)
104
- self.class.call(column_type, value, value_changer)
105
- end
106
-
107
- def dummy_value_for_column
108
- Shoulda::Matchers::Util.dummy_value_for(column_type)
109
- end
110
- end
111
- end