shoulda-matchers 2.8.0 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound_config/ruby.yml +7 -0
- data/.travis.yml +11 -54
- data/Appraisals +45 -100
- data/CONTRIBUTING.md +51 -7
- data/Gemfile +7 -19
- data/Gemfile.lock +60 -134
- data/Guardfile +5 -0
- data/NEWS.md +203 -0
- data/README.md +95 -50
- data/Rakefile +1 -0
- data/doc_config/yard/templates/default/layout/html/setup.rb +1 -1
- data/gemfiles/4.0.0.gemfile +10 -7
- data/gemfiles/4.0.0.gemfile.lock +103 -79
- data/gemfiles/4.0.1.gemfile +10 -7
- data/gemfiles/4.0.1.gemfile.lock +109 -83
- data/gemfiles/4.1.gemfile +10 -7
- data/gemfiles/4.1.gemfile.lock +109 -85
- data/gemfiles/4.2.gemfile +10 -9
- data/gemfiles/4.2.gemfile.lock +86 -78
- data/lib/shoulda/matchers.rb +13 -18
- data/lib/shoulda/matchers/action_controller.rb +4 -1
- data/lib/shoulda/matchers/action_controller/flash_store.rb +95 -0
- data/lib/shoulda/matchers/action_controller/{strong_parameters_matcher.rb → permit_matcher.rb} +147 -30
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -1
- data/lib/shoulda/matchers/action_controller/route_params.rb +15 -6
- data/lib/shoulda/matchers/action_controller/session_store.rb +34 -0
- data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +30 -136
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +28 -109
- data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +103 -0
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +1 -12
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +79 -10
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +10 -0
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +21 -0
- data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +24 -0
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +22 -5
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +29 -10
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +27 -10
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +27 -12
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +56 -20
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +3 -11
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +65 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +40 -6
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +21 -7
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +11 -40
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +1 -1
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +2 -6
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +137 -22
- data/lib/shoulda/matchers/configuration.rb +20 -0
- data/lib/shoulda/matchers/doublespeak.rb +11 -1
- data/lib/shoulda/matchers/doublespeak/double.rb +29 -11
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +4 -3
- data/lib/shoulda/matchers/doublespeak/method_call.rb +35 -0
- data/lib/shoulda/matchers/doublespeak/object_double.rb +7 -2
- data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +4 -3
- data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +3 -3
- data/lib/shoulda/matchers/doublespeak/world.rb +21 -1
- data/lib/shoulda/matchers/integrations.rb +43 -0
- data/lib/shoulda/matchers/integrations/configuration.rb +68 -0
- data/lib/shoulda/matchers/integrations/configuration_error.rb +9 -0
- data/lib/shoulda/matchers/integrations/inclusion.rb +20 -0
- data/lib/shoulda/matchers/integrations/libraries.rb +15 -0
- data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +31 -0
- data/lib/shoulda/matchers/integrations/libraries/active_model.rb +26 -0
- data/lib/shoulda/matchers/integrations/libraries/active_record.rb +26 -0
- data/lib/shoulda/matchers/integrations/libraries/missing_library.rb +19 -0
- data/lib/shoulda/matchers/integrations/libraries/rails.rb +30 -0
- data/lib/shoulda/matchers/integrations/rails.rb +12 -0
- data/lib/shoulda/matchers/integrations/registry.rb +28 -0
- data/lib/shoulda/matchers/integrations/test_frameworks.rb +16 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +37 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +36 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +37 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +40 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +29 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +36 -0
- data/lib/shoulda/matchers/rails_shim.rb +0 -40
- data/lib/shoulda/matchers/version.rb +1 -1
- data/script/SUPPORTED_VERSIONS +1 -1
- data/script/update_gems_in_all_appraisals +14 -0
- data/shoulda-matchers.gemspec +2 -2
- data/spec/acceptance/active_model_integration_spec.rb +4 -1
- data/spec/acceptance/independent_matchers_spec.rb +6 -6
- data/spec/acceptance/multiple_libraries_integration_spec.rb +52 -0
- data/spec/acceptance/rails_integration_spec.rb +15 -5
- data/spec/acceptance_spec_helper.rb +8 -0
- data/spec/doublespeak_spec_helper.rb +14 -0
- data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +110 -0
- data/spec/support/acceptance/helpers.rb +2 -0
- data/spec/support/acceptance/helpers/base_helpers.rb +6 -1
- data/spec/support/acceptance/helpers/command_helpers.rb +6 -2
- data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -8
- data/spec/support/acceptance/helpers/n_unit_helpers.rb +25 -0
- data/spec/support/acceptance/helpers/rspec_helpers.rb +2 -0
- data/spec/support/acceptance/helpers/step_helpers.rb +13 -19
- data/spec/support/acceptance/matchers/have_output.rb +1 -1
- data/spec/support/tests/bundle.rb +1 -1
- data/spec/support/tests/command_runner.rb +25 -13
- data/spec/support/tests/current_bundle.rb +47 -0
- data/spec/support/tests/database.rb +28 -0
- data/spec/support/tests/database_adapters/postgresql.rb +25 -0
- data/spec/support/tests/database_adapters/sqlite3.rb +26 -0
- data/spec/support/tests/database_configuration.rb +33 -0
- data/spec/support/tests/database_configuration_registry.rb +28 -0
- data/spec/support/tests/filesystem.rb +25 -2
- data/spec/support/unit/helpers/active_record_versions.rb +12 -0
- data/spec/support/unit/helpers/class_builder.rb +6 -2
- data/spec/support/unit/helpers/column_type_helpers.rb +26 -0
- data/spec/support/unit/helpers/controller_builder.rb +0 -28
- data/spec/support/unit/helpers/database_helpers.rb +18 -0
- data/spec/support/unit/helpers/model_builder.rb +38 -6
- data/spec/support/unit/helpers/rails_versions.rb +2 -2
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +9 -8
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +1 -1
- data/spec/support/unit/rails_application.rb +29 -13
- data/spec/support/unit/record_validating_confirmation_builder.rb +1 -2
- data/spec/support/unit/shared_examples/set_session_or_flash.rb +355 -0
- data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +433 -0
- data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +1 -5
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +37 -0
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +23 -147
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +8 -285
- data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +562 -0
- data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +81 -14
- data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +16 -8
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +101 -9
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +39 -1
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +39 -1
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +39 -0
- data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +838 -271
- data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -19
- data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +93 -0
- data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +3 -3
- data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +25 -0
- data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +905 -0
- data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +17 -11
- data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
- data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +144 -43
- data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +1 -1
- data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +36 -11
- data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +29 -16
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +8 -5
- data/spec/unit/shoulda/matchers/doublespeak_spec.rb +1 -1
- data/spec/unit_spec_helper.rb +15 -14
- data/spec/warnings_spy.rb +1 -1
- metadata +68 -29
- data/docs.watchr +0 -5
- data/gemfiles/3.0.gemfile +0 -26
- data/gemfiles/3.0.gemfile.lock +0 -173
- data/gemfiles/3.1.gemfile +0 -32
- data/gemfiles/3.1.gemfile.lock +0 -212
- data/gemfiles/3.1_1.9.2.gemfile +0 -32
- data/gemfiles/3.1_1.9.2.gemfile.lock +0 -212
- data/gemfiles/3.2.gemfile +0 -33
- data/gemfiles/3.2.gemfile.lock +0 -212
- data/gemfiles/3.2_1.9.2.gemfile +0 -31
- data/gemfiles/3.2_1.9.2.gemfile.lock +0 -207
- data/lib/shoulda/matchers/assertion_error.rb +0 -27
- data/lib/shoulda/matchers/doublespeak/structs.rb +0 -10
- data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +0 -39
- data/lib/shoulda/matchers/integrations/rspec.rb +0 -19
- data/lib/shoulda/matchers/integrations/test_unit.rb +0 -34
- data/spec/unit/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +0 -331
- data/spec/unit/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -564
@@ -14,7 +14,7 @@ describe 'shoulda-matchers integrates with Rails' do
|
|
14
14
|
end
|
15
15
|
FILE
|
16
16
|
|
17
|
-
run_rake_tasks!(
|
17
|
+
run_rake_tasks!(*%w(db:drop db:create db:migrate))
|
18
18
|
|
19
19
|
write_file 'app/models/user.rb', <<-FILE
|
20
20
|
class User < ActiveRecord::Base
|
@@ -34,10 +34,13 @@ describe 'shoulda-matchers integrates with Rails' do
|
|
34
34
|
configure_routes_with_single_wildcard_route
|
35
35
|
end
|
36
36
|
|
37
|
-
specify 'in a project that uses
|
37
|
+
specify 'in a project that uses the default test framework' do
|
38
38
|
updating_bundle do
|
39
39
|
add_gems_for_n_unit
|
40
|
-
add_shoulda_matchers_to_project
|
40
|
+
add_shoulda_matchers_to_project(
|
41
|
+
test_frameworks: [default_test_framework],
|
42
|
+
libraries: [:rails]
|
43
|
+
)
|
41
44
|
end
|
42
45
|
|
43
46
|
run_tests_for_n_unit
|
@@ -46,7 +49,10 @@ describe 'shoulda-matchers integrates with Rails' do
|
|
46
49
|
specify 'in a project that uses RSpec' do
|
47
50
|
updating_bundle do
|
48
51
|
add_gems_for_rspec
|
49
|
-
add_shoulda_matchers_to_project(
|
52
|
+
add_shoulda_matchers_to_project(
|
53
|
+
test_frameworks: [:rspec],
|
54
|
+
libraries: [:rails]
|
55
|
+
)
|
50
56
|
end
|
51
57
|
|
52
58
|
run_tests_for_rspec
|
@@ -62,6 +68,7 @@ describe 'shoulda-matchers integrates with Rails' do
|
|
62
68
|
add_gems_for_rspec
|
63
69
|
add_shoulda_matchers_to_project(
|
64
70
|
test_frameworks: [:rspec],
|
71
|
+
libraries: [:rails],
|
65
72
|
manually: true
|
66
73
|
)
|
67
74
|
end
|
@@ -75,7 +82,10 @@ describe 'shoulda-matchers integrates with Rails' do
|
|
75
82
|
updating_bundle do
|
76
83
|
add_gems_for_n_unit
|
77
84
|
add_gems_for_rspec
|
78
|
-
add_shoulda_matchers_to_project
|
85
|
+
add_shoulda_matchers_to_project(
|
86
|
+
test_frameworks: [:rspec, nil],
|
87
|
+
libraries: [:rails]
|
88
|
+
)
|
79
89
|
end
|
80
90
|
|
81
91
|
run_tests_for_n_unit
|
@@ -1,4 +1,12 @@
|
|
1
|
+
require_relative 'support/tests/current_bundle'
|
2
|
+
|
3
|
+
Tests::CurrentBundle.instance.assert_appraisal!
|
4
|
+
|
5
|
+
#---
|
6
|
+
|
1
7
|
require 'rspec/core'
|
8
|
+
require 'pry'
|
9
|
+
require 'pry-byebug'
|
2
10
|
|
3
11
|
Dir[ File.join(File.expand_path('../support/acceptance/**/*.rb', __FILE__)) ].sort.each do |file|
|
4
12
|
require file
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'shoulda-matchers'
|
2
|
+
|
3
|
+
PROJECT_ROOT = File.expand_path('../..', __FILE__)
|
4
|
+
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.order = :random
|
8
|
+
|
9
|
+
config.expect_with :rspec do |c|
|
10
|
+
c.syntax = :expect
|
11
|
+
end
|
12
|
+
|
13
|
+
config.mock_with :rspec
|
14
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require_relative 'helpers/base_helpers'
|
2
|
+
require_relative 'helpers/rspec_helpers'
|
3
|
+
|
4
|
+
module AcceptanceTests
|
5
|
+
class AddsShouldaMatchersToProject
|
6
|
+
def self.call(options)
|
7
|
+
new(options).call
|
8
|
+
end
|
9
|
+
|
10
|
+
include BaseHelpers
|
11
|
+
include RspecHelpers
|
12
|
+
|
13
|
+
def initialize(options)
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
add_gem 'shoulda-matchers', gem_options
|
19
|
+
configure_test_helper_files
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
attr_reader :options
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def gem_options
|
29
|
+
gem_options = { path: fs.root_directory }
|
30
|
+
|
31
|
+
if options[:manually]
|
32
|
+
gem_options[:require] = false
|
33
|
+
end
|
34
|
+
|
35
|
+
gem_options
|
36
|
+
end
|
37
|
+
|
38
|
+
def configure_test_helper_files
|
39
|
+
each_test_helper_file do |test_helper_file, test_framework, library|
|
40
|
+
add_configuration_block_to(
|
41
|
+
test_helper_file,
|
42
|
+
test_framework,
|
43
|
+
library
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def each_test_helper_file
|
49
|
+
options[:test_frameworks].each do |test_framework|
|
50
|
+
libraries = options.fetch(:libraries, [])
|
51
|
+
test_helper_file = test_helper_file_for(test_framework, libraries)
|
52
|
+
yield test_helper_file, test_framework, libraries
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_configuration_block_to(test_helper_file, test_framework, libraries)
|
57
|
+
test_framework_config = test_framework_config_for(test_framework)
|
58
|
+
library_config = library_config_for(libraries)
|
59
|
+
|
60
|
+
content = <<-EOT
|
61
|
+
Shoulda::Matchers.configure do |config|
|
62
|
+
config.integrate do |with|
|
63
|
+
#{test_framework_config}
|
64
|
+
#{library_config}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
EOT
|
68
|
+
|
69
|
+
if options[:manually]
|
70
|
+
content = "require 'shoulda-matchers'\n#{content}"
|
71
|
+
end
|
72
|
+
|
73
|
+
fs.append_to_file(test_helper_file, content)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_framework_config_for(test_framework)
|
77
|
+
if test_framework
|
78
|
+
"with.test_framework :#{test_framework}\n"
|
79
|
+
else
|
80
|
+
''
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def library_config_for(libraries)
|
85
|
+
libraries.map { |library| "with.library :#{library}" }.join("\n")
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_helper_file_for(test_framework, libraries)
|
89
|
+
if integrates_with_rails?(test_framework, libraries) ||
|
90
|
+
integrates_with_nunit?(test_framework)
|
91
|
+
'test/test_helper.rb'
|
92
|
+
elsif integrates_with_rspec?(test_framework)
|
93
|
+
spec_helper_file_path
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def integrates_with_nunit?(test_framework)
|
98
|
+
nunit_frameworks = [:test_unit, :minitest, :minitest_4, :minitest_5]
|
99
|
+
nunit_frameworks.include?(test_framework)
|
100
|
+
end
|
101
|
+
|
102
|
+
def integrates_with_rspec?(test_framework)
|
103
|
+
test_framework == :rspec
|
104
|
+
end
|
105
|
+
|
106
|
+
def integrates_with_rails?(test_framework, libraries)
|
107
|
+
test_framework.nil? && libraries.include?(:rails)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -2,6 +2,7 @@ require_relative 'helpers/active_model_helpers'
|
|
2
2
|
require_relative 'helpers/base_helpers'
|
3
3
|
require_relative 'helpers/command_helpers'
|
4
4
|
require_relative 'helpers/gem_helpers'
|
5
|
+
require_relative 'helpers/n_unit_helpers'
|
5
6
|
require_relative 'helpers/rails_version_helpers'
|
6
7
|
require_relative 'helpers/rspec_helpers'
|
7
8
|
require_relative 'helpers/ruby_version_helpers'
|
@@ -21,6 +22,7 @@ module AcceptanceTests
|
|
21
22
|
include BaseHelpers
|
22
23
|
include CommandHelpers
|
23
24
|
include GemHelpers
|
25
|
+
include NUnitHelpers
|
24
26
|
include RailsVersionHelpers
|
25
27
|
include RspecHelpers
|
26
28
|
include RubyVersionHelpers
|
@@ -1,5 +1,6 @@
|
|
1
|
-
require_relative '../../tests/filesystem'
|
2
1
|
require_relative '../../tests/bundle'
|
2
|
+
require_relative '../../tests/database'
|
3
|
+
require_relative '../../tests/filesystem'
|
3
4
|
|
4
5
|
module AcceptanceTests
|
5
6
|
module BaseHelpers
|
@@ -10,5 +11,9 @@ module AcceptanceTests
|
|
10
11
|
def bundle
|
11
12
|
@_bundle ||= Tests::Bundle.new
|
12
13
|
end
|
14
|
+
|
15
|
+
def database
|
16
|
+
@_database ||= Tests::Database.instance
|
17
|
+
end
|
13
18
|
end
|
14
19
|
end
|
@@ -41,11 +41,15 @@ module AcceptanceTests
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def run_rake_tasks(*tasks)
|
44
|
-
|
44
|
+
options = tasks.last.is_a?(Hash) ? tasks.pop : {}
|
45
|
+
args = ['rake', *tasks, '--trace'] + [options]
|
46
|
+
run_command_within_bundle(*args)
|
45
47
|
end
|
46
48
|
|
47
49
|
def run_rake_tasks!(*tasks)
|
48
|
-
|
50
|
+
options = tasks.last.is_a?(Hash) ? tasks.pop : {}
|
51
|
+
args = ['rake', *tasks, '--trace'] + [options]
|
52
|
+
run_command_within_bundle!(*args)
|
49
53
|
end
|
50
54
|
end
|
51
55
|
end
|
@@ -4,14 +4,6 @@ module AcceptanceTests
|
|
4
4
|
module MinitestHelpers
|
5
5
|
include GemHelpers
|
6
6
|
|
7
|
-
def minitest_test_case_superclass
|
8
|
-
if minitest_version >= 5
|
9
|
-
'Minitest::Test'
|
10
|
-
else
|
11
|
-
'MiniTest::Unit::TestCase'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
7
|
def minitest_version
|
16
8
|
bundle_version_of('minitest')
|
17
9
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'rails_version_helpers'
|
2
|
+
|
3
|
+
module AcceptanceTests
|
4
|
+
module NUnitHelpers
|
5
|
+
include RailsVersionHelpers
|
6
|
+
|
7
|
+
def n_unit_test_case_superclass
|
8
|
+
case default_test_framework
|
9
|
+
when :test_unit then 'Test::Unit::TestCase'
|
10
|
+
when :minitest_4 then 'MiniTest::Unit::TestCase'
|
11
|
+
else 'Minitest::Test'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_test_framework
|
16
|
+
if rails_version =~ '< 4'
|
17
|
+
:test_unit
|
18
|
+
elsif rails_version =~ '~> 4.0.0'
|
19
|
+
:minitest_4
|
20
|
+
else
|
21
|
+
:minitest
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -2,6 +2,8 @@ require_relative 'file_helpers'
|
|
2
2
|
require_relative 'gem_helpers'
|
3
3
|
require_relative 'minitest_helpers'
|
4
4
|
|
5
|
+
require 'yaml'
|
6
|
+
|
5
7
|
module AcceptanceTests
|
6
8
|
module StepHelpers
|
7
9
|
include FileHelpers
|
@@ -21,23 +23,7 @@ module AcceptanceTests
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def add_shoulda_matchers_to_project(options = {})
|
24
|
-
|
25
|
-
|
26
|
-
if options[:manually]
|
27
|
-
gem_options[:require] = false
|
28
|
-
end
|
29
|
-
|
30
|
-
add_gem 'shoulda-matchers', gem_options
|
31
|
-
|
32
|
-
if options[:manually]
|
33
|
-
if options[:test_frameworks].include?(:rspec)
|
34
|
-
append_to_file spec_helper_file_path, "require 'shoulda/matchers'"
|
35
|
-
end
|
36
|
-
|
37
|
-
if options[:test_frameworks].include?(:n_unit)
|
38
|
-
append_to_file 'test/test_helper.rb', "require 'shoulda/matchers'"
|
39
|
-
end
|
40
|
-
end
|
26
|
+
AddsShouldaMatchersToProject.call(options)
|
41
27
|
end
|
42
28
|
|
43
29
|
def add_minitest_to_project
|
@@ -61,8 +47,8 @@ module AcceptanceTests
|
|
61
47
|
end
|
62
48
|
end
|
63
49
|
|
64
|
-
def
|
65
|
-
contents = yield
|
50
|
+
def write_n_unit_test(path)
|
51
|
+
contents = yield n_unit_test_case_superclass
|
66
52
|
write_file(path, contents)
|
67
53
|
end
|
68
54
|
|
@@ -85,6 +71,14 @@ module AcceptanceTests
|
|
85
71
|
bundle.remove_gem 'turn'
|
86
72
|
bundle.remove_gem 'coffee-rails'
|
87
73
|
bundle.remove_gem 'uglifier'
|
74
|
+
bundle.remove_gem 'debugger'
|
75
|
+
bundle.remove_gem 'byebug'
|
76
|
+
bundle.remove_gem 'web-console'
|
77
|
+
bundle.add_gem 'pg'
|
78
|
+
end
|
79
|
+
|
80
|
+
fs.open('config/database.yml', 'w') do |file|
|
81
|
+
YAML.dump(database.config.to_hash, file)
|
88
82
|
end
|
89
83
|
end
|
90
84
|
|
@@ -19,7 +19,7 @@ module Tests
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
attr_reader :status, :options, :env
|
22
|
+
attr_reader :status, :options, :env
|
23
23
|
attr_accessor :command_prefix, :run_quickly, :run_successfully, :retries,
|
24
24
|
:timeout
|
25
25
|
|
@@ -35,7 +35,7 @@ module Tests
|
|
35
35
|
|
36
36
|
@wrapper = ->(block) { block.call }
|
37
37
|
@command_prefix = ''
|
38
|
-
|
38
|
+
self.directory = Dir.pwd
|
39
39
|
@run_quickly = false
|
40
40
|
@run_successfully = false
|
41
41
|
@retries = 1
|
@@ -47,8 +47,12 @@ module Tests
|
|
47
47
|
@wrapper = block
|
48
48
|
end
|
49
49
|
|
50
|
+
def directory
|
51
|
+
@options[:chdir]
|
52
|
+
end
|
53
|
+
|
50
54
|
def directory=(directory)
|
51
|
-
@
|
55
|
+
@options[:chdir] = directory || Dir.pwd
|
52
56
|
end
|
53
57
|
|
54
58
|
def formatted_command
|
@@ -60,9 +64,7 @@ module Tests
|
|
60
64
|
def call
|
61
65
|
possibly_retrying do
|
62
66
|
possibly_running_quickly do
|
63
|
-
|
64
|
-
wrapper.call(-> { run })
|
65
|
-
debug { "\n" + divider('START') + output + divider('END') }
|
67
|
+
run_with_debugging
|
66
68
|
|
67
69
|
if run_successfully && !success?
|
68
70
|
fail!
|
@@ -108,7 +110,7 @@ module Tests
|
|
108
110
|
|
109
111
|
def fail!
|
110
112
|
raise <<-MESSAGE
|
111
|
-
Command #{
|
113
|
+
Command #{formatted_command.inspect} exited with status #{exit_status}.
|
112
114
|
Output:
|
113
115
|
#{divider('START') + output + divider('END')}
|
114
116
|
MESSAGE
|
@@ -142,14 +144,24 @@ Output:
|
|
142
144
|
end
|
143
145
|
|
144
146
|
def run
|
145
|
-
|
146
|
-
|
147
|
-
Process.waitpid(pid)
|
148
|
-
end
|
149
|
-
|
147
|
+
pid = spawn(env, *command, options)
|
148
|
+
Process.waitpid(pid)
|
150
149
|
@status = $?
|
151
150
|
end
|
152
151
|
|
152
|
+
def run_with_wrapper
|
153
|
+
wrapper.call(method(:run))
|
154
|
+
end
|
155
|
+
|
156
|
+
def run_with_debugging
|
157
|
+
debug { "\n\e[33mChanging to directory:\e[0m #{directory}" }
|
158
|
+
debug { "\e[32mRunning command:\e[0m #{formatted_command}" }
|
159
|
+
|
160
|
+
run_with_wrapper
|
161
|
+
|
162
|
+
debug { "\n" + divider('START') + output + divider('END') }
|
163
|
+
end
|
164
|
+
|
153
165
|
def possibly_running_quickly(&block)
|
154
166
|
if run_quickly
|
155
167
|
begin
|
@@ -160,7 +172,7 @@ Output:
|
|
160
172
|
message =
|
161
173
|
"Command timed out after #{timeout} seconds: #{formatted_command}\n" +
|
162
174
|
"Output:\n" +
|
163
|
-
|
175
|
+
output
|
164
176
|
|
165
177
|
raise TimeoutError, message
|
166
178
|
end
|