【发布时间】:2015-12-09 19:40:24
【问题描述】:
我正在使用 ruby v1.9.3 和 factory_girl v2.2 并尝试设置特征。但是当我尝试使用我的特质时,我得到了这个错误。是不是因为我用的是ruby版本?
Failure/Error: let!(:notification) { create(:notification, :confirmable) }
NoMethodError:
undefined method `symbolize_keys' for :confirmable:Symbol
# ./spec/controllers/api/v1/sms_controller_spec.rb:13:in `block (3 levels) in <top (required)>
这是我的工厂:
FactoryGirl.define do
factory :notification do
smssid { Faker::Number.number(10) }
msg { Faker::Lorem.sentence(3) }
to { Faker::PhoneNumber.phone_number }
trait :confirmable do
confirmable "true"
end
end
end
规格:
require 'spec_helper'
describe Api::V1::SmsController do
let!(:user) { create(:user) }
describe "GET /api/v1/user/sms" do
let!(:notification) { FactoryGirl.create(:notification, :confirmable) }
context "a user replies to a confirmation with c" do
it "does something" do
get :incomming_message, :sid => notification.smssid,
:to => notification.to,
:from => user.phone_number,
:body => "c",
:status => "recieved",
:format => :json
notification.reload
notification.confirmed.should eq(true)
end
end
end
end
*** 编辑,用我的规范文件更新
【问题讨论】:
-
你的规范文件是什么样子的
-
对于旧版本的 FactoryGirl,我认为您使用特征的方式不同,例如,github.com/thoughtbot/factory_girl/blob/v2.2.0/…
-
我会尽快更新您的应用程序,不再支持 Ruby 1.9.3 并且不安全。正如@DaveNewton 指出的那样,您的问题似乎还在于您使用的是带有较新文档的过时版本的 FactoryGirl。
-
@DaveNewton 我查看了文档,似乎特征设置正确。但是,他们没有给出任何关于在建造工厂时使用特性的例子。
-
哪些文档?哪个版本的FG? AFAIK 错误消息和 2.2 文档都表明您没有正确使用它来满足
create在您的版本中的期望。
标签: ruby-on-rails ruby factory-bot