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代码是一个非常不明智的选择,最好的方法就是在编写应用程序代码之前就 ...
随机推荐
- Jquery禁用网页右键菜单
$(function(){ $(document).bind("contextmenu",function(e){ return false; }); });
- 更换过Ubuntu之后经常性卡死,原因有待细究
如题: 卡死时间: 2019-5-22-14:45 再次卡死,这次绝对不是看视频的原因了,具体什么原因还是不知道,不过我觉得就是显卡的问题,和搜索出来的问题差不多,安装了一些东西,看看行不行吧 sud ...
- [LuoGu]P2664 树上游戏
Portal 这题真的好. 看到树上路径, 脑子里就要点分治 这一题对于每个点都要计算一遍, 如果暴算实在不好算, 这样我们就可以考虑算贡献. 直接计算每种颜色的贡献. 因为一条过重心的路径中, 可能 ...
- 模拟 HDOJ 5099 Comparison of Android versions
题目传送门 /* 题意:比较型号的大小 模拟:坑点在长度可能为5,此时设为'A' */ #include <cstdio> #include <algorithm> #incl ...
- 浅谈Java中static作用--转
static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被static修饰的成员变量和成员方法独立于该类的任何 ...
- 创建表的规范 nvarchar2,varchar2
1,这个真没见过什么最佳实践,都是变长的,这些都是研发根据业务需求自己设定啊. 如果需要多语种支持就用NVARCHAR2(或者汉语),如果只是单语种(英语)就varchar2 . 2. Oracle中 ...
- debug授权码
www.vfxcx.com 704835b5c54b56426257e0742568fe54
- 1049 - One Way Roads 观察 dfs
http://lightoj.com/volume_showproblem.php?problem=1049 题意是,在一副有向图中,要使得它变成一个首尾相连的图,需要的最小代价. 就是本来是1--& ...
- JS执行保存在数据库中的JS代码
function createScript(script) { var myScript = document.createElement("script"); myScript. ...
- C#基础学习2
变量与数据类型!