我正在研究部分9.3.3关于Michael Hartl的ruby on rails教程的分页,我陷入困境:运行rspec测试我收到一条错误信息,即gem FactoryGirl有问题。你认为可能会出现什么问题吗?
/Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/definition_proxy.rb:43:in `add_attribute': Both value and block given (FactoryGirl::AttributeDefinitionError)
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/definition_proxy.rb:102:in `method_missing'
from /Users/smi/projects/sample_app/spec/factories.rb:3:in `block (2 levels) in <top (required)>'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:18:in `instance_eval'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:18:in `factory'
from /Users/smi/projects/sample_app/spec/factories.rb:2:in `block in <top (required)>'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:49:in `instance_eval'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:49:in `run'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:7:in `define'
from /Users/smi/projects/sample_app/spec/factories.rb:1:in `<top (required)>'
from /Users/smi/.rvm/ge......................
users_pages_spec.rb:
describe "pagination" do
before(:all) { 30.times { FactoryGirl.create(:user) } }
after(:all) { User.delete_all }
it { should have_selector('div.pagination') }
it "should list each user" do
User.paginate(page: 1).each do |user|
expect(page).to have_selector('li', text: user.name)
end
end
end
factories.rb:
FactoryGirl.define do
factory :user do
sequense(:name) { |n| "Person #{n}" }
sequense(:email) { |n| "person_#{n}@example.com" }
password "foobar"
password_confirmation "foobar"
end
end
答案 0 :(得分:2)
我找到了答案!在factory.rb中的方法“sequence”写错了。现在所有测试都是绿色的。