跟随BenWalker的(惊人的)Let'sBuildInstagramWithRails,特别是BDD版本。教程使用FactoryGirl。我在多次测试中遇到以下错误:精简版Failure/Error:post=create(:post,user_id=user.id)ArgumentError:Traitnotregistered:1我什至无法让Ben用cloneofmyrepo重新创建错误,我在StackOverflow的“特征未注册”问题中找不到任何内容。这是我的第一个SO问题,所以如果我在那个前面做错了什么,请告诉我。在此先感谢您的帮助!代码选择:spec/factories
如果我有这个工厂:factory:product,class:Productdoname{Faker::Commerce.product_name}description{Faker::Lorem.paragraph}price{Faker::Number.number(3)}end我可以使用create_list创建2个这样的产品:FactoryGirl.create_list(:product,2)但我想将默认值传递给我的两个产品,我会假设理论上是这样的吗?prods=[{:name=>"Product1"},{:name=>"Product2"}]FactoryGirl.crea
我正在使用RubyonRails3.0.9、RSpec-rails2和FactoryGirl。我正在尝试陈述一个工厂协会模型,但我遇到了麻烦。我有一个factories/user.rb文件,如下所示:FactoryGirl.definedofactory:user,:class=>Userdoattribute_1attribute_2...association:account,:factory=>:users_account,:method=>:build,:email=>'foo@bar.com'endend和一个factories/users/account.rb文件,如下所示
#rspectestcode@room=FactoryGirl.build(:room)#factorydefinitionfactory:roomdolength{10}width{20}end#codeimplementationclassRoomattr_accessor:length,:widthdefinitialize(length,width)@length=length@width=widthendend在尝试构建@room时运行rspec会导致此错误ArgumentError:wrongnumberofarguments(0for2) 最佳
我有一个应用程序,用户可以在其中使用多种服务登录,例如GooglePlus、Facebook、Twitter等为此,我有一个基本的User模型,其中有has_manyIdentity记录。每个Identity记录都有一个provider字段(例如“Google”、“Facebook”等。..)以指示用于登录的提供商。有一个ActiveRecord验证只允许用户拥有每种类型的提供程序之一。所以一个用户不能有2个"Google"identities。我的工厂设置如下:FactoryGirl.definedofactory:userdosequence(:name){|n|"JulioJon
我有许多模型可以是可授权的(有一个作者字段)和/或可租赁的(有一个租户字段)。所以,我写了对他们两个的担忧。问题出在测试中。我曾使用shared_examples_forblock为关注点编写测试并将它们包含到我的模型测试中。无论如何,要做到这一点,我有几个特征和block后,例如:after(:build)do|authorable|authorable.author=build(:user,tenant:authorable.tenant)endtrait:no_authordoafter(:build)do|authorable|authorable.author=nilende
看起来很简单,但一直无法弄清楚如何让它发挥作用。在模型.rb中:defModelattr_accessor:width,:heightdefinitializeparams@width=params[:width]@height=params[:height]...在工厂文件models.rb中:FactoryGirl.definedofactory:modeldoheight5width7endend在工厂方法中设置属性会抛出错误wrongnumberofarguments(0for1)在没有Rails的情况下使用Ruby1.9.3,使用Factory.build。FactoryGi
我有这些模型,我正在尝试创建工厂以使用factory_girl。classFoo我不确定如何在不创建工厂无休止地相互调用的循环的情况下创建工厂。Factory.define:foodo|f|f.after_createdo|ff|ff.baz=Factory(:baz)endendFactory.define:bazdo|f|f.after_createdo|ff|ff.foos=[Factory.create(:foo)]endend我意识到我可以在baz工厂中省略ff.foos=[Factory.create(:foo)],但是在我的baz中测试我被迫使用foo.baz而不是仅仅使
模型/message.rbclassMessageattr_reader:bundle_id,:order_id,:order_number,:eventdefinitialize(message)hash=message@bundle_id=hash[:payload][:bundle_id]@order_id=hash[:payload][:order_id]@order_number=hash[:payload][:order_number]@event=hash[:concern]endend规范/模型/message_spec.rbrequire'spec_helper'de
我读了this来自Thoughtbot,但它仍然让我感到困惑。这是他们的例子:factory:userdotransientdorockstartrueupcasedfalseendname{"JohnDoe#{"-Rockstar"ifrockstar}"}email{"#{name.downcase}@example.com"}after(:create)do|user,evaluator|user.name.upcase!ifevaluator.upcasedendendcreate(:user,upcased:true).name#=>"JOHNDOE-ROCKSTAR"所以,