4

我遇到了一个快速的问题。我得到了 user_spec 页面的“未定义方法‘工厂’”。我相信“let(:user) { Factory(:user) }”的语法不正确。但是我想不出一个可行的方法。

Failure/Error: let(:user) { Factory(:user) }
     NoMethodError:
       undefined method `Factory' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fc7ac31e6a8>

如果有人可以查看我的代码并帮助我,那将不胜感激,因为我几乎完成了密码重置的测试。

user_spec.rb:

require 'spec_helper'

describe User do
  describe "#send_password_reset" do
    let(:user) { Factory(:user) }

    it "generates a unique password_reset_token each time" do
      user.send_password_reset
      last_token = user.password_reset_token
      user.send_password_reset
      user.password_reset_token.should_not eq(last_token)
    end

    it "saves the time the password reset was sent" do
      user.send_password_reset
      user.reload.password_reset_sent_at.should be_present
    end

    it "delivers email to user" do
      user.send_password_reset
      last_email.to.should include (user.email)
    end
  end
end
4

2 回答 2

8

Factory Girl 方法如下:

let(:user) { FactoryGirl.create(:user) }
于 2013-03-06T14:29:56.243 回答
7

替换FactoryFactoryGirl,他们将其更改为消除歧义并让有用的Factory命名空间可用。

于 2013-03-06T14:11:36.583 回答