thoughtbot / shoulda

Makes tests easy on the fingers and the eyes

Home Page:http://www.thoughtbot.com/community

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not worked with rails 5.0.1 old project?

zw963 opened this issue · comments

 ╰─ $ cat Gemfile.lock |grep shoulda
    shoulda (2.11.3)
    shoulda-matchers (3.1.2)
  shoulda
  shoulda-matchers
  gem 'shoulda'
  gem 'shoulda-matchers'

When add model should spec, got following error:

 ╰─ $ rails test
/home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require': cannot load such file -- test/unit (LoadError)
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/shoulda-2.11.3/lib/shoulda/integrations/test_unit.rb:1:in `<top (required)>'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/shoulda-2.11.3/lib/shoulda.rb:8:in `<top (required)>'
	from /home/zw963/.rvm/gems/ruby-2.3.4@global/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `require'
	from /home/zw963/.rvm/gems/ruby-2.3.4@global/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
	from /home/zw963/.rvm/gems/ruby-2.3.4@global/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `each'
	from /home/zw963/.rvm/gems/ruby-2.3.4@global/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `block in require'
	from /home/zw963/.rvm/gems/ruby-2.3.4@global/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `each'
	from /home/zw963/.rvm/gems/ruby-2.3.4@global/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `require'
	from /home/zw963/.rvm/gems/ruby-2.3.4@global/gems/bundler-1.16.1/lib/bundler.rb:114:in `require'
	from /home/zw963/IKCRM/ik_kefu/config/application.rb:6:in `<top (required)>'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/spring-2.0.1/lib/spring/application.rb:82:in `require'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/spring-2.0.1/lib/spring/application.rb:82:in `preload'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/spring-2.0.1/lib/spring/application.rb:143:in `serve'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/spring-2.0.1/lib/spring/application.rb:131:in `block in run'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/spring-2.0.1/lib/spring/application.rb:125:in `loop'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/spring-2.0.1/lib/spring/application.rb:125:in `run'
	from /home/zw963/.rvm/gems/ruby-2.3.4@ik_kefu/gems/spring-2.0.1/lib/spring/application/boot.rb:19:in `<top (required)>'
	from /home/zw963/.rvm/rubies/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /home/zw963/.rvm/rubies/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from -e:1:in `<main>'

Rails version: 5.0.6

broken test is here:

require 'test_helper'

class RenewalRateMonthlyReportTest < ActiveSupport::TestCase
  should belong_to :reportable
end

test_helper is here:

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  # fixtures :all

  # Add more helper methods to be used by all tests here...

  include FactoryBot::Syntax::Methods
  include Devise::Test::IntegrationHelpers
end

Hey, I'm so so sorry for the late update on this. I just released shoulda 4.0.0.rc1. Can you try it out and see if it works for you?

Sorry, old project not support ruby 2.4.0, can't test on it.

Fetching shoulda-context 2.0.0.rc2
Installing shoulda-context 2.0.0.rc2
Fetching shoulda-matchers 4.1.2
Installing shoulda-matchers 4.1.2
Gem::InstallError: shoulda-matchers requires Ruby version >= 2.4.0.
An error occurred while installing shoulda-matchers (4.1.2), and Bundler cannot continue.
Make sure that gem install shoulda-matchers -v '4.1.2' succeeds before bundling.

Ah I see. Yes, Ruby 2.3.x was end-of-lifed earlier this year, so you might want to see if you can upgrade: https://www.ruby-lang.org/en/news/2018/10/17/ruby-2-3-8-released/. Sorry about that.

I just released Shoulda 4.0.0. This upgrades the dependency on shoulda-context to 2.0.0 as well as shoulda-matchers to ~> 4.0, both of which add proper support for Rails 5 and 6. Closing this now, but if you see any more issues don't hesitate to file them!