diff --git a/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb index 3d0efdc6..a9cb32fd 100644 --- a/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +++ b/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb @@ -355,7 +355,7 @@ EOT description = "validate that :#{@attribute}" description << - if @array.many? + if @array.count > 1 " is either #{inspected_array}" else " is #{inspected_array}" diff --git a/spec/acceptance/active_model_integration_spec.rb b/spec/acceptance/active_model_integration_spec.rb index e55fab5c..ea6438a6 100644 --- a/spec/acceptance/active_model_integration_spec.rb +++ b/spec/acceptance/active_model_integration_spec.rb @@ -1,13 +1,34 @@ require 'acceptance_spec_helper' describe 'shoulda-matchers integrates with an ActiveModel project' do - specify 'and loads without errors' do + before do create_active_model_project - add_shoulda_matchers_to_project( - test_frameworks: [:rspec], - libraries: [:active_model], - ) + write_file 'lib/user.rb', <<-FILE + require 'active_model' + + class User + include ActiveModel::Validations + attr_accessor :gender + + validates :gender, inclusion: { in: %w(male female) } + end + FILE + + write_file 'spec/user_spec.rb', <<-FILE + require 'spec_helper' + require 'user' + include Shoulda::Matchers::ActiveModel + + describe User do + context 'when gender is valid' do + it { is_expected.to validate_inclusion_of(:gender).in_array(%w(male female)) } + end + context 'when gender is invalid' do + it { is_expected.to validate_inclusion_of(:gender).in_array(%w(transgender female)) } + end + end + FILE write_file 'load_dependencies.rb', <<-FILE require 'active_model' @@ -17,7 +38,42 @@ describe 'shoulda-matchers integrates with an ActiveModel project' do puts "Loaded all dependencies without errors" FILE - result = run_command_within_bundle('ruby load_dependencies.rb') - expect(result).to have_output('Loaded all dependencies without errors') + updating_bundle do + add_rspec_to_project + add_shoulda_matchers_to_project( + manually: true, + with_configuration: false, + ) + + write_file 'spec/spec_helper.rb', <<-FILE + require 'active_model' + require 'shoulda-matchers' + + Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + + with.library :active_model + end + end + FILE + end + end + + context 'when using active model library' do + it 'and loads without errors' do + result = run_command_within_bundle('ruby load_dependencies.rb') + + expect(result).to have_output('Loaded all dependencies without errors') + end + + it 'allows use of inclusion matcher from active model library' do + result = run_rspec_tests('spec/user_spec.rb') + + expect(result).to have_output('2 examples, 1 failure') + expect(result).to have_output( + 'gender: ["is not included in the list"]', + ) + end end end