Fix the undefined method error for non rails project due to use of many? method. (#1459)

* Fix the undefined method error for non rails project due to use of many? method

* Add tests for inclusion validation for non rails app.

* Remove unnecessary spaces.

* Rubocop offenses.

Co-authored-by: Nitin S <nitin.singh@edcast.com>
Co-authored-by: = <=>
This commit is contained in:
Nitin Singh 2021-09-01 04:34:37 +05:30 committed by GitHub
parent c934d75345
commit 3e9d69ba7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 8 deletions

View File

@ -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}"

View File

@ -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