【问题标题】:Missing Method when include require 'test_helper'包含需要'test_helper'时缺少方法
【发布时间】:2019-03-06 05:45:02
【问题描述】:

我正在尝试使用 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' 用于

(NoMethodError) 你的意思是?控制台

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]

【问题讨论】:

  • 你确定不是console?从readme 看来是这样。不过不确定这将如何在测试中发挥作用。

标签: ruby-on-rails ruby testing minitest


【解决方案1】:

请将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 install

【讨论】:

  • 我这样做了,但我收到了这条消息Web Console is activated in the test environment. This is usually a mistake. To ensure it's only activated in development mode, move it to the development group of your Gemfile: gem 'web-console', group: :development If you still want to run it in the test environment (and know what you are doing), put this in your Rails application configuration: config.web_console.development_only = false
猜你喜欢
  • 1970-01-01
  • 2018-08-09
  • 2015-10-09
  • 2015-06-12
  • 2015-02-06
  • 2016-09-08
  • 1970-01-01
  • 1970-01-01
  • 2017-01-16
相关资源
最近更新 更多