IntegrationTest 从配置中引发错误?
IntegrationTest raises errors from configuration?
我在测试我的 Rails 应用程序时遇到了一些问题。
我有以下简单的文件来测试控制器(依赖于http://guides.rubyonrails.org/testing.html):
require "./test/test_helper"
class GraphControllerTest < ActionDispatch::IntegrationTest
setup do
@instance = Instance.where(client_id: 2).first
end
test "should_create" do
assert_difference('Graph.count') do
post v2_instance_graphs_url(instance_id: @instance.client_id), {'name': "test of test", 'instance_id': @instance.client_id}.to_json, {'Authorization': 'Token token=blabla', 'Content-Type': 'application/json'}
end
assert_equal JSON.parse(@response.body)["name"], "test of test"
end
end
test_helper.rb 是:
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.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
end
我在控制台中 运行:
bin/rake test test/controllers/knowledge_graph_controller_test.rb
这应该只触发上面的两个断言。但是,我得到了上面的两个断言和 8 个错误。
错误如下:
1) Error:
ActiveSupport::TestCase#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
2) Error:
ActionController::TestCase#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
3) Error:
Minitest::Test#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
4) Error:
GraphControllerTest#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
5) Error:
ActionDispatch::IntegrationTest#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
6) Error:
Minitest::Unit::TestCase#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
7) Error:
Rails::Generators::TestCase#test_app:
RuntimeError: You need to configure your Rails::Generators::TestCase destination root.
8) Error:
Rails::Generators::TestCase#test_app=:
RuntimeError: You need to configure your Rails::Generators::TestCase destination root.
我无法解释。我什至不明白它们来自什么文件。
我正在使用 Rails 4.2.7.1
非常感谢您的帮助!
问题是另一个文件中的 "include ActionDispatch"。
我在测试我的 Rails 应用程序时遇到了一些问题。
我有以下简单的文件来测试控制器(依赖于http://guides.rubyonrails.org/testing.html):
require "./test/test_helper"
class GraphControllerTest < ActionDispatch::IntegrationTest
setup do
@instance = Instance.where(client_id: 2).first
end
test "should_create" do
assert_difference('Graph.count') do
post v2_instance_graphs_url(instance_id: @instance.client_id), {'name': "test of test", 'instance_id': @instance.client_id}.to_json, {'Authorization': 'Token token=blabla', 'Content-Type': 'application/json'}
end
assert_equal JSON.parse(@response.body)["name"], "test of test"
end
end
test_helper.rb 是:
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.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
end
我在控制台中 运行:
bin/rake test test/controllers/knowledge_graph_controller_test.rb
这应该只触发上面的两个断言。但是,我得到了上面的两个断言和 8 个错误。
错误如下:
1) Error:
ActiveSupport::TestCase#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
2) Error:
ActionController::TestCase#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
3) Error:
Minitest::Test#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
4) Error:
GraphControllerTest#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
5) Error:
ActionDispatch::IntegrationTest#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
6) Error:
Minitest::Unit::TestCase#test_app=:
ArgumentError: wrong number of arguments (given 0, expected 1)
7) Error:
Rails::Generators::TestCase#test_app:
RuntimeError: You need to configure your Rails::Generators::TestCase destination root.
8) Error:
Rails::Generators::TestCase#test_app=:
RuntimeError: You need to configure your Rails::Generators::TestCase destination root.
我无法解释。我什至不明白它们来自什么文件。
我正在使用 Rails 4.2.7.1
非常感谢您的帮助!
问题是另一个文件中的 "include ActionDispatch"。