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.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +72 -40
- data/lib/shoulda/matchers/action_controller.rb +2 -0
- data/lib/shoulda/matchers/active_model.rb +2 -3
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +1 -0
- data/lib/shoulda/matchers/active_record.rb +2 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +34 -0
- data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +27 -4
- data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +27 -4
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/independent.rb +2 -1
- data/lib/shoulda/matchers/rails_shim.rb +5 -9
- data/lib/shoulda/matchers/version.rb +1 -1
- data/lib/shoulda/matchers/warn.rb +1 -0
- data/shoulda-matchers.gemspec +11 -3
- metadata +13 -340
- data/.gitignore +0 -12
- data/.hound.yml +0 -3
- data/.hound/ruby.yml +0 -1062
- data/.python-version +0 -1
- data/.rubocop.yml +0 -15
- data/.travis.yml +0 -21
- data/.yardopts +0 -10
- data/Appraisals +0 -105
- data/CONTRIBUTING.md +0 -172
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -59
- data/MAINTAINING.md +0 -250
- data/NEWS.md +0 -1235
- data/Rakefile +0 -46
- data/bin/setup +0 -190
- data/custom_plan.rb +0 -104
- data/doc_config/gh-pages/index.html.erb +0 -9
- data/doc_config/yard/setup.rb +0 -22
- data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
- data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
- data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -66
- data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
- data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
- data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -26
- data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
- data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
- data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -281
- data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
- data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
- data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
- data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -35
- data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
- data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
- data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
- data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
- data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
- data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
- data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
- data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
- data/gemfiles/4.2.gemfile +0 -39
- data/gemfiles/4.2.gemfile.lock +0 -246
- data/gemfiles/5.0.gemfile +0 -37
- data/gemfiles/5.0.gemfile.lock +0 -238
- data/gemfiles/5.1.gemfile +0 -38
- data/gemfiles/5.1.gemfile.lock +0 -254
- data/gemfiles/5.2.gemfile +0 -40
- data/gemfiles/5.2.gemfile.lock +0 -273
- data/script/install_gems_in_all_appraisals +0 -16
- data/script/run_all_tests +0 -16
- data/script/supported_ruby_versions +0 -7
- data/script/update_gem_in_all_appraisals +0 -17
- data/script/update_gems_in_all_appraisals +0 -16
- data/spec/acceptance/active_model_integration_spec.rb +0 -23
- data/spec/acceptance/independent_matchers_spec.rb +0 -125
- data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
- data/spec/acceptance/rails_integration_spec.rb +0 -156
- data/spec/acceptance_spec_helper.rb +0 -23
- data/spec/doublespeak_spec_helper.rb +0 -2
- data/spec/report_warnings.rb +0 -7
- data/spec/spec_helper.rb +0 -20
- data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
- data/spec/support/acceptance/helpers.rb +0 -33
- data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
- data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
- data/spec/support/acceptance/helpers/command_helpers.rb +0 -68
- data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
- data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
- data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
- data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
- data/spec/support/acceptance/helpers/rails_migration_helpers.rb +0 -21
- data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
- data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
- data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
- data/spec/support/acceptance/matchers/have_output.rb +0 -31
- data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
- data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
- data/spec/support/tests/bundle.rb +0 -94
- data/spec/support/tests/command_runner.rb +0 -230
- data/spec/support/tests/current_bundle.rb +0 -55
- data/spec/support/tests/database.rb +0 -28
- data/spec/support/tests/database_adapters/postgresql.rb +0 -25
- data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
- data/spec/support/tests/database_configuration.rb +0 -33
- data/spec/support/tests/database_configuration_registry.rb +0 -28
- data/spec/support/tests/filesystem.rb +0 -100
- data/spec/support/tests/version.rb +0 -45
- data/spec/support/unit/active_record/create_table.rb +0 -54
- data/spec/support/unit/attribute.rb +0 -45
- data/spec/support/unit/capture.rb +0 -46
- data/spec/support/unit/change_value.rb +0 -111
- data/spec/support/unit/create_model_arguments/basic.rb +0 -135
- data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
- data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
- data/spec/support/unit/helpers/action_pack_versions.rb +0 -22
- data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
- data/spec/support/unit/helpers/active_model_versions.rb +0 -32
- data/spec/support/unit/helpers/active_record_versions.rb +0 -44
- data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
- data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
- data/spec/support/unit/helpers/class_builder.rb +0 -90
- data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
- data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
- data/spec/support/unit/helpers/controller_builder.rb +0 -63
- data/spec/support/unit/helpers/database_helpers.rb +0 -20
- data/spec/support/unit/helpers/i18n_faker.rb +0 -15
- data/spec/support/unit/helpers/mailer_builder.rb +0 -12
- data/spec/support/unit/helpers/message_helpers.rb +0 -19
- data/spec/support/unit/helpers/model_builder.rb +0 -114
- data/spec/support/unit/helpers/rails_versions.rb +0 -42
- data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
- data/spec/support/unit/i18n.rb +0 -7
- data/spec/support/unit/load_environment.rb +0 -12
- data/spec/support/unit/matchers/deprecate.rb +0 -60
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -64
- data/spec/support/unit/matchers/print_warning_including.rb +0 -67
- data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
- data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
- data/spec/support/unit/model_creators.rb +0 -19
- data/spec/support/unit/model_creators/active_model.rb +0 -39
- data/spec/support/unit/model_creators/active_record.rb +0 -42
- data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
- data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
- data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
- data/spec/support/unit/model_creators/basic.rb +0 -102
- data/spec/support/unit/rails_application.rb +0 -151
- data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
- data/spec/support/unit/record_validating_confirmation_builder.rb +0 -54
- data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
- data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
- data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
- data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
- data/spec/support/unit/validation_matcher_scenario.rb +0 -60
- data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
- data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
- data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -629
- data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
- data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
- data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
- data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
- data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
- data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
- data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -117
- data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -829
- data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
- data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
- data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
- data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -290
- data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -109
- data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -172
- data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -264
- data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1049
- data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -335
- data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1865
- data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -406
- data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
- data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1672
- data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
- data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -690
- data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
- data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
- data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
- data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +0 -169
- data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
- data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1682
- data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
- data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
- data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
- data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
- data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
- data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -78
- data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -650
- data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -406
- data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
- data/spec/unit_spec_helper.rb +0 -54
- data/spec/warnings_spy.rb +0 -64
- data/spec/warnings_spy/filesystem.rb +0 -45
- data/spec/warnings_spy/partitioner.rb +0 -36
- data/spec/warnings_spy/reader.rb +0 -53
- data/spec/warnings_spy/reporter.rb +0 -88
- data/tasks/documentation.rb +0 -199
- data/zeus.json +0 -11
@@ -1,103 +0,0 @@
|
|
1
|
-
require_relative '../helpers/array_helpers'
|
2
|
-
require_relative '../helpers/pluralization_helpers'
|
3
|
-
require_relative '../helpers/rails_version_helpers'
|
4
|
-
|
5
|
-
module AcceptanceTests
|
6
|
-
module Matchers
|
7
|
-
def indicate_that_tests_were_run(series)
|
8
|
-
IndicateThatTestsWereRunMatcher.new(series)
|
9
|
-
end
|
10
|
-
|
11
|
-
class IndicateThatTestsWereRunMatcher
|
12
|
-
include ArrayHelpers
|
13
|
-
include PluralizationHelpers
|
14
|
-
include RailsVersionHelpers
|
15
|
-
|
16
|
-
def initialize(args)
|
17
|
-
@args = args
|
18
|
-
@series = args.values
|
19
|
-
end
|
20
|
-
|
21
|
-
def matches?(runner)
|
22
|
-
@runner = runner
|
23
|
-
!matching_expected_output.nil?
|
24
|
-
end
|
25
|
-
|
26
|
-
def failure_message
|
27
|
-
"Expected output to indicate that #{some_tests_were_run}.\n" +
|
28
|
-
"#{formatted_expected_output}\n" +
|
29
|
-
"#{formatted_actual_output}\n"
|
30
|
-
end
|
31
|
-
|
32
|
-
protected
|
33
|
-
|
34
|
-
attr_reader :args, :series, :runner
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def expected_outputs
|
39
|
-
[
|
40
|
-
expected_output_for_rails_3,
|
41
|
-
expected_output_for_turn,
|
42
|
-
expected_output_for_rails_4
|
43
|
-
]
|
44
|
-
end
|
45
|
-
|
46
|
-
def matching_expected_output
|
47
|
-
@_matching_expected_output ||=
|
48
|
-
expected_outputs.detect do |expected_output|
|
49
|
-
actual_output =~ expected_output
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def expected_output_for_rails_3
|
54
|
-
full_report = series.map do |number|
|
55
|
-
"#{number} tests, #{number} assertions, 0 failures, 0 errors(, 0 skips)?"
|
56
|
-
end.join('.+')
|
57
|
-
|
58
|
-
Regexp.new(full_report, Regexp::MULTILINE)
|
59
|
-
end
|
60
|
-
|
61
|
-
def expected_output_for_turn
|
62
|
-
full_report = series.map do |number|
|
63
|
-
"pass: #{number}, fail: 0, error: 0"
|
64
|
-
end.join('.+')
|
65
|
-
|
66
|
-
Regexp.new(full_report, Regexp::MULTILINE)
|
67
|
-
end
|
68
|
-
|
69
|
-
def expected_output_for_rails_4
|
70
|
-
total = series.inject(:+)
|
71
|
-
/#{total} (tests|runs), #{total} assertions, 0 failures, 0 errors(, 0 skips)?/
|
72
|
-
end
|
73
|
-
|
74
|
-
def formatted_expected_output
|
75
|
-
if matching_expected_output
|
76
|
-
"Expected output:\n#{matching_actual_output}"
|
77
|
-
else
|
78
|
-
"Expected output: (n/a)"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def actual_output
|
83
|
-
runner.output
|
84
|
-
end
|
85
|
-
|
86
|
-
def formatted_actual_output
|
87
|
-
if actual_output.empty?
|
88
|
-
"Actual output: (empty)"
|
89
|
-
else
|
90
|
-
"Actual output:\n#{actual_output}"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def some_tests_were_run
|
95
|
-
clauses = args.map do |type, number|
|
96
|
-
pluralize(number, "#{type} test was run", "#{type} tests were run")
|
97
|
-
end
|
98
|
-
|
99
|
-
to_sentence(clauses)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require_relative 'filesystem'
|
2
|
-
require_relative 'command_runner'
|
3
|
-
require_relative 'version'
|
4
|
-
|
5
|
-
module Tests
|
6
|
-
class Bundle
|
7
|
-
def initialize
|
8
|
-
@already_updating = false
|
9
|
-
@fs = Filesystem.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def updating(&block)
|
13
|
-
if already_updating?
|
14
|
-
yield self
|
15
|
-
return
|
16
|
-
end
|
17
|
-
|
18
|
-
@already_updating = true
|
19
|
-
|
20
|
-
yield self
|
21
|
-
|
22
|
-
@already_updating = false
|
23
|
-
|
24
|
-
install_gems
|
25
|
-
end
|
26
|
-
|
27
|
-
def add_gem(gem, *args)
|
28
|
-
updating do
|
29
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
30
|
-
version = args.shift
|
31
|
-
line = assemble_gem_line(gem, version, options)
|
32
|
-
fs.append_to_file('Gemfile', line)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def remove_gem(gem)
|
37
|
-
updating do
|
38
|
-
fs.comment_lines_matching('Gemfile', /^[ ]*gem ("|')#{gem}\1/)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def install_gems
|
43
|
-
CommandRunner.run!('bundle install --local') do |runner|
|
44
|
-
runner.retries = 5
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def version_of(gem)
|
49
|
-
Version.new(Bundler.definition.specs[gem][0].version)
|
50
|
-
end
|
51
|
-
|
52
|
-
def includes?(gem)
|
53
|
-
Bundler.definition.dependencies.any? do |dependency|
|
54
|
-
dependency.name == gem
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
protected
|
59
|
-
|
60
|
-
attr_reader :fs
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def already_updating?
|
65
|
-
@already_updating
|
66
|
-
end
|
67
|
-
|
68
|
-
def assemble_gem_line(gem, version, options)
|
69
|
-
formatted_options = options.
|
70
|
-
map { |key, value| "#{key}: #{formatted_value(value)}" }.
|
71
|
-
join(', ')
|
72
|
-
|
73
|
-
line = %(gem '#{gem}')
|
74
|
-
|
75
|
-
if version
|
76
|
-
line << %(, '#{version}')
|
77
|
-
end
|
78
|
-
|
79
|
-
if options.any?
|
80
|
-
line << %(, #{formatted_options})
|
81
|
-
end
|
82
|
-
|
83
|
-
line << "\n"
|
84
|
-
end
|
85
|
-
|
86
|
-
def formatted_value(value)
|
87
|
-
if value.is_a?(Pathname)
|
88
|
-
value.to_s.inspect
|
89
|
-
else
|
90
|
-
value.inspect
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,230 +0,0 @@
|
|
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
|
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
|
-
self.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
|
51
|
-
@options[:chdir]
|
52
|
-
end
|
53
|
-
|
54
|
-
def directory=(directory)
|
55
|
-
@options[:chdir] = directory || Dir.pwd
|
56
|
-
end
|
57
|
-
|
58
|
-
def formatted_command
|
59
|
-
[formatted_env, Shellwords.join(command)].
|
60
|
-
select { |value| !value.empty? }.
|
61
|
-
join(' ')
|
62
|
-
end
|
63
|
-
|
64
|
-
def call
|
65
|
-
possibly_retrying do
|
66
|
-
possibly_running_quickly do
|
67
|
-
run_with_debugging
|
68
|
-
|
69
|
-
if run_successfully && !success?
|
70
|
-
fail!
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
self
|
76
|
-
end
|
77
|
-
|
78
|
-
def stop
|
79
|
-
unless writer.closed?
|
80
|
-
writer.close
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def output
|
85
|
-
@_output ||= begin
|
86
|
-
stop
|
87
|
-
without_colors(reader.read)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def elided_output
|
92
|
-
lines = output.split(/\n/)
|
93
|
-
new_lines = lines[0..4]
|
94
|
-
|
95
|
-
if lines.size > 10
|
96
|
-
new_lines << "(...#{lines.size - 10} more lines...)"
|
97
|
-
end
|
98
|
-
|
99
|
-
new_lines << lines[-5..-1]
|
100
|
-
new_lines.join("\n")
|
101
|
-
end
|
102
|
-
|
103
|
-
def success?
|
104
|
-
status.success?
|
105
|
-
end
|
106
|
-
|
107
|
-
def exit_status
|
108
|
-
status.exitstatus
|
109
|
-
end
|
110
|
-
|
111
|
-
def fail!
|
112
|
-
raise <<-MESSAGE
|
113
|
-
Command #{formatted_command.inspect} exited with status #{exit_status}.
|
114
|
-
Output:
|
115
|
-
#{divider('START') + output + divider('END')}
|
116
|
-
MESSAGE
|
117
|
-
end
|
118
|
-
|
119
|
-
def has_output?(expected_output)
|
120
|
-
if expected_output.is_a?(Regexp)
|
121
|
-
output =~ expected_output
|
122
|
-
else
|
123
|
-
output.include?(expected_output)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
protected
|
128
|
-
|
129
|
-
attr_reader :args, :reader, :writer, :wrapper
|
130
|
-
|
131
|
-
private
|
132
|
-
|
133
|
-
def extract_env_from(options)
|
134
|
-
options.delete(:env) { {} }.inject({}) do |hash, (key, value)|
|
135
|
-
hash[key.to_s] = value
|
136
|
-
hash
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def command
|
141
|
-
([command_prefix] + args).flatten.flat_map do |word|
|
142
|
-
Shellwords.split(word)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def formatted_env
|
147
|
-
env.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
|
148
|
-
end
|
149
|
-
|
150
|
-
def run
|
151
|
-
pid = spawn(env, *command, options)
|
152
|
-
Process.waitpid(pid)
|
153
|
-
@status = $?
|
154
|
-
end
|
155
|
-
|
156
|
-
def run_with_wrapper
|
157
|
-
wrapper.call(method(:run))
|
158
|
-
end
|
159
|
-
|
160
|
-
def run_with_debugging
|
161
|
-
debug { "\n\e[33mChanging to directory:\e[0m #{directory}" }
|
162
|
-
debug { "\e[32mRunning command:\e[0m #{formatted_command}" }
|
163
|
-
|
164
|
-
run_with_wrapper
|
165
|
-
|
166
|
-
debug { "\n" + divider('START') + output + divider('END') }
|
167
|
-
end
|
168
|
-
|
169
|
-
def possibly_running_quickly(&block)
|
170
|
-
if run_quickly
|
171
|
-
begin
|
172
|
-
Timeout.timeout(timeout, &block)
|
173
|
-
rescue Timeout::Error
|
174
|
-
stop
|
175
|
-
|
176
|
-
message =
|
177
|
-
"Command timed out after #{timeout} seconds: #{formatted_command}\n" +
|
178
|
-
"Output:\n" +
|
179
|
-
output
|
180
|
-
|
181
|
-
raise TimeoutError, message
|
182
|
-
end
|
183
|
-
else
|
184
|
-
yield
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
def possibly_retrying
|
189
|
-
begin
|
190
|
-
@num_times_run += 1
|
191
|
-
yield
|
192
|
-
rescue => error
|
193
|
-
debug { "#{error.class}: #{error.message}" }
|
194
|
-
|
195
|
-
if @num_times_run < @retries
|
196
|
-
sleep @num_times_run
|
197
|
-
retry
|
198
|
-
else
|
199
|
-
raise error
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def divider(title = '')
|
205
|
-
total_length = 72
|
206
|
-
start_length = 3
|
207
|
-
|
208
|
-
string = ''
|
209
|
-
string << ('-' * start_length)
|
210
|
-
string << title
|
211
|
-
string << '-' * (total_length - start_length - title.length)
|
212
|
-
string << "\n"
|
213
|
-
string
|
214
|
-
end
|
215
|
-
|
216
|
-
def without_colors(string)
|
217
|
-
string.gsub(/\e\[\d+(?:;\d+)?m(.+?)\e\[0m/, '\1')
|
218
|
-
end
|
219
|
-
|
220
|
-
def debugging_enabled?
|
221
|
-
ENV['DEBUG_COMMANDS'] == '1'
|
222
|
-
end
|
223
|
-
|
224
|
-
def debug(&block)
|
225
|
-
if debugging_enabled?
|
226
|
-
puts block.call
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
require 'appraisal'
|
3
|
-
|
4
|
-
module Tests
|
5
|
-
class CurrentBundle
|
6
|
-
AppraisalNotSpecified = Class.new(ArgumentError)
|
7
|
-
|
8
|
-
include Singleton
|
9
|
-
|
10
|
-
def assert_appraisal!
|
11
|
-
unless appraisal_in_use?
|
12
|
-
message = <<EOT
|
13
|
-
|
14
|
-
|
15
|
-
Please run tests starting with `appraisal <appraisal_name>`.
|
16
|
-
Possible appraisals are: #{available_appraisals}
|
17
|
-
|
18
|
-
EOT
|
19
|
-
raise AppraisalNotSpecified, message
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def appraisal_in_use?
|
24
|
-
path.dirname == root.join('gemfiles')
|
25
|
-
end
|
26
|
-
|
27
|
-
def current_or_latest_appraisal
|
28
|
-
current_appraisal || latest_appraisal
|
29
|
-
end
|
30
|
-
|
31
|
-
def latest_appraisal
|
32
|
-
available_appraisals.sort.last
|
33
|
-
end
|
34
|
-
|
35
|
-
def available_appraisals
|
36
|
-
Appraisal::AppraisalFile.each.map(&:name)
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def current_appraisal
|
42
|
-
if appraisal_in_use?
|
43
|
-
File.basename(path, ".gemfile")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def path
|
48
|
-
Bundler.default_gemfile
|
49
|
-
end
|
50
|
-
|
51
|
-
def root
|
52
|
-
Pathname.new('../../../..').expand_path(__FILE__)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|