0

アプリでテストをセットアップしようとしていますが、RSpec、FactoryGirl、および Mongoid で問題が発生しました。私は次の工場を持っています:

FactoryGirl.define do
  factory :user do |u|
    u.name             { Faker::Name.name }
    u.email            { Faker::Internet.email }
    u.crypted_password { Faker::Lorem.characters(10) }
    u.password_salt    { Faker::Lorem.characters(10) }
    u.role             :user
  end
end

テストでこのファクトリを使用しようとしています:

require 'spec_helper'
describe User do
  it "has a valid factory" do
    create(:user).should be_valid
  end
end

しかし、私はこのエラーが発生します:

  1) User has a valid factory
     Failure/Error: FactoryGirl.create(:user).should be_valid
     NoMethodError:
       undefined method `user' for #<User:0x007ff24a119b28>
     # ./spec/models/user_spec.rb:5:in `block (2 levels) in <top (required)>'

このエラーの原因がわかりません。また、rspec を使用して完全なスタック トレースを表示する方法はありますか?

4

1 に答える 1

2

この行には問題があります

u.role :user

デフォルトの役割を「ユーザー」として定義したいと思いますか?次に、シンボルまたはメソッドを使用しないで、代わりに文字列を使用します

u.role 'user'
于 2013-07-02T04:50:34.303 に答える