rspec测试(使用guard自动测试和spork加速测试)配置
Gemfile文件添加rspec、guard和spork,之后执行bundle install命令
gem 'rb-readline'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug' #rspec
gem 'rspec-rails' #guard
gem 'guard-rspec'
gem 'selenium-webdriver'
gem 'capybara' #spork
gem 'spork-rails'
gem 'guard-spork'
gem 'childprocess'
end
引入rspec到rails工程中执行:rails g rspec:install
root@jec:~/RubymineProjects/Brush# rails g rspec:install
create .rspec
create spec
create spec/spec_helper.rb
create spec/rails_helper.rb
之后会在工程添加spec文件夹,如下图所示:

rspec已经引入成功,接下来初始化Guard,这样guard才能和rspec一起使用,执行:bundle exec guard init rspec
root@jec:~/RubymineProjects/Brush# bundle exec guard init rspec
:: - INFO - Writing new Guardfile to /root/RubymineProjects/Brush/Guardfile
:: - INFO - rspec guard added to Guardfile, feel free to edit it
运行guard:bundle exec guard
root@jec:~/RubymineProjects/Brush# bundle exec guard
:: - INFO - Guard::RSpec is running
:: - INFO - Guard is now watching at '/root/RubymineProjects/Brush'
[] guard(main)>
接下来导入Spork的设置:bundle exec spork --bootstrap
root@jec:~/RubymineProjects/Brush# bundle exec spork --bootstrap
Using RSpec, Rails
Bootstrapping /root/RubymineProjects/Brush/spec/spec_helper.rb.
Done. Edit /root/RubymineProjects/Brush/spec/spec_helper.rb now with your favorite text editor and follow the instructions.
修改spec/spec_helper.rb的rspec设置文件,让所需的环境在一个预派生(prefork)代码块中加载,保证环境只被加载一次
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# config.order = "random"
config.include Capybara::DSL
end
end
运行spork:bundle exec spork
#在启动spork之前,一定要先创建测试数据库,即执行rake db:create和rake db:migrate命令
root@jec:~/RubymineProjects/Brush# bundle exec spork
Using RSpec, Rails
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on !
Guard和Spork协作,执行:bundle exec guard init spork
之后只要执行bundle exec guard就会自动启动spork服务器
root@jec:~/RubymineProjects/Brush# bundle exec guard init spork
:: - INFO - spork guard added to Guardfile, feel free to edit it
执行:bundle exec guard
root@jec:~/RubymineProjects/Brush# bundle exec guard
:: - INFO - Guard::RSpec is running
:: - INFO - Starting Spork for RSpec
Using RSpec, Rails
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on !
:: - INFO - Spork server for RSpec successfully started :: - INFO - Guard is now watching at '/root/RubymineProjects/Brush'
[] guard(main)>
ok
rspec测试(使用guard自动测试和spork加速测试)配置的更多相关文章
- 通过Jasmine和Guard自动测试JavaScript
原文标题:Autotesting JavaScript with Jasmine and Guard 原文地址:http://edspencer.net/2013/06/15/autotesting- ...
- Ruby Rails学习中:关于测试的补充,MiniTest报告程序,Guard自动测试
一. 关于测试的补充 1.MiniTest报告程序 为了让 Rails 应用的测试适时显示红色和绿色,我建议你在测试辅助文件中加入以下内容: (1).打开文件:test/test_helper.rb ...
- WiFi QC 自动测试:ixChariot API初探
Chariot虽然给我们提供了友好的界面,但是必须使用命令行或者使用它的API才能 实现自动测试.Chariot在安装的时候会让你选择命令行界面组件,在它的安装目录下面有一些工具, 暂时还不知道是干什 ...
- Nightwatch.js – 轻松实现浏览器的自动测试
Nightwatch.js 是一个易于使用的,基于 Node.js 平台的浏览器自动化测试解决方案.它使用强大的 Selenium WebDriver API 来在 DOM 元素上执行命令和断言. 语 ...
- Jenkins+Maven+SVN搭建自动部署、自动测试环境
.打开http://10.3.15.78:8080/jenkins/,第一次进入里面没有数据,我们需要创建job,我们这有2个项目,需要创建2个job.http://10.3.34.163:9890/ ...
- 自动测试工具SilkTest全面介绍
象交互,并最终记录测试结果,用户可以根据这些测试结果来判断测试成功还是失败. 4Test 脚本语言 和绝大多数自动化测试工具一样, SilkTest 可以自动捕捉,检测和重复用户交互的操作从而驱动测试 ...
- Apache JMeter--网站自动测试与性能测评
Apache JMeter--网站自动测试与性能测评 2013-02-28 15:48:05 标签:Jmeter From:http://bdql.iteye.com/blog/291987 出于学习 ...
- Qtp自动测试工具(案例学习)
♣Qtp是什么? ♣测试用例网站 ♦注册与登录 ♦测试脚本 ◊录制/执行测试脚本 ◊分析录制的测试脚本 ◊执行.查看测试脚本 ♦建立检查点 ...
- PHP自动测试框架Top 10
对于很多PHP开发新手来说,测试自己编写的代码是一个非常棘手的问题.如果出现问题,他们将不知道下一步该怎么做.花费很长的时间调试PHP代码是一个非常不明智的选择,最好的方法就是在编写应用程序代码之前就 ...
随机推荐
- 开发者神器!Windows上最强大的虚拟桌面工具-Dexpot
简介 : 用过Linux和Mac计算机的人都知道 , 这两个系统上都有个多桌面的功能非常使用 . 而在Windows上并没有该项功能 , 虽然目前Win10已经增加了多桌面的程序 , 但使用上仍体验不 ...
- 伪元素选择器:before 以及 :after
E:after.E:before 在旧版本里是伪类,在新版本里是伪元素,新版本下E:after.E:before会被自动识别为E::after.E::before,按伪元素来对待,这样做的目的是用来做 ...
- charles之抓包和断点
一 .charles抓包 Charles抓包很简单,只要手机设置代理即可,不会的也可以去百度. 在这里是要记录抓包过程中win10遇到的问题,手机代理设置没问题但是就是抓不到包的情况 1.关闭防火墙 ...
- Hdu 5451 Best Solver (2015 ACM/ICPC Asia Regional Shenyang Online) 暴力找循环节 + 递推
题目链接: Hdu 5451 Best Solver 题目描述: 对于,给出x和mod,求y向下取整后取余mod的值为多少? 解题思路: x的取值为[1, 232],看到这个指数,我的心情是异常崩 ...
- _bzoj1096 [ZJOI2007]仓库建设【斜率优化dp】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1096 又是一道经典斜率优化. #include <cstdio> const i ...
- UvaLive6439(string使用、回文串)
样例手写一写很容易发现规律(前后一样的串,则ans+=2),实现起来却忘了string的便捷性,其实根本用不到哈希. ; int n, ans; string s, t1, t2; int main( ...
- 设置Linux环境变量的方法和区别_Ubuntu/CentOS
设置 Linux 环境变量可以通过 export 实现,也可以通过修改几个文件来实现,有必要弄清楚这两种方法以及这几个文件的区别. 通过文件设置 Linux 环境变量 首先是设置全局环境变量,对所有用 ...
- Brush (III) LightOJ - 1017
Brush (III) LightOJ - 1017 题意:有一些点,每刷一次可以将纵坐标在区间(y1,y1+w)范围内的所有点刷光,y1为任何实数.最多能刷k次,求最多共能刷掉几个点. 先将点按照纵 ...
- Minimal string CodeForces - 797C
Minimal string CodeForces - 797C 题意:有一个字符串s和空串t和u,每次操作可以将s的第一个字符取出并删除然后放到t的最后,或者将t的最后一个字符取出并删除然后放到u的 ...
- (022)[工具软件]图片浏览 JPEGView
JPEGView是一款小巧绿色快速的图像浏览工具,并且支持全屏或窗口模式.主页地址: https://sourceforge.net/projects/jpegview/JPEGView软件小巧,但功 ...