2011-11-22 86 views
0

我試圖在我的rails3應用程序中實現一些單元測試。以下是我的'test_helper.rb'文件。Rails 3中的單元測試錯誤

ENV["RAILS_ENV"] = "test" 
require File.expand_path('../../config/environment', __FILE__) 
require 'rails/test_help' 

class ActiveSupport::TestCase 
    include Devise::TestHelpers 
    fixtures :all 
end 

關注我的fixture文件(site_layouts.yml

# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 

one: 
    name: layout1 
    content: <html><head></head><body>layout1</body></html> 

two: 
    name: layout2 
    content: <html><head></head><body>layout2</body></html> 

和下面是我的單元測試類

require 'test_helper' 

class SiteLayoutTest < Test::Unit::TestCase 
    fixtures :site_layouts 
    test "show site layout" do 
    layout = site_layouts(:one) 
    end 
end 

,當我嘗試運行rake test:units我發現了以下錯誤

undefined method `fixtures' for SiteLayoutTest:Class (NoMethodError) 

我有點新的測試。我在

  • 的Rails 3.0.0
  • Linux的
  • 測試單元(2.4.1,2.4.0,2.3.2,1.2.3)
  • 測試單位通知( 0.3.0)

回答

1

我認爲你不需要在SiteLayoutTest內調用fixtures :site_layouts。 Rails應該自動加載你的燈具。

更多關於燈具Rails Guides的信息。

+0

謝謝ream88,你是對的 – sameera207

1

您是否應該從您在test_helper.rb中創建的ActiveSupport :: TestCase派生?這應該自動加載你的裝置

require 'test_helper' 

class SiteLayoutTest < ActiveSupport::TestCase 
    test "show site layout" do 
    layout = site_layouts(:one) 
    end 
end