TypeError: неправильный тип аргумента String (ожидаемый модуль)

У меня есть следующий код:

class ProfileLookup < ActiveRecord::Base
  class << self
    ProfileLookup.select("DISTINCT category").map{|c| c.category}.each do |category|
      define_method("available_#{category.pluralize}".to_sym) do
        ProfileLookup.where(category: category).order(:value).all.collect{|g| g.value}
      end
    end
  end
end

, который в основном содержит загрузку данных поиска, разделенных по категориям. Цель состоит в том, чтобы создать метод для каждой категории в базе данных. Через консоль Rails, этот код работает так, как ожидалось:

ruby-1.9.3@hub :002 > ProfileLookup.available_genders
  ProfileLookup Load (0.6ms)  SELECT "profile_lookups".* FROM "profile_lookups" WHERE "profile_lookups"."category" = 'gender' ORDER BY value
 => ["Female", "Male"] 

Однако мои спецификации не работают. Следующая спецификация:

require "spec_helper"

describe ProfileLookup do

  its(:available_genders).should include("Male")
  its(:available_age_groups).should include("0-17")
  its(:available_interests).should include("Autos & Vehicles")
  its(:available_countries).should include("United States")

end

не работает с:

Exception encountered: #<TypeError: wrong argument type String (expected Module)>
backtrace:
/Users/fred/code/my_app/spec/models/profile_lookup_spec.rb:5:in `include'

в чем проблема?

7
задан Neil Middleton 5 December 2011 в 12:14
поделиться