我正在与factory_girl合作,但看着机械师宝石.你能告诉我 - 迁移到机械师的利弊是什么?你比较过那些libs吗?
在工厂女孩/机械师的工厂中是否有一些配置强制它在测试用例期间只创建一次具有相同工厂名称的对象并且一直返回相同的实例?我知道,我可以这样做:
def singleton name
@@singletons ||= {}
@@singletons[name] ||= Factory name
end
...
Factory.define :my_model do |m|
m.singleton_model { singleton :singleton_model }
end
Run Code Online (Sandbox Code Playgroud)
但也许有更好的方法.
我得到一些奇怪的验证行为:它复制了我的验证错误消息,我无法弄清楚导致它的原因......它不会在rails控制台中执行此操作.
以下是我的手机型号的验证:
# phone.rb
validates :number, :length => { :minimum => 3 }
Run Code Online (Sandbox Code Playgroud)
我的规格:
require 'spec_helper'
describe Phone do
it "requires a number" do
user = User.make!
@p = Phone.new(number:nil,user_id:user.id,type:2)
@p.valid?
puts @p.errors.inspect
@p.should have(1).error_on(:number)
end
Run Code Online (Sandbox Code Playgroud)
我的测试结果:
# rspec and machinist
#<ActiveModel::Errors:0x000000036f1258 @base=#<Phone id: nil, user_id: 614, kind: nil, number: nil, created_at: nil, updated_at: nil>, @messages={:number=>["is too short (minimum is 3 characters)", "is too short (minimum is 3 characters)"]}>
F
Failures:
1) Phone requires a number
Failure/Error: @p.should have(1).error_on(:number)
expected …
Run Code Online (Sandbox Code Playgroud) 今天早上我遇到以下错误:
14) Deal on creation sets frozen to false or nil
Failure/Error: Unable to find matching line from backtrace
Errno::EMFILE:
Too many open files - identify -format %wx%h '/var/folders/BJ/BJcTANEBFxWcan28U2YEKE+++TI/-Tmp-/stream20120229-36866-4l1sa8.gif[0]'
# ./spec/support/blueprints.rb:29:in `block in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
规格太慢了(即使用spork),所以它们没用.在模型中运行20个示例需要9分钟.blueprint.rb中的第29行位于以下块之间:
Company.blueprint do
name { "Office Tronic#{rand(10 ** 10)}" }
website { 'officetronic.com' }
subdomain {"officetronic#{rand(10 ** 10)}"}
facebook { 'officetronic' }
twitter { 'officetronic' }
description { 'We are a company dealing with electronics and office supply' }
address_line1 {'34 John Street'}
address_line2 {''} …
Run Code Online (Sandbox Code Playgroud) 我想写一个rails集成测试(带ActionDispatch::IntegrationTest
).我正在使用设计验证和测试模型的机械师.我无法成功登录.
这是一个简单的例子:
class UserFlowsTest < ActionDispatch::IntegrationTest
setup do
User.make
end
test "sign in to the site"
# sign in
post_via_redirect 'users/sign_in', :email => 'foo@bar.com', :password => 'qwerty'
p flash
p User.all
end
Run Code Online (Sandbox Code Playgroud)
这是调试输出:
Loaded suite test/integration/user_flows_test
Started
{:alert=>"Invalid email or password."}
[#<User id: 980190962, email: "", encrypted_password: "", password_salt: "", reset_password_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2010-11-27 16:44:10", updated_at: "2010-11-27 16:44:10">, #<User id: 980190963, email: "foo@bar.com", encrypted_password: …
Run Code Online (Sandbox Code Playgroud) 如果我想创建和实例使用"创建"构建策略然后想要使用"attributes_for"构建策略进行验证,是否可以这样做?如果我在工厂使用序列?机械师宝石有可能吗?
我正在针对Ember.js应用程序编写单元和集成测试,当应用程序处于测试阶段时,我无法连接到服务器.这意味着我需要使用DS.FixtureAdapter来备份我的数据存储.
但我个人并不喜欢大型应用程序中的灯具,因为很难想出一套适用于每个测试用例的灯具.我更喜欢像factory_girl和machinist这样的工具,它允许我生成与所有其他测试隔离的特定于测试的数据:
FactoryGirl.define do
factory :user do
name 'John Doe'
date_of_birth { 21.years.ago }
end
end
# In specific test cases:
user = FactoryGirl.build(:user)
young_user = FactoryGirl.create(:user, date_of_birth: 17.years.ago)
Run Code Online (Sandbox Code Playgroud)
当然,factory_girl和machinist也可以自动生成相关模型.
现在有没有简单的方法在Ember.js中做到这一点?是否有技术,惯例或库可以使这更容易?谷歌搜索还没有真正的选择.
我正在使用Rails 3,机械师2,黄瓜和rspec,并且有两个blueprints.rb文件.一个在spec目录中,一个在features/support目录中.
只有一个blueprints.rb文件是个好主意吗?
如果是,那么设置它的首选方法是什么?
对于同时我只是符号链接我的功能/支持/ blueprints.rb文件投机/ blueprints.rb这可能是错误的,但它为我工作.