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加速测试)配置的更多相关文章

  1. 通过Jasmine和Guard自动测试JavaScript

    原文标题:Autotesting JavaScript with Jasmine and Guard 原文地址:http://edspencer.net/2013/06/15/autotesting- ...

  2. Ruby Rails学习中:关于测试的补充,MiniTest报告程序,Guard自动测试

    一. 关于测试的补充 1.MiniTest报告程序 为了让 Rails 应用的测试适时显示红色和绿色,我建议你在测试辅助文件中加入以下内容: (1).打开文件:test/test_helper.rb ...

  3. WiFi QC 自动测试:ixChariot API初探

    Chariot虽然给我们提供了友好的界面,但是必须使用命令行或者使用它的API才能 实现自动测试.Chariot在安装的时候会让你选择命令行界面组件,在它的安装目录下面有一些工具, 暂时还不知道是干什 ...

  4. Nightwatch.js – 轻松实现浏览器的自动测试

    Nightwatch.js 是一个易于使用的,基于 Node.js 平台的浏览器自动化测试解决方案.它使用强大的 Selenium WebDriver API 来在 DOM 元素上执行命令和断言. 语 ...

  5. Jenkins+Maven+SVN搭建自动部署、自动测试环境

    .打开http://10.3.15.78:8080/jenkins/,第一次进入里面没有数据,我们需要创建job,我们这有2个项目,需要创建2个job.http://10.3.34.163:9890/ ...

  6. 自动测试工具SilkTest全面介绍

    象交互,并最终记录测试结果,用户可以根据这些测试结果来判断测试成功还是失败. 4Test 脚本语言 和绝大多数自动化测试工具一样, SilkTest 可以自动捕捉,检测和重复用户交互的操作从而驱动测试 ...

  7. Apache JMeter--网站自动测试与性能测评

    Apache JMeter--网站自动测试与性能测评 2013-02-28 15:48:05 标签:Jmeter From:http://bdql.iteye.com/blog/291987 出于学习 ...

  8. Qtp自动测试工具(案例学习)

    ♣Qtp是什么? ♣测试用例网站    ♦注册与登录    ♦测试脚本       ◊录制/执行测试脚本       ◊分析录制的测试脚本       ◊执行.查看测试脚本    ♦建立检查点     ...

  9. PHP自动测试框架Top 10

    对于很多PHP开发新手来说,测试自己编写的代码是一个非常棘手的问题.如果出现问题,他们将不知道下一步该怎么做.花费很长的时间调试PHP代码是一个非常不明智的选择,最好的方法就是在编写应用程序代码之前就 ...

随机推荐

  1. 【HDU - 1257】最少拦截系统(贪心)

    最少拦截系统 Descriptions: 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的 ...

  2. 大型系统的Redis性能优化

    问题描述 系统背景:大型线上Java服务集群(活跃用户数上千万),业务重度使用Redis存储个管理Session,业务并发量>1WQPS,基本上每个请求都需要访问Redis(可能是多次),使用了 ...

  3. ubuntu 下配置django 项目能够被局域网下的其他电脑访问

    在项目下的路径下下运行 python manage.py runserver 后面的端口换成其他可用的端口也可以 如何让外网也能访问呢,有待更新

  4. the little schemer 笔记(2)

    第二章 Do it, Do it Again, and Again, and Again... 假设l是 (Jack Sprat could eat no chicken fat) 那么 (lat? ...

  5. Codeforces 1144F(二分染色)

    发现奇环不可行,偶环可行,考虑二分图.然后染色,方向全都从一种指向另一种就可以了,随意. ; int n, m, color[maxn]; vector<int> vc[maxn]; ve ...

  6. 在CATIA中通过OUTGEN 生成OUT 文件 教程

    前言: 本教程基于CATIA V5R2014版本. 关于大众数据标准格式:OUT/DMU/PCA文件的说明,如图1所示. 图1:关于OUT/DMU/PCA文件的说明 1.创建KPR文件,下挂所有子文件 ...

  7. freertos之特点

    主要特点:协程(co-routine):任务间的中断通信机制              支持可抢占式/协作式任务调度 .FreeRTOS-MPU              内核对象可以动态或静态分配 ...

  8. angularjs 下select中ng-options使用

    当我有一堆object数据要用下拉框进行显示选择时,可以使用到angularjs中的select中的ng-options的属性.官网网址:https://docs.angularjs.org/api/ ...

  9. PHP设计模式 观察者模式(Observer)

    定义 当一个对象状态发生改变时,依赖它的对象全部会收到通知,并自动更新. 模式要点 Event:事件 Trigger() 触发新的事件 abstract EventGenerator 事件产生者 Fu ...

  10. checkbox:click事件触发span元素内容改变

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...