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. 《对“XXX::Invoke”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃、损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们》的问题的解决方法

    <对“XXX::Invoke”类型的已垃圾回收委托进行了回调.这可能会导致应用程序崩溃.损坏和数据丢失.向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们& ...

  2. C++面向对象程序设计举例

    [例8.1]最简单的例子. #include <iostream> using namespace std; class Time //定义Time类 { public : //数据成员为 ...

  3. 双端队列 HDOJ 3530 Subsequence

    题目传送门 题意:问最长子序列,满足区间最大值 - 最小值在[m, k]之间 分析:用双端队列维护最大值和最小值,保存的是位置.当满足条件时,更新最大值. /********************* ...

  4. SecureCRT的配色方法

    配色后效果如下: 下面开始配色 1.首先配置成默认模式 2.终端(Terminal)==>仿真(Emulation) 按图中标注进行勾选,勾选完毕点击确认 2.选项(Options)==> ...

  5. PowerShell~文件操作和对象遍历

    ps提供了丰富的文件操作,如建立,删除,改名,移动,复制,文件夹建立,显示文件列表,同时对数组对象的遍历也很方便,如果在使用PS脚本时,希望现时传入参数,可以把参数声明为param,当然需要把它写在文 ...

  6. html到计时特效(直接代码)

    <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/h ...

  7. JSP自定义标签开发步骤

    自定义的标签库一.基本概念: 1.标签(Tag): 标签,通常也成为动作,是一组按照XML语法格式编写的代码片段,在JSP中,用来封装在页面中可重复利用的逻辑,通过标签可以使JSP网页变得简洁并且易于 ...

  8. MongoDB部署、使用、监控及调优

    MongoDB部署 系统环境:CentOS7   下载地址:http://mirrors.163.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD ...

  9. SqlServer 2008 创建测试数据

    包含要点: 数据库的循环 . insert select 句式   . 随机数(rand()函数).绝对值(abs()函数) ) ) DECLARE @randomvalue float SET @s ...

  10. Ubuntu16.04常用操作命令总结ing

    查看软件安装目录:whereis 软件名称(如:whereis mysql,where is sqlite3等) 安装软件:apt/apt-get install 软件名称(如:apt/apt-get ...