2011-01-12 37 views
0

我有以下幾點:如何在我的test_helper.rb文件中設置factory_girl以與shoulda一起使用?

1 ENV["RAILS_ENV"] = "test" 
    2 require File.expand_path(File.dirname(__FILE__) + "/../config/environment") 
    3 require 'test_help' 
    4 require 'shoulda' 
    5 require 'factory_girl' 
    6 FactoryGirl.find_definitions 

我得到一個錯誤:

NameError: uninitialized constant OutboundEmail 

我把它放在那裏,因爲當我跑我的測試,沒有它,它不承認我的OutboundMailer:

require 'test_helper' 
    2 
    3 class OutboundMailerTest < ActionMailer::TestCase 
    4 
    5 context "test creating email" do 
    6 
    7  setup do 
    8  @email = Factory.build(:outbound_email) #create email from factory 
    9  end 
10 
11  should "test sending of the outbound email" do 
12  @expected.subject = "#{@email.subject}" 
13  @expected.body = "#{@email.body}" 
14  @expected.date = Time.now 
15 
16  assert_equal @expected.encoded, OutboundMailer.create_email(@expected.date).encoded 
17  end 
18 end 
19 end 
+0

Rails 2.3.x或Rails 3? – 2011-01-12 00:55:36

回答

3

您有一個錯字。正如你在OutboundMailerTest類做你應該使用

Factory.find_definitions 

FactoryGirl.find_definitions 

+0

啊,也許就是這樣,讓我一起去吧... – Angela 2011-01-12 03:05:57

相關問題