包含时缺少方法需要'test_helper'

问题描述 投票:0回答:1

我正在尝试使用minitest测试,但在运行此文件时

bin / rails test test / controllers / api / v1 / blogs_api_controller_test.rb

但它给出了这个错误

.rvm / gems / ruby​​-2.3.1 / gems / railties-5.1.1 / lib / rails / railtie / configuration.rb:95:in method_missing': undefined methodweb_console'for

(NoMethodError) Did you mean? console

require 'test_helper'

class BlogsApiControllerTest < ActiveSupport::TestCase
  test 'Get all Blogs' do
    assert false
  end
end

Rails版本5.1.1 Ruby 2.3.1

宝石文件

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.1'
# Use Puma as the app server
gem 'puma', '~> 3.8.2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 3.2.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails', '~> 4.1.1'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.6'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'

gem 'kaminari', '~> 0.17.0'
gem 'bootsy', '~> 2.4'
gem 'searchkick', '~> 3.0.2'
gem 'devise', '~> 4.3.0'
gem 'omniauth-facebook', '~> 3.0.0'
gem 'omniauth-google-oauth2', '~> 0.4.1'

gem 'cancancan', '~> 1.15.0'
gem 'paperclip', '~> 5.0.0'
gem 'sitemap_generator', '~> 5.1.0'
gem 'jwt'
gem 'simple_command'

gem 'rack-cors', require: 'rack/cors'

# For admin panel ----------------
gem 'activeadmin', '~> 1.0.0'
# Below are for rails 5
# gem 'inherited_resources', github: 'activeadmin/inherited_resources'
# gem 'ransack',             github: 'activerecord-hackery/ransack'
gem 'draper',              '~> 3.0.1'
# ---------------------

group :development, :test do
  gem 'pry'

  # Use mysql as the database for Active Record
  gem 'mysql2', '~> 0.4.6'
end

group :development do
  gem 'wdm', '>= 0.1.0' if Gem.win_platform?
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console'
  gem 'listen', '~> 3.0.8'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.1'
end

group :production do
  gem 'pg', '~> 0.18.4'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
ruby-on-rails ruby testing minitest
1个回答
0
投票

请将gem 'web-console'放入Gemfile的测试部分。您可以更改以下行

group :development, :test do
  gem 'pry'

  # Use mysql as the database for Active Record
  gem 'mysql2', '~> 0.4.6'
end

以下

group :development, :test do
  gem 'pry'
  gem 'web-console'
  # Use mysql as the database for Active Record
  gem 'mysql2', '~> 0.4.6'
end

并从以下行中删除web-console

group :development do
  gem 'wdm', '>= 0.1.0' if Gem.win_platform?
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console' # remove this

现在运行以下命令来更新bundle

bundle install
© www.soinside.com 2019 - 2024. All rights reserved.