好吧,有點尷尬昨天我問了一個very similar question,但我們又被卡住了。Rails 4集成測試 - 失敗(事件斷言爲真)
我們修復了所有的控制器測試,並開始編寫集成測試。我們對我們所有的集成測試遇到錯誤,甚至著名的斷言=真:
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記者。如果這影響了任何事情,我們也通過Devise擁有一個登錄系統。
解決方案:
正是有了設計的問題。我在class ActiveSupport::TestCase
中包含include Devise::TestHelpers
而不是class ActionController::TestCase
。
我有強烈的不喜歡鏈問題,特別是在幾乎相同的主題。如果沒有人給你答案,他們顯示的進展很小。 – sevenseacat
請考慮發佈您的解決方案作爲答案並接受它們,而不是將它們編輯到問題中。 –