开发者

how do I set up factory_girl in my test_helper.rb file to use with shoulda?

开发者 https://www.devze.com 2023-02-04 10:54 出处:网络
I have the following: 1 ENV[\"RAILS_ENV\"] = \"test\" 2 require File.expand_path(File.dirname(__FILE__) + \"/../config/environment\")

I have the following:

  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

I get an error:

NameError: uninitialized constant OutboundEmail

I put it there because when I ran my test without it, it didn't recognize my OutboundMailer:

require 'test_helper'
  2 
  3 class OutboundMailerTest < Ac开发者_Go百科tionMailer::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


You have a typo. You should use

Factory.find_definitions 

not

FactoryGirl.find_definitions

As you do in your OutboundMailerTest class.

0

精彩评论

暂无评论...
验证码 换一张
取 消