rspec / rspec-rails

RSpec for Rails 6+
https://rspec.info
MIT License
5.16k stars 1.03k forks source link

Could not find generator rspec:install - Rails 3.2 #2465

Closed drd-2rcl closed 3 years ago

drd-2rcl commented 3 years ago

What Ruby, Rails and RSpec versions are you using?

Ruby version: 2.3.3p222 Rails version: 3.2.22.4 RSpec version: 3.9

Bundler version: 1.17.3

Observed behaviour

When I run: rails generate rspec:install I receive: Could not find generator rspec:install.

If I try to add the gem 'rspec' together with 'rspec-rails' I start to get another error:

.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.9.3/lib/rspec/core/dsl.rb:83:in `remove_method': method `describe' not defined in #<Class:#<Object:0x007f8b680c6660>> (NameError)

After that I uninstalled both gems and installed only rspec-rails and the error remains. After much research I have not found new ways to try to solve this. We are trying to migrate from the mini-test to rspec. Any suggestions would help a lot

drd-2rcl commented 3 years ago

why did it close? @JonRowe

JonRowe commented 3 years ago

:wave: We try to keep our Github issues for bug reports rather than questions, and Rails 3.2 is very old, so we no longer support it, all of these together are why I've closed this issue. I'm happy to help here further however.

You probably need to ensure that rspec-rails is in both the dev and test groups for bundler, so that Rails can see it, the error you are seeing is because RSpec by default does not monkey patch the top level anymore, if you use RSpec.describe instead that error should go away.

drd-2rcl commented 3 years ago

Understood, sorry!

Yes, rspec-rails is part of the test and development group. Is it necessary to keep rspec within the group or isrspec-rails enough? Where exactly can I put RSpec.describe?

JonRowe commented 3 years ago

Can you throw your Gemfile up somewhere? Having rspec in the group should not change anything as it is a dependency of rspec-rails

drd-2rcl commented 3 years ago

Hi @JonRowe, sorry for the delay, I thought i had solved the error, but it reappeared, follow my Gemfile:

source 'https://rubygems.org'

gem 'rails', '~> 3.2.20'
gem 'makara', '~> 0.4.1'

gem 'erubi', '~> 1.8'
gem 'u-case', '~> 1.0.0', require: 'u-case/with_validation'
gem 'u-attributes', '~> 1.2.0'
gem 'u-authorization', '~> 2.3.0'
gem 'type_validator', '~> 1.0.0'

gem 'rake', '=13.0.0'
gem 'rack-cors', :require => 'rack/cors'
gem 'puma'
gem 'unicorn'
gem 'mysql2', '= 0.3.18'
gem 'coffee-script'
gem 'haml'
gem 'haml-rails', '0.3.5'
gem 'i18n', '0.6.4'
gem 'rails-i18n'
gem 'date_validator'
gem 'default_value_for', '3.0.0'
gem 'http_accept_language'
gem 'acts_as_flags'
gem 'acts_as_status'
gem 'prawn'
gem 'prawn-table'
gem 'prawn_rails'
gem 'nokogiri', '1.5.9'
gem 'rubyzip'
gem 'rabl'
gem 'money'
gem 'base32-crockford'
gem 'activemerchant'
gem 'paperclip', '~> 4.2'
gem 'aws-sdk', '< 2.0'
#gem 'ordered-active-record'

gem 'foreman'
gem 'cancan'
gem 'closure_tree'
gem 'nested_form'
gem 'liquid'
gem 'multi_json', '1.7.3'
gem 'savon', '~> 2.3.0'
# gem install libv8 -v '3.16.14.11' -- --with-system-v8
gem 'libv8'
gem 'mixpanel-ruby'
gem 'barby'
gem 'paper_trail', '~> 3.0.2'
gem 'redis-mutex'
gem 'redis-rails'
gem 'holidays', '~> 2.2.0'
gem 'kaminari'
gem 'posix-spawn'
gem 'spreadsheet', require: false
gem 'simple_form'
gem 'wicked_pdf', '1.1.0'
gem 'wkhtmltopdf-binary-edge', '0.12.4'
# gem 'rqrcode'
gem 'mini_magick'
gem 'rqrcode-rails3'

# global configuration
gem 'global'

# Authentication
gem 'ruby-saml'

# Authorization
gem 'pundit'

# Elasticsearch
gem 'tire'
gem 'elasticsearch', '= 5.0.4'

gem 'sidekiq', '~> 4.2.10'
gem 'sidekiq-pro', :path => 'vendor/gems/sidekiq-pro-3.7.1'
gem 'sidekiq-ent', :path => 'vendor/gems/sidekiq-ent-1.6.1'

gem 'sinatra', :require => nil

# pretty logging
gem 'lograge'
gem 'sidekiq-logstash'

# Errors Monitor
gem 'airbrake', '~> 10'

# Performance Monitor
# gem 'skylight', group: :production
# gem 'sidekiq-skylight', group: :production
gem 'newrelic_rpm'

# Status Monitoring
gem 'dogstatsd-ruby', '~> 4'

# sys
gem 'dotenv-rails'
# gem 'pry-rails'

# ONLY ON DEVELOPMENT BRANCH - DO NOT DEPLOY TO PRODUCTION AS THIS
# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sqlite3'
  gem 'sass', '3.2.9'
  gem 'sass-rails', '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  gem 'compass', ">= 0.12.2"
  gem 'compass-rails'
end

gem 'uglifier', '>= 1.0.3'
gem 'closure-compiler'
gem 'jquery-rails'

gem 'rack-cas'

gem 'nfe-paulistana', '= 1.0.3'

group :test, :development do
  gem 'therubyracer', '0.12.2'
  gem 'pry'
  gem 'pry-byebug'
  gem 'pry-rails'
  # gem 'test-unit-minitest'
  gem 'test-unit', '~> 3.0'
  gem 'minitest'
  gem 'minitest-hooks'
  gem 'minitest-reporters'
  gem 'minispec-metadata'
  gem 'capybara'
  gem 'shoulda-matchers'
  gem 'database_cleaner', '= 1.7.0'
  gem 'simplecov'
  gem 'fabrication'
  # gem 'launchy'
  # gem 'bourne', '1.3.0'
  gem 'mocha', '~> 1.8.0', :require => false
  gem 'faker'
  gem 'meta_request'
  gem 'parallel_tests'
  gem 'mock_redis'
  gem 'fakeweb'
  gem 'get_process_mem'
  gem 'rack-mini-profiler'
  gem 'rspec'
  gem 'rspec-rails'
end

group :profile do
  gem 'ruby-prof'
  gem 'fabrication'
  gem 'mock_redis'
end

group :development do
  gem 'rubocop', require: false
end

gem 'codeclimate-test-reporter', group: :test, require: nil

group :test do
  gem 'timecop'
  gem 'm'
  gem 'vcr', '3.0'
  gem 'webmock'
end

group :production do
  gem 'rails_12factor'
end

gem 'activerecord-import'
gem 'charlock_holmes'
gem 'activeuuid', '=0.6.1'
gem 'bcrypt'
gem 'jwt'
gem 'ddtrace'
gem 'correios-cep'
pirj commented 3 years ago

Could you please constrain your versions of rspec and rspec-rails to ~> 3.5.0, run bundle update --conservative rspec rspec-rails and re-check?

I'm not seeing your Gemfile.lock but can guess you're still using the latest released version of rspec-rails, and chances are it doesn't work with Rails 3.2 anymore.

drd-2rcl commented 3 years ago

Sure, I restricted it to 3.5.0 and I run bundle update:

Screen Shot 2021-02-23 at 14 11 06

but now I have error in another moment when I run: RAILS_ENV=test rails runner puts 1

Screen Shot 2021-02-23 at 15 14 00

pirj commented 3 years ago

You seem to have globally-exposed DSL disabled.

It's hard to tell what is going on exactly, and why it attempts a method that doesn't exist when e have a check if it's defined https://github.com/rspec/rspec-core/blob/6263a6d4bf66c56efc218ac479273536f5c59410/lib/rspec/core/dsl.rb#L83:

remove_method(method_name) if method_defined?(method_name)

I guess, debugging will help.

JonRowe commented 3 years ago

You didn't need to regress your gems here, rspec-rails 3.9.x supports Rails 3.2, and supports RSpec 3.9.x. Thats all fine.

What this looks like is an artefact of trying to get an existing previous minitest setup working work RSpec, the two are not directly compatible, even though we make efforts to make parts of minitest available.

The error is weird as its happening during our setup phase, somehow it looks like we think describe is exposed but it isn't. Which is very weird, like minitest has defined it elsewhere.

Can you open source a setup that causes this error? Maybe just copy the gemfile and some config into a new app and see if you can reproduce this? Otherwise my suggestion here is to comment out parts of your gemfile until you can run the generator.

drd-2rcl commented 3 years ago

Hi @pirj and @JonRowe, I would like to thank you for your help and attention. In the end what was missing was to add rspec inside application.rb. This solved the problem. =)

pirj commented 3 years ago

I'm not sure how it solves the problem, and a bit worried about side effects of such a change on non-test envs, but happy it all worked for you! You're always welcome.