shoulda-matchers 3.0.0.rc1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -3
- data/Gemfile.lock +12 -41
- data/NEWS.md +118 -26
- data/README.md +34 -11
- data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -0
- data/doc_config/yard/templates/default/fulldoc/html/css/style.css +4 -0
- data/gemfiles/4.0.0.gemfile +2 -3
- data/gemfiles/4.0.0.gemfile.lock +47 -77
- data/gemfiles/4.0.1.gemfile +2 -3
- data/gemfiles/4.0.1.gemfile.lock +51 -79
- data/gemfiles/4.1.gemfile +2 -3
- data/gemfiles/4.1.gemfile.lock +73 -103
- data/gemfiles/4.2.gemfile +2 -3
- data/gemfiles/4.2.gemfile.lock +90 -124
- data/lib/shoulda/matchers.rb +1 -0
- data/lib/shoulda/matchers/action_controller/callback_matcher.rb +6 -8
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +1 -3
- data/lib/shoulda/matchers/action_controller/flash_store.rb +1 -8
- data/lib/shoulda/matchers/action_controller/permit_matcher.rb +140 -88
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +2 -5
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +5 -10
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +2 -4
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -3
- data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +3 -5
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -7
- data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +35 -9
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_model.rb +57 -1
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +2 -5
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +162 -54
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +5 -2
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +1 -3
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +24 -11
- data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +0 -2
- data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +4 -3
- data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +2 -1
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +15 -13
- data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +8 -8
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +8 -8
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +12 -14
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +10 -4
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +0 -3
- data/lib/shoulda/matchers/active_model/validator.rb +0 -8
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +4 -6
- data/lib/shoulda/matchers/active_record/association_matcher.rb +58 -43
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +2 -2
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +3 -5
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +3 -5
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +1 -4
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +3 -5
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +7 -7
- data/lib/shoulda/matchers/doublespeak/double.rb +10 -1
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +13 -5
- data/lib/shoulda/matchers/doublespeak/method_call.rb +10 -1
- data/lib/shoulda/matchers/doublespeak/object_double.rb +2 -1
- data/lib/shoulda/matchers/doublespeak/world.rb +10 -0
- data/lib/shoulda/matchers/error.rb +4 -0
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +11 -10
- data/lib/shoulda/matchers/integrations/libraries.rb +1 -0
- data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/active_model.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/active_record.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -1
- data/lib/shoulda/matchers/integrations/libraries/routing.rb +27 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +2 -2
- data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
- data/lib/shoulda/matchers/routing.rb +10 -0
- data/lib/shoulda/matchers/version.rb +1 -1
- data/script/SUPPORTED_VERSIONS +1 -1
- data/spec/acceptance/independent_matchers_spec.rb +103 -42
- data/spec/doublespeak_spec_helper.rb +5 -1
- data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +34 -11
- data/spec/support/acceptance/helpers/rspec_helpers.rb +9 -13
- data/spec/support/acceptance/helpers/step_helpers.rb +13 -0
- data/spec/support/acceptance/matchers/have_output.rb +1 -1
- data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +1 -1
- data/spec/support/tests/command_runner.rb +5 -1
- data/spec/support/unit/helpers/active_record_versions.rb +0 -4
- data/spec/support/unit/shared_examples/set_session_or_flash.rb +8 -3
- data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +198 -39
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +269 -102
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +24 -0
- data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +118 -101
- data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -82
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +148 -121
- data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +20 -8
- data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +64 -183
- data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +14 -0
- data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +60 -0
- data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +23 -7
- data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +242 -0
- data/spec/unit_spec_helper.rb +4 -0
- data/tasks/documentation.rb +35 -0
- metadata +9 -8
- data/Guardfile +0 -5
- data/cucumber.yml +0 -1
- data/lib/shoulda/matchers/active_model/validator_with_captured_range_error.rb +0 -12
@@ -0,0 +1,27 @@
|
|
1
|
+
module Shoulda
|
2
|
+
module Matchers
|
3
|
+
module Integrations
|
4
|
+
module Libraries
|
5
|
+
# @private
|
6
|
+
class Routing
|
7
|
+
Integrations.register_library(self, :routing)
|
8
|
+
|
9
|
+
include Integrations::Inclusion
|
10
|
+
include Integrations::Rails
|
11
|
+
|
12
|
+
def integrate_with(test_framework)
|
13
|
+
test_framework.include(matchers_module, type: :routing)
|
14
|
+
|
15
|
+
include_into(::ActionController::TestCase, matchers_module)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def matchers_module
|
21
|
+
Shoulda::Matchers::Routing
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/script/SUPPORTED_VERSIONS
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0 2.1.
|
1
|
+
2.0.0 2.1.6 2.2.3
|
@@ -1,64 +1,125 @@
|
|
1
1
|
require 'acceptance_spec_helper'
|
2
2
|
|
3
|
-
describe 'shoulda-matchers has independent matchers' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
describe 'shoulda-matchers has independent matchers, specifically delegate_method' do
|
4
|
+
specify 'and integrates with a Ruby application that uses the default test framework' do
|
5
|
+
create_generic_bundler_project
|
6
|
+
|
7
|
+
updating_bundle do
|
8
|
+
add_minitest_to_project
|
9
|
+
add_shoulda_context_to_project(manually: true)
|
10
|
+
add_shoulda_matchers_to_project(
|
11
|
+
test_frameworks: [default_test_framework],
|
12
|
+
manually: true
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
write_file 'lib/post_office.rb', <<-FILE
|
17
|
+
class PostOffice
|
15
18
|
end
|
19
|
+
FILE
|
20
|
+
|
21
|
+
write_file 'lib/courier.rb', <<-FILE
|
22
|
+
require 'forwardable'
|
16
23
|
|
17
|
-
|
18
|
-
|
24
|
+
class Courier
|
25
|
+
extend Forwardable
|
26
|
+
|
27
|
+
def_delegators :post_office, :deliver
|
28
|
+
|
29
|
+
attr_reader :post_office
|
30
|
+
|
31
|
+
def initialize(post_office)
|
32
|
+
@post_office = post_office
|
33
|
+
end
|
34
|
+
end
|
35
|
+
FILE
|
36
|
+
|
37
|
+
write_n_unit_test 'test/courier_test.rb' do |test_case_superclass|
|
38
|
+
<<-FILE
|
39
|
+
require 'test_helper'
|
40
|
+
require 'courier'
|
41
|
+
require 'post_office'
|
42
|
+
|
43
|
+
class CourierTest < #{test_case_superclass}
|
44
|
+
subject { Courier.new(post_office) }
|
45
|
+
|
46
|
+
should delegate_method(:deliver).to(:post_office)
|
47
|
+
|
48
|
+
def post_office
|
49
|
+
PostOffice.new
|
50
|
+
end
|
19
51
|
end
|
20
52
|
FILE
|
53
|
+
end
|
21
54
|
|
22
|
-
|
23
|
-
require 'forwardable'
|
55
|
+
result = run_n_unit_tests('test/courier_test.rb')
|
24
56
|
|
25
|
-
|
26
|
-
|
57
|
+
expect(result).to indicate_number_of_tests_was_run(1)
|
58
|
+
expect(result).to have_output(
|
59
|
+
'Courier should delegate #deliver to #post_office object'
|
60
|
+
)
|
61
|
+
end
|
27
62
|
|
28
|
-
|
63
|
+
specify 'and integrates with a Ruby application that uses RSpec' do
|
64
|
+
create_generic_bundler_project
|
29
65
|
|
30
|
-
|
66
|
+
updating_bundle do
|
67
|
+
add_rspec_to_project
|
68
|
+
add_shoulda_matchers_to_project(
|
69
|
+
manually: true,
|
70
|
+
with_configuration: false
|
71
|
+
)
|
72
|
+
write_file 'spec/spec_helper.rb', <<-FILE
|
73
|
+
require 'shoulda/matchers/independent'
|
31
74
|
|
32
|
-
|
33
|
-
|
34
|
-
end
|
75
|
+
RSpec.configure do |config|
|
76
|
+
config.include(Shoulda::Matchers::Independent)
|
35
77
|
end
|
36
78
|
FILE
|
79
|
+
end
|
80
|
+
|
81
|
+
write_file 'lib/post_office.rb', <<-FILE
|
82
|
+
class PostOffice
|
83
|
+
end
|
84
|
+
FILE
|
37
85
|
|
38
|
-
|
39
|
-
|
40
|
-
require 'test_helper'
|
41
|
-
require 'courier'
|
42
|
-
require 'post_office'
|
86
|
+
write_file 'lib/courier.rb', <<-FILE
|
87
|
+
require 'forwardable'
|
43
88
|
|
44
|
-
|
45
|
-
|
89
|
+
class Courier
|
90
|
+
extend Forwardable
|
46
91
|
|
47
|
-
|
92
|
+
def_delegators :post_office, :deliver
|
48
93
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
94
|
+
attr_reader :post_office
|
95
|
+
|
96
|
+
def initialize(post_office)
|
97
|
+
@post_office = post_office
|
98
|
+
end
|
54
99
|
end
|
100
|
+
FILE
|
55
101
|
|
56
|
-
|
102
|
+
write_file 'spec/courier_spec.rb', <<-FILE
|
103
|
+
require 'spec_helper'
|
104
|
+
require 'courier'
|
105
|
+
require 'post_office'
|
57
106
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
107
|
+
describe Courier do
|
108
|
+
subject { Courier.new(post_office) }
|
109
|
+
|
110
|
+
it { should delegate_method(:deliver).to(:post_office) }
|
111
|
+
|
112
|
+
def post_office
|
113
|
+
PostOffice.new
|
114
|
+
end
|
115
|
+
end
|
116
|
+
FILE
|
117
|
+
|
118
|
+
result = run_rspec_tests('spec/courier_spec.rb')
|
119
|
+
|
120
|
+
expect(result).to indicate_number_of_tests_was_run(1)
|
121
|
+
expect(result).to have_output(
|
122
|
+
/Courier\s+should delegate #deliver to #post_office object/
|
123
|
+
)
|
63
124
|
end
|
64
125
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'shoulda
|
1
|
+
require 'shoulda/matchers/doublespeak'
|
2
2
|
|
3
3
|
PROJECT_ROOT = File.expand_path('../..', __FILE__)
|
4
4
|
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
|
@@ -10,5 +10,9 @@ RSpec.configure do |config|
|
|
10
10
|
c.syntax = :expect
|
11
11
|
end
|
12
12
|
|
13
|
+
if config.files_to_run.one?
|
14
|
+
config.default_formatter = 'doc'
|
15
|
+
end
|
16
|
+
|
13
17
|
config.mock_with :rspec
|
14
18
|
end
|
@@ -16,7 +16,10 @@ module AcceptanceTests
|
|
16
16
|
|
17
17
|
def call
|
18
18
|
add_gem 'shoulda-matchers', gem_options
|
19
|
-
|
19
|
+
|
20
|
+
unless options[:with_configuration] === false
|
21
|
+
configure_test_helper_files
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
25
|
protected
|
@@ -48,8 +51,10 @@ module AcceptanceTests
|
|
48
51
|
def each_test_helper_file
|
49
52
|
options[:test_frameworks].each do |test_framework|
|
50
53
|
libraries = options.fetch(:libraries, [])
|
51
|
-
|
52
|
-
|
54
|
+
|
55
|
+
test_helper_files_for(test_framework, libraries).each do |test_helper_file|
|
56
|
+
yield test_helper_file, test_framework, libraries
|
57
|
+
end
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
@@ -85,16 +90,26 @@ module AcceptanceTests
|
|
85
90
|
libraries.map { |library| "with.library :#{library}" }.join("\n")
|
86
91
|
end
|
87
92
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
93
|
+
def test_helper_files_for(test_framework, libraries)
|
94
|
+
files = []
|
95
|
+
|
96
|
+
if integrates_with_nunit_and_rails?(test_framework, libraries) ||
|
97
|
+
integrates_with_nunit_only?(test_framework)
|
98
|
+
files << 'test/test_helper.rb'
|
94
99
|
end
|
100
|
+
|
101
|
+
if integrates_with_rspec?(test_framework)
|
102
|
+
if bundle.includes?('rspec-rails')
|
103
|
+
files << 'spec/rails_helper.rb'
|
104
|
+
else
|
105
|
+
files << 'spec/spec_helper.rb'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
files
|
95
110
|
end
|
96
111
|
|
97
|
-
def
|
112
|
+
def integrates_with_nunit_only?(test_framework)
|
98
113
|
nunit_frameworks = [:test_unit, :minitest, :minitest_4, :minitest_5]
|
99
114
|
nunit_frameworks.include?(test_framework)
|
100
115
|
end
|
@@ -103,8 +118,16 @@ module AcceptanceTests
|
|
103
118
|
test_framework == :rspec
|
104
119
|
end
|
105
120
|
|
106
|
-
def
|
121
|
+
def integrates_with_rspec_rails_3_x?(test_framework, libraries)
|
122
|
+
integrates_with_rails?(libraries) && rspec_rails_version >= 3
|
123
|
+
end
|
124
|
+
|
125
|
+
def integrates_with_nunit_and_rails?(test_framework, libraries)
|
107
126
|
test_framework.nil? && libraries.include?(:rails)
|
108
127
|
end
|
128
|
+
|
129
|
+
def integrates_with_rails?(libraries)
|
130
|
+
libraries.include?(:rails)
|
131
|
+
end
|
109
132
|
end
|
110
133
|
end
|
@@ -4,25 +4,21 @@ module AcceptanceTests
|
|
4
4
|
module RspecHelpers
|
5
5
|
include GemHelpers
|
6
6
|
|
7
|
-
def
|
8
|
-
bundle_version_of('rspec-
|
7
|
+
def rspec_core_version
|
8
|
+
bundle_version_of('rspec-core')
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
write_file path, content
|
11
|
+
def rspec_expectations_version
|
12
|
+
bundle_version_of('rspec-expectations')
|
14
13
|
end
|
15
14
|
|
16
|
-
def
|
17
|
-
|
18
|
-
'rails_helper'
|
19
|
-
else
|
20
|
-
'spec_helper'
|
21
|
-
end
|
15
|
+
def rspec_rails_version
|
16
|
+
bundle_version_of('rspec-rails')
|
22
17
|
end
|
23
18
|
|
24
|
-
def
|
25
|
-
"
|
19
|
+
def add_rspec_file(path, content)
|
20
|
+
content = "require 'rails_helper'\n#{content}"
|
21
|
+
write_file path, content
|
26
22
|
end
|
27
23
|
end
|
28
24
|
end
|
@@ -90,12 +90,25 @@ module AcceptanceTests
|
|
90
90
|
FILE
|
91
91
|
end
|
92
92
|
|
93
|
+
def add_rspec_to_project
|
94
|
+
add_gem 'rspec-core', rspec_core_version
|
95
|
+
add_gem 'rspec-expectations', rspec_expectations_version
|
96
|
+
append_to_file 'spec/spec_helper.rb', <<-FILE
|
97
|
+
require 'rspec/core'
|
98
|
+
require 'rspec/expectations'
|
99
|
+
FILE
|
100
|
+
end
|
101
|
+
|
93
102
|
def add_rspec_rails_to_project!
|
94
103
|
add_gem 'rspec-rails', rspec_rails_version
|
95
104
|
run_command_within_bundle!('rails g rspec:install')
|
96
105
|
remove_from_file '.rspec', '--warnings'
|
97
106
|
end
|
98
107
|
|
108
|
+
def run_rspec_tests(*paths)
|
109
|
+
run_command_within_bundle 'rspec --format documentation --backtrace', *paths
|
110
|
+
end
|
111
|
+
|
99
112
|
def run_rspec_suite
|
100
113
|
run_rake_tasks('spec', env: { SPEC_OPTS: '-fd' })
|
101
114
|
end
|