我正在尝试关注railstutorial.org,目前正在第7章开始使用工厂:http://railstutorial.org/chapters/modeling-and-viewing-users-two#sec:tests_with_factories
我正在使用Rails 3.0.1和ruby-1.9.2-p0
我不能为我的生活让我的rspec测试通过,我得到的错误是
Failures:
1) UsersController GET 'show' should be successful
Failure/Error: @user = Factory(:user)
undefined method `Factory' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1:0x00000101cc5608>
# ./spec/controllers/users_controller_spec.rb:9:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
我的factories.rb看起来像这样:
# By using the symbol ':user', we get Factory Girl to simulate the User model.
Factory.define :user do |user|
user.name "Michael Hartl"
user.email "mhartl@example.com"
user.password "foobar"
user.password_confirmation "foobar"
end
Run Code Online (Sandbox Code Playgroud)
这是我的users_controller_spec.rb档案:
require 'spec_helper'
describe UsersController do
render_views
describe "GET 'show'" do
before(:each) do
@user = Factory(:user)
end …Run Code Online (Sandbox Code Playgroud)