shoulda-matchers 2.7.0 → 2.8.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -3
- data/Appraisals +18 -0
- data/CONTRIBUTING.md +13 -29
- data/Gemfile +1 -4
- data/Gemfile.lock +2 -10
- data/NEWS.md +100 -14
- data/README.md +62 -58
- data/Rakefile +9 -16
- data/gemfiles/3.0.gemfile +11 -12
- data/gemfiles/3.0.gemfile.lock +15 -10
- data/gemfiles/3.1.gemfile +11 -12
- data/gemfiles/3.1.gemfile.lock +14 -10
- data/gemfiles/3.1_1.9.2.gemfile +12 -11
- data/gemfiles/3.1_1.9.2.gemfile.lock +14 -3
- data/gemfiles/3.2.gemfile +11 -12
- data/gemfiles/3.2.gemfile.lock +15 -10
- data/gemfiles/3.2_1.9.2.gemfile +12 -11
- data/gemfiles/3.2_1.9.2.gemfile.lock +14 -2
- data/gemfiles/4.0.0.gemfile +10 -12
- data/gemfiles/4.0.0.gemfile.lock +13 -10
- data/gemfiles/4.0.1.gemfile +10 -12
- data/gemfiles/4.0.1.gemfile.lock +13 -10
- data/gemfiles/4.1.gemfile +13 -15
- data/gemfiles/4.1.gemfile.lock +45 -50
- data/gemfiles/4.2.gemfile +36 -0
- data/gemfiles/4.2.gemfile.lock +245 -0
- data/lib/shoulda/matchers.rb +3 -1
- data/lib/shoulda/matchers/action_controller.rb +1 -1
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/route_params.rb +9 -4
- data/lib/shoulda/matchers/action_controller/{set_the_flash_matcher.rb → set_flash_matcher.rb} +34 -26
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +125 -69
- data/lib/shoulda/matchers/active_model.rb +1 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +18 -5
- data/lib/shoulda/matchers/active_model/exception_message_finder.rb +2 -2
- data/lib/shoulda/matchers/active_model/helpers.rb +4 -4
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +10 -3
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +3 -1
- data/lib/shoulda/matchers/active_model/{ensure_length_of_matcher.rb → validate_length_of_matcher.rb} +30 -20
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +21 -0
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -2
- data/lib/shoulda/matchers/active_record.rb +2 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +96 -2
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +3 -3
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +22 -2
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +30 -4
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +19 -3
- data/lib/shoulda/matchers/active_record/uniqueness.rb +14 -0
- data/lib/shoulda/matchers/active_record/uniqueness/model.rb +45 -0
- data/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +36 -0
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +50 -0
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +24 -0
- data/lib/shoulda/matchers/{active_model → active_record}/validate_uniqueness_of_matcher.rb +76 -16
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +117 -51
- data/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +1 -1
- data/lib/shoulda/matchers/matcher_context.rb +35 -0
- data/lib/shoulda/matchers/rails_shim.rb +23 -0
- data/lib/shoulda/matchers/util.rb +28 -0
- data/lib/shoulda/matchers/version.rb +1 -1
- data/script/SUPPORTED_VERSIONS +1 -1
- data/spec/acceptance/active_model_integration_spec.rb +20 -0
- data/spec/acceptance/independent_matchers_spec.rb +64 -0
- data/spec/acceptance/rails_integration_spec.rb +142 -0
- data/spec/acceptance_spec_helper.rb +23 -0
- data/spec/support/acceptance/helpers.rb +29 -0
- data/spec/support/acceptance/helpers/active_model_helpers.rb +11 -0
- data/spec/support/acceptance/helpers/array_helpers.rb +13 -0
- data/spec/support/acceptance/helpers/base_helpers.rb +14 -0
- data/spec/support/acceptance/helpers/command_helpers.rb +51 -0
- data/spec/support/acceptance/helpers/file_helpers.rb +19 -0
- data/spec/support/acceptance/helpers/gem_helpers.rb +31 -0
- data/spec/support/acceptance/helpers/minitest_helpers.rb +19 -0
- data/spec/support/acceptance/helpers/pluralization_helpers.rb +13 -0
- data/spec/support/acceptance/helpers/rails_version_helpers.rb +11 -0
- data/spec/support/acceptance/helpers/rspec_helpers.rb +26 -0
- data/spec/support/acceptance/helpers/ruby_version_helpers.rb +9 -0
- data/spec/support/acceptance/helpers/step_helpers.rb +117 -0
- data/spec/support/acceptance/matchers/have_output.rb +31 -0
- data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +55 -0
- data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +103 -0
- data/spec/support/tests/bundle.rb +94 -0
- data/spec/support/tests/command_runner.rb +214 -0
- data/spec/support/tests/filesystem.rb +77 -0
- data/spec/support/tests/version.rb +45 -0
- data/spec/support/unit/capture.rb +34 -0
- data/spec/support/unit/helpers/active_model_helpers.rb +25 -0
- data/spec/support/unit/helpers/active_model_versions.rb +20 -0
- data/spec/support/unit/helpers/active_resource_builder.rb +27 -0
- data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +15 -0
- data/spec/support/unit/helpers/class_builder.rb +72 -0
- data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +17 -0
- data/spec/support/unit/helpers/controller_builder.rb +91 -0
- data/spec/support/unit/helpers/i18n_faker.rb +15 -0
- data/spec/support/unit/helpers/mailer_builder.rb +12 -0
- data/spec/support/unit/helpers/model_builder.rb +102 -0
- data/spec/support/unit/helpers/rails_versions.rb +28 -0
- data/spec/support/unit/i18n.rb +7 -0
- data/spec/support/unit/matchers/deprecate.rb +60 -0
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +50 -0
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +50 -0
- data/spec/support/unit/matchers/print_warning_including.rb +59 -0
- data/spec/support/unit/rails_application.rb +110 -0
- data/spec/support/unit/record_builder_with_i18n_validation_message.rb +69 -0
- data/spec/support/unit/record_validating_confirmation_builder.rb +56 -0
- data/spec/support/unit/record_with_different_error_attribute_builder.rb +92 -0
- data/spec/support/{shared_examples → unit/shared_examples}/numerical_submatcher.rb +0 -2
- data/spec/support/{shared_examples → unit/shared_examples}/numerical_type_submatcher.rb +0 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/callback_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/filter_param_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/redirect_to_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_template_matcher_spec.rb +2 -4
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_with_layout_matcher_spec.rb +9 -6
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/rescue_from_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/respond_with_matcher_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +126 -0
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/route_params_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +167 -0
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +294 -0
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/strong_parameters_matcher_spec.rb +19 -11
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_value_matcher_spec.rb +49 -21
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/disallow_value_matcher_spec.rb +8 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/exception_message_finder_spec.rb +4 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/have_secure_password_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/helpers_spec.rb +7 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_absence_of_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_acceptance_of_matcher_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +63 -0
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_exclusion_of_matcher_spec.rb +5 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_inclusion_of_matcher_spec.rb +7 -14
- data/spec/{shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb → unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb} +43 -23
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_numericality_of_matcher_spec.rb +3 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_presence_of_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +127 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validation_message_finder_spec.rb +8 -6
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matcher_spec.rb +217 -26
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matchers/model_reflection_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/define_enum_for_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_column_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_index_matcher_spec.rb +8 -5
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_readonly_attributes_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/serialize_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_collection_spec.rb +29 -7
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_spec.rb +20 -10
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/object_double_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/proxy_implementation_spec.rb +13 -6
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/stub_implementation_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +77 -0
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak_spec.rb +11 -3
- data/spec/{shoulda → unit/shoulda}/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +1 -1
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +517 -0
- data/spec/unit_spec_helper.rb +66 -0
- data/spec/warnings_spy/partitioner.rb +10 -3
- data/spec/warnings_spy/reader.rb +9 -20
- data/spec/warnings_spy/reporter.rb +2 -1
- metadata +212 -149
- data/features/activemodel_integration.feature +0 -15
- data/features/rails_integration.feature +0 -160
- data/features/step_definitions/activemodel_steps.rb +0 -21
- data/features/step_definitions/rails_steps.rb +0 -227
- data/features/support/env.rb +0 -6
- data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -70
- data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -113
- data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +0 -153
- data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -47
- data/spec/shoulda/matchers/doublespeak/world_spec.rb +0 -70
- data/spec/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -309
- data/spec/spec_helper.rb +0 -42
- data/spec/support/active_model_versions.rb +0 -13
- data/spec/support/active_resource_builder.rb +0 -29
- data/spec/support/activemodel_helpers.rb +0 -23
- data/spec/support/capture_helpers.rb +0 -19
- data/spec/support/class_builder.rb +0 -46
- data/spec/support/controller_builder.rb +0 -102
- data/spec/support/fail_with_message_including_matcher.rb +0 -44
- data/spec/support/fail_with_message_matcher.rb +0 -44
- data/spec/support/i18n_faker.rb +0 -10
- data/spec/support/mailer_builder.rb +0 -10
- data/spec/support/model_builder.rb +0 -81
- data/spec/support/rails_versions.rb +0 -26
- data/spec/support/test_application.rb +0 -120
@@ -0,0 +1,214 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
require 'shellwords'
|
3
|
+
|
4
|
+
module Tests
|
5
|
+
class CommandRunner
|
6
|
+
TimeoutError = Class.new(StandardError)
|
7
|
+
|
8
|
+
def self.run(*args)
|
9
|
+
new(*args).tap do |runner|
|
10
|
+
yield runner
|
11
|
+
runner.call
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.run!(*args)
|
16
|
+
run(*args) do |runner|
|
17
|
+
runner.run_successfully = true
|
18
|
+
yield runner if block_given?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :status, :options, :env, :directory
|
23
|
+
attr_accessor :command_prefix, :run_quickly, :run_successfully, :retries,
|
24
|
+
:timeout
|
25
|
+
|
26
|
+
def initialize(*args)
|
27
|
+
@reader, @writer = IO.pipe
|
28
|
+
options = (args.last.is_a?(Hash) ? args.pop : {})
|
29
|
+
@args = args
|
30
|
+
@options = options.merge(
|
31
|
+
err: [:child, :out],
|
32
|
+
out: writer
|
33
|
+
)
|
34
|
+
@env = extract_env_from(@options)
|
35
|
+
|
36
|
+
@wrapper = ->(block) { block.call }
|
37
|
+
@command_prefix = ''
|
38
|
+
@directory = Dir.pwd
|
39
|
+
@run_quickly = false
|
40
|
+
@run_successfully = false
|
41
|
+
@retries = 1
|
42
|
+
@num_times_run = 0
|
43
|
+
@timeout = 20
|
44
|
+
end
|
45
|
+
|
46
|
+
def around_command(&block)
|
47
|
+
@wrapper = block
|
48
|
+
end
|
49
|
+
|
50
|
+
def directory=(directory)
|
51
|
+
@directory = directory || Dir.pwd
|
52
|
+
end
|
53
|
+
|
54
|
+
def formatted_command
|
55
|
+
[formatted_env, Shellwords.join(command)].
|
56
|
+
select { |value| !value.empty? }.
|
57
|
+
join(' ')
|
58
|
+
end
|
59
|
+
|
60
|
+
def call
|
61
|
+
possibly_retrying do
|
62
|
+
possibly_running_quickly do
|
63
|
+
debug { "\n\e[32mRunning command:\e[0m #{formatted_command}" }
|
64
|
+
wrapper.call(-> { run })
|
65
|
+
debug { "\n" + divider('START') + output + divider('END') }
|
66
|
+
|
67
|
+
if run_successfully && !success?
|
68
|
+
fail!
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def stop
|
77
|
+
unless writer.closed?
|
78
|
+
writer.close
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def output
|
83
|
+
@_output ||= begin
|
84
|
+
stop
|
85
|
+
without_colors(reader.read)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def elided_output
|
90
|
+
lines = output.split(/\n/)
|
91
|
+
new_lines = lines[0..4]
|
92
|
+
|
93
|
+
if lines.size > 10
|
94
|
+
new_lines << "(...#{lines.size - 10} more lines...)"
|
95
|
+
end
|
96
|
+
|
97
|
+
new_lines << lines[-5..-1]
|
98
|
+
new_lines.join("\n")
|
99
|
+
end
|
100
|
+
|
101
|
+
def success?
|
102
|
+
status.success?
|
103
|
+
end
|
104
|
+
|
105
|
+
def exit_status
|
106
|
+
status.exitstatus
|
107
|
+
end
|
108
|
+
|
109
|
+
def fail!
|
110
|
+
raise <<-MESSAGE
|
111
|
+
Command #{command.inspect} exited with status #{exit_status}.
|
112
|
+
Output:
|
113
|
+
#{divider('START') + output + divider('END')}
|
114
|
+
MESSAGE
|
115
|
+
end
|
116
|
+
|
117
|
+
def has_output?(expected_output)
|
118
|
+
output.include?(expected_output)
|
119
|
+
end
|
120
|
+
|
121
|
+
protected
|
122
|
+
|
123
|
+
attr_reader :args, :reader, :writer, :wrapper
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def extract_env_from(options)
|
128
|
+
options.delete(:env) { {} }.inject({}) do |hash, (key, value)|
|
129
|
+
hash[key.to_s] = value
|
130
|
+
hash
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def command
|
135
|
+
([command_prefix] + args).flatten.flat_map do |word|
|
136
|
+
Shellwords.split(word)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def formatted_env
|
141
|
+
env.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
|
142
|
+
end
|
143
|
+
|
144
|
+
def run
|
145
|
+
Dir.chdir(directory) do
|
146
|
+
pid = spawn(env, *command, options)
|
147
|
+
Process.waitpid(pid)
|
148
|
+
end
|
149
|
+
|
150
|
+
@status = $?
|
151
|
+
end
|
152
|
+
|
153
|
+
def possibly_running_quickly(&block)
|
154
|
+
if run_quickly
|
155
|
+
begin
|
156
|
+
Timeout.timeout(timeout, &block)
|
157
|
+
rescue Timeout::Error
|
158
|
+
stop
|
159
|
+
|
160
|
+
message =
|
161
|
+
"Command timed out after #{timeout} seconds: #{formatted_command}\n" +
|
162
|
+
"Output:\n" +
|
163
|
+
elided_output
|
164
|
+
|
165
|
+
raise TimeoutError, message
|
166
|
+
end
|
167
|
+
else
|
168
|
+
yield
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def possibly_retrying
|
173
|
+
begin
|
174
|
+
@num_times_run += 1
|
175
|
+
yield
|
176
|
+
rescue => error
|
177
|
+
debug { "#{error.class}: #{error.message}" }
|
178
|
+
|
179
|
+
if @num_times_run < @retries
|
180
|
+
sleep @num_times_run
|
181
|
+
retry
|
182
|
+
else
|
183
|
+
raise error
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def divider(title = '')
|
189
|
+
total_length = 72
|
190
|
+
start_length = 3
|
191
|
+
|
192
|
+
string = ''
|
193
|
+
string << ('-' * start_length)
|
194
|
+
string << title
|
195
|
+
string << '-' * (total_length - start_length - title.length)
|
196
|
+
string << "\n"
|
197
|
+
string
|
198
|
+
end
|
199
|
+
|
200
|
+
def without_colors(string)
|
201
|
+
string.gsub(/\e\[\d+(?:;\d+)?m(.+?)\e\[0m/, '\1')
|
202
|
+
end
|
203
|
+
|
204
|
+
def debugging_enabled?
|
205
|
+
ENV['DEBUG_COMMANDS'] == '1'
|
206
|
+
end
|
207
|
+
|
208
|
+
def debug(&block)
|
209
|
+
if debugging_enabled?
|
210
|
+
puts block.call
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Tests
|
4
|
+
class Filesystem
|
5
|
+
PROJECT_NAME = 'test-project'
|
6
|
+
ROOT_DIRECTORY = Pathname.new('../../../..').expand_path(__FILE__)
|
7
|
+
TEMP_DIRECTORY = ROOT_DIRECTORY.join('tmp/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
|
+
content = read(path)
|
73
|
+
content.sub!(/#{pattern}\n/, '')
|
74
|
+
write(path, content)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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
|
@@ -0,0 +1,34 @@
|
|
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
|
+
def capture(stream)
|
6
|
+
stream = stream.to_s
|
7
|
+
captured_stream = Tempfile.new(stream)
|
8
|
+
stream_io = eval("$#{stream}")
|
9
|
+
origin_stream = stream_io.dup
|
10
|
+
stream_io.reopen(captured_stream)
|
11
|
+
|
12
|
+
yield
|
13
|
+
|
14
|
+
stream_io.rewind
|
15
|
+
return captured_stream.read
|
16
|
+
ensure
|
17
|
+
captured_stream.unlink
|
18
|
+
stream_io.reopen(origin_stream)
|
19
|
+
end
|
20
|
+
|
21
|
+
def silence_stream(stream)
|
22
|
+
old_stream = stream.dup
|
23
|
+
stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
|
24
|
+
stream.sync = true
|
25
|
+
yield
|
26
|
+
ensure
|
27
|
+
stream.reopen(old_stream)
|
28
|
+
old_stream.close
|
29
|
+
end
|
30
|
+
|
31
|
+
def silence_stderr
|
32
|
+
silence_stream(STDERR) { yield }
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module UnitTests
|
2
|
+
module ActiveModelHelpers
|
3
|
+
def self.configure_example_group(example_group)
|
4
|
+
example_group.include(self)
|
5
|
+
end
|
6
|
+
|
7
|
+
def custom_validation(options = {}, &block)
|
8
|
+
attribute_name = options.fetch(:attribute_name, :attr)
|
9
|
+
attribute_type = options.fetch(:attribute_type, :integer)
|
10
|
+
|
11
|
+
define_model(:example, attribute_name => attribute_type) do
|
12
|
+
validate :custom_validation
|
13
|
+
|
14
|
+
define_method(:custom_validation, &block)
|
15
|
+
end.new
|
16
|
+
end
|
17
|
+
alias record_with_custom_validation custom_validation
|
18
|
+
|
19
|
+
def validating_format(options)
|
20
|
+
define_model :example, attr: :string do
|
21
|
+
validates_format_of :attr, options
|
22
|
+
end.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module UnitTests
|
2
|
+
module ActiveModelVersions
|
3
|
+
def self.configure_example_group(example_group)
|
4
|
+
example_group.include(self)
|
5
|
+
example_group.extend(self)
|
6
|
+
end
|
7
|
+
|
8
|
+
def active_model_3_1?
|
9
|
+
(::ActiveModel::VERSION::MAJOR == 3 && ::ActiveModel::VERSION::MINOR >= 1) || active_model_4_0?
|
10
|
+
end
|
11
|
+
|
12
|
+
def active_model_3_2?
|
13
|
+
(::ActiveModel::VERSION::MAJOR == 3 && ::ActiveModel::VERSION::MINOR >= 2) || active_model_4_0?
|
14
|
+
end
|
15
|
+
|
16
|
+
def active_model_4_0?
|
17
|
+
::ActiveModel::VERSION::MAJOR == 4
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
module UnitTests
|
4
|
+
module ActiveResourceBuilder
|
5
|
+
def self.configure_example_group(example_group)
|
6
|
+
example_group.include ActiveResourceBuilder
|
7
|
+
|
8
|
+
example_group.after do
|
9
|
+
ActiveSupport::Dependencies.clear
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def define_active_resource_class(class_name, attributes = {}, &block)
|
14
|
+
define_class(class_name, ActiveResource::Base) do
|
15
|
+
schema do
|
16
|
+
attributes.each do |attr, type|
|
17
|
+
attribute attr, type
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
if block_given?
|
22
|
+
class_eval(&block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|