【发布时间】:2015-10-28 04:37:37
【问题描述】:
好吧,我有点不好意思昨天问了very similar question,但我们又卡住了。
我们已经修复了所有控制器测试,并开始编写集成测试。我们在所有的集成测试中都遇到了错误,即使是著名的 assert = true:
site_layout_test.rb
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
test "the truth" do
assert true
end
#commenting out our real tests for debugging
=begin
test "top navigation bar links" do
get 'beta/index'
assert_template 'beta/index'
assert_select "a[href=?]", home_path
assert_select "a[href=?]", how_it_works_path
to do add map, community, sign up, login paths
to do: add paths to links on dropdown if user is logged in
end
=end
end
终端测试结果
12:31:32 - INFO - Running: test/integration/site_layout_test.rb
Started with run options --seed 27747
ERROR["test_the_truth", SiteLayoutTest, 2015-10-25 11:36:28 +0800]
test_the_truth#SiteLayoutTest (1445744188.33s)
NoMethodError: NoMethodError: undefined method `env' for nil:NilClass
1/1: [===================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.05380s
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/reporters"
Minitest::Reporters.use!
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
include Devise::TestHelpers
# Add more helper methods to be used by all tests here...
#
def setup_variables
@base_title = "TripHappy"
end
end
不幸的是,该错误消息几乎没有给我们提供关于错误发生位置的线索。我尝试阅读 Minitests,但不知道在哪里看我相当迷茫。
谢谢你!
作为参考,我们关注 M. Harti's Rails Tutorial,这意味着我们正在使用 Guard 和 Minitest Reporters。我们还有一个通过 Devise 的登录系统,如果这会影响任何事情的话。
解决方案:
这是设计的问题。我在class ActiveSupport::TestCase 中包含了include Devise::TestHelpers 而不是class ActionController::TestCase。
【问题讨论】:
-
我非常不喜欢一连串的问题,尤其是在几乎相同的主题上。如果没有人为您提供答案,它们显示的进展很小。
-
请考虑发布您的解决方案作为答案并接受它们,而不是将它们编辑到问题中。
标签: ruby-on-rails ruby-on-rails-4 testing integration-testing minitest