私は次のコードを持っている:カテゴリによって分割され、例外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コンソールを介して、このコードは正常に動作します。
[email protected] :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'
ここでの問題は何ですか?
私たちはinclude-lineを表示します。それがどこにあっても。 –