sameera207
sameera207

Reputation: 16629

Unit testing error in Rails 3

I'm trying to implement some unit tests in my rails3 application. The following is my 'test_helper.rb' file.

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

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

Following my fixture file (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>

and following is my Unit test class

require 'test_helper'

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

and when I try to run the rake test:units I'm getting the following error

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

I'm a little new to testing. I'm on

Upvotes: 0

Views: 504

Answers (2)

ramblex
ramblex

Reputation: 3057

Should you derive from the ActiveSupport::TestCase you've created in test_helper.rb? That should autoload your fixtures

require 'test_helper'

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

Upvotes: 1

Mario Uher
Mario Uher

Reputation: 12397

I think you don't need the fixtures :site_layouts call inside SiteLayoutTest. Rails should auto load your fixtures.

More about fixtures in the Rails Guides.

Upvotes: 1

Related Questions