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代码是一个非常不明智的选择,最好的方法就是在编写应用程序代码之前就 ...
随机推荐
- springboot(十二) SpringBoot 性能优化
代码地址:https://github.com/showkawa/springBoot_2017/tree/master/spb-demo springboot优化主要有三类优化:1.包扫描优化 2. ...
- JAVA多线程(一) Thread & Runnable
githut代码地址:https://github.com/showkawa/springBoot_2017/tree/master/spb-demo/spb-brian-query-service/ ...
- 鸟哥私房菜基础篇:Linux是什么习题
猫宁!!! 参考链接:http://cn.linux.vbird.org/linux_basic/0110whatislinux.php#ex 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-你在你的 ...
- iOS bounds vs frame
斯坦福iOS开发课程的白胡子大叔的PPT解释得淋漓尽致!
- 莫比乌斯函数 && HDU-1695
莫比乌斯函数定义: $$\mu(d)=\begin{cases}1 &\text{d = 1}\\(-1)^r &\text{$d=p_1p_2...p_r,其中p_i为不同的素数$} ...
- PopupWindow(2)简单示例-自定义弹出菜单
本示例,用 popupWindow 自定义弹出菜单 public class CustomActionProvider extends ActionProvider implements OnMenu ...
- uva 6910 - Cutting Tree 并查集的删边操作,逆序
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- Hadoop体系结构管理
一.查看Zookeeper信息 [hadoop@weekend01 ~]$zkServer.sh status JMX enabled by default Using config: /hadoop ...
- servlet生命周期:
Servlet生命周期分为三个阶段: 1,初始化阶段 servlet实例创建时调用init()方法,在Servlet的整个生命周期内,init()方法只被调用一次. 2,响应客户请求阶段 调用ser ...
- Oozie是什么?
但是,一般用Azkaban了.(具体见我写的另一篇博客:) 官网:https://oozie.apache.org/ Oozie is a workflow scheduler system ...