我为一个现有的项目更新了我的Ruby2.4到2.7,现在rspec对每一个规范都会给出这个错误。我找不到错误的来源。我的项目中没有BigDecimal。测试不是我写的。如何找到导致问题的gem?
An error occurred while loading ./spec/views/terms_users/new.html.erb_spec.rb.
Failure/Error: require File.expand_path('../../config/environment', __FILE__)
NoMethodError:
undefined method `new' for BigDecimal:Class
# ./config/application.rb:17:in `<top (required)>'
# ./config/environment.rb:2:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/views/terms_users/new.html.erb_spec.rb:1:in `<top (required)>'
C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:271: warning: already initialized constant Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher::ARBITRARY_OUTSIDE_STRING
C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:271: warning: previous definition of ARBITRARY_OUTSIDE_STRING was here
C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:272: warning: already initialized constant Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher::ARBITRARY_OUTSIDE_FIXNUM
C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:272: warning: previous definition of ARBITRARY_OUTSIDE_FIXNUM was here这是application.rb:17
Bundler.require(*Rails.groups)这是我的:test Gemfile
ruby '~>2.7.0'
gem 'rails', '~> 5.0.2'
group :test do
# Acceptance test framework for web applications
gem 'capybara'
# Strategies for cleaning databases
gem 'database_cleaner'#, '~> 1.6.1.0'
# Factories
gem 'fabrication'#, '~> 2.16.1'
# Tool for writing automated tests of websites
gem 'selenium-webdriver'#, '~> 3.4'
# Code coverage
gem 'simplecov', require: false
# One-liners that test common Rails functionality
gem 'shoulda-matchers', git: 'https://github.com/thoughtbot/shoulda-matchers.git', branch: 'rails-5'
# Stubbing and setting expectations on HTTP requests
gem 'webmock', require: false
end
group :development, :test do
# Annotate Rails classes with schema and routes info
gem 'annotate', '~> 2.7'
# Call 'byebug' anywhere to stop execution and get a debugger console
gem 'byebug' #, platform: :mri
# Load environment variables from `.env`
gem 'dotenv-rails', '~> 2.2'
# `rails c` alternative and runtime developer console
gem 'pry-rails', '~> 0.3'
# Launch a pry session when a test fails
gem 'pry-rescue'
# Move up and down the stack with pry
gem 'pry-stack_explorer'
# Testing
gem 'rspec-rails'#, '~> 3.5'
# Ruby static code analyzer
gem 'rubocop', '~> 0.49.1', require: false
gem 'rubocop-rspec'#, '~> 1.15', require: false
end该应用程序运行、加载和工作。
发布于 2021-09-28 02:49:48
下面是它的跟踪结果:
>set RAILS_ENV=test
>echo %RAILS_ENV%
test
>rails console
Traceback (most recent call last):
58: from bin/rails:9:in `<main>'
57: from C:/ruby27/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
...
1: from C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:270:in `<module:ActiveModel>'
C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:273:in `<class:ValidateInclusionOfMatcher>': undefined method `new' for BigDecimal:Class (NoMethodError)这就解决了这个问题:
`Gemfile`
gem 'shoulda-matchers'#, git: 'https://github.com/thoughtbot/shoulda-matchers.git', branch: 'rails-5'
> bundle update
Installing shoulda-matchers 4.5.1 (was 3.1.2)
> rails console
[1] pry(main)>https://stackoverflow.com/questions/69355164
复制相似问题