gem install factory_girl
文章是从个人博客转过来的, 可以直接访问 iwangzheng.com
https://github.com/thoughtbot/factory_girl
https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md
今天项目结束,打算搞一下接手这个项目之前的单元测试,因为接受的时候很多测试是跑不通的,于是重新学习了一下 factory_girl
gem install factory_girl (半天没响应)
由于国内网络原因(你懂的),导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败。所以你会与遇到 gem install rack 或 bundle install 的时候半天没有响应,具体可以用 gem install rails -V 来查看执行过程。现在来更换一下gem source
$ gem sources --remove https://rubygems.org/
$ gem sources -a http://ruby.taobao.org/
$ gem sources -l
*** CURRENT SOURCES *** http://ruby.taobao.org
# 请确保只有 ruby.taobao.org
Configure your test suite
# rspec
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end # Test::Unit
class Test::Unit::TestCase
include FactoryGirl::Syntax::Methods
end # Cucumber
World(FactoryGirl::Syntax::Methods) # Spinach
class Spinach::FeatureSteps
include FactoryGirl::Syntax::Methods
end # MiniTest
class MiniTest::Unit::TestCase
include FactoryGirl::Syntax::Methods
end # MiniTest::Spec
class MiniTest::Spec
include FactoryGirl::Syntax::Methods
end # minitest-rails
class MiniTest::Rails::ActiveSupport::TestCase
include FactoryGirl::Syntax::Methods
end 由于我们用的是rspec,所以选第一种,所在spec/spec_helper.rb里配置第18行那句
1 # -*- encoding : utf-8 -*-
2 # This file is copied to spec/ when you run 'rails generate rspec:install'
3 ENV["RAILS_ENV"] ||= 'test'
4 require File.expand_path("../../config/environment", __FILE__)
5 require 'rspec/rails'
6 require 'rspec/autorun'
7 require "email_spec"
8
9 # Requires supporting ruby files with custom matchers and macros, etc,
10 # in spec/support/ and its subdirectories.
11 Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
12 Dir[Rails.root.join("lib/mock*.rb")].each {|f| require f}
13
14 RSpec.configure do |config|
15 config.fixture_path = "#{::Rails.root}/spec/fixtures"
16 config.use_transactional_fixtures = true
17 config.infer_base_class_for_anonymous_controllers = false
18 config.include FactoryGirl::Syntax::Methods
19 config.global_fixtures = :all
20 config.include(EmailSpec::Helpers)
21 config.include(EmailSpec::Matchers)
22 end
Defining factories
# This will guess the User class
FactoryGirl.define do
factory :user do
first_name "John"
last_name "Doe"
admin false
end # This will use the User class (Admin would have been guessed)
factory :admin, class: User do
first_name "Admin"
last_name "User"
admin true
end
end
一般在factories的文件夹,以modle名字来命名factory,这样更清晰
来看看我写的这段
FactoryGirl.define do
factory :cms_tv_version do
title "2.0.0"
state 1
end
end
gem install factory_girl的更多相关文章
- mac gem install nokogiri error
Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /Users/angela/.rbenv/versions/1.9 ...
- OSX 10.11 cocoapods安装命令: sudo gem install -n /usr/local/bin cocoapods
10.11 cocoapods安装命令: sudo gem install -n /usr/local/bin cocoapods
- gem install 出现Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org
在安装了rvm来管理多版本的ruby之后,想在不同环境下安装一些gems,结果gem install puma 之后,发现一次又一次失败. gem install 出现Errno::ECONNRESE ...
- sudo gem install cocoapods 没反应问题
1. 尝试更新 sudo gem update --system 2. 查看安装详细 sudo gem install cocoapods -V 3.详细使用有个链接 http://blog.csdn ...
- ruby on rails gem install pg时无法安装
gem install pg -v '0.18.2' Building native extensions. This could take a while... ERROR: Error insta ...
- sudo gem install cocoapods
在使用IOS_BaiduSDK的时候,需要用到cocoapods,所以就需要按照步骤继续着.但是在过程中会遇到一些问题: 1. sudo gem install cocoapods 运行这个报错 Ru ...
- 在openSUSE13.2上gem install rails -v 4.1成功,但是之后不存在rails命令解决
解决方案为,不要用sudo gem install就好了,卧槽
- 本地安装gem install --local redis-stat-0.4.13.gem
因为主机环境不能联外网,悲哀,所以只能想办法下载包,上传到主机来安装 环境:el6.x86_64 1. gem 安装[http://centos.ustc.edu.cn/centos/6/os/x86 ...
- gem install走代理,速度刚刚的
有个树莓pi,安装了shadowsocks 和 cow ,做代理,走ipv6,学校不收ipv6流量钱.速度也不错,快的下载可达10M/s. gem install xx遇到墙了. nano ~/.ge ...
随机推荐
- [Aaronyang] 写给自己的WPF4.5 笔记[3MenuItem中的icon]
敢于尝试,就等于你已经向成功迈出了第一步 --Aaronyang的博客(www.ayjs.net)-www.8mi.me =============时隔两年后再看WPF========== 因为以前的 ...
- Linq之延迟加载特性
目录 写在前面 系列文章 延迟加载 总结 写在前面 上篇文章介绍了linq中常见的几个关键字,并列举了几个例子,算是对linq如何使用有了初步了解.上篇文章中也提到了,能够使用linq的场合有一个要求 ...
- [设计模式] javascript 之 代理模式
代理模式说明 说明:顾名思义就是用一个类来代替另一个类来执行方法功能,这个模式跟装饰模式有点相似,不一样的是,代理模式是代替客户初始化被代理对象类,而装饰模式采用接口或初装饰者参数引用的方式来执行的. ...
- nonatomic, retain,weak,strong用法详解
strong weak strong与weak是由ARC新引入的对象变量属性 ARC引入了新的对象的新生命周期限定,即零弱引用.如果零弱引用指向的对象被deallocated的话,零弱引用的对象会被自 ...
- 每天一个linux命令(19):Linux 目录结构
对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统只管重要,下面 ...
- 团队项目作业第二项:利用NABCD模型进行竞争性需求分析
项目需求分析与建议--NABCD模型(王鲁跃负责) N (Need 需求) 对于现在的学生来说,我们认为打字是很重要的.不管在什么方面都需要进行电脑打字,例如文员.QQ.MSN.制作,论文等等,都需要 ...
- iOS开发中的错误整理,关于用绑定Tag取控件的注意事项,有时候不绑定也是个错!
如图:红色框中是个自定义的导航工具条titlesView(没有绑定Tag),工具条中有五个按钮(按钮绑定了Tag)以及一个红色的指示器indicatorView(没有绑定Tag),下面的蓝色是可以滚动 ...
- 【前端学习】sublime开启vim模式
学习目标:在sublime下开启vim模式,了解基本vim的编辑快捷键. 下载安装Sublime Text 3 :http://www.sublimetext.com/3 Vim/Vi: Vim/Vi ...
- Teradata SQL tips
Question: Insert into table_name (1),(2),.... Teradata 貌似不能同时插入,只能一条一条插入,报错. 后来改为: Insert into tabl ...
- BZOJ1083 繁忙的都市
Description 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口 ...