Rspec 使用笔记
来源:互联网 发布:小ck 知乎 编辑:程序博客网 时间:2024/06/13 15:08
打算以后使用rspec 就行测试开发,由于第一次在项目中使用,所以,记录再次,便于以后查询
本文的记录参考了开源软件 angle-nest 和 Ruby-China源码
- 安装gem
group :development, :test do gem 'cucumber-rails', :require => false gem 'database_cleaner' gem 'factory_girl' gem 'factory_girl_rails' gem 'rspec-rails' gem 'capybara' gem 'delorean'end
- install
rails generate rspec:install
- 运行测试
rake spec
- 修改helper文件
config.mock_with :rspec config.use_transactional_fixtures = false config.include Delorean DatabaseCleaner.strategy = :truncation config.before do DatabaseCleaner.clean end
- 安装watchr
gem 'watchr'
- 新建.watchr文件
def run_spec(file) unless File.exist?(file) puts "#{file} does not exist" return end puts "Running #{file}" system "bundle exec rspec #{file}" putsendwatch("spec/.*/*_spec.rb") do |match| run_spec match[0]endwatch("app/(.*/.*).rb") do |match| run_spec %{spec/#{match[1]}_spec.rb}end
解析一旦spec/目录下有以_spec.rb结尾的文件发生了改变,watchr便会自动运行run_spec 方法来对该文件进行测试。 一旦有app/目录下有.rb结尾的文件发生了改变,立即调用run_spec 方法来执行该文件所对应的spec测试文件。 run_file 通过文件名来检查spec文件是否存在, 然后来运行该spec (调用 system)
- 运行
watchr .watchr
- 增加spark提升速度
gem 'spork', '1.0.0rc3'
- 运行
spork --bootstrap
- 修改spec_helper.rb
第一,上传 rubygems,因为我们已经有bundler了
修改spec_helper.rb文件如下require 'spork'#uncomment the following line to use spork with the debugger#require 'spork/ext/ruby-debug'Spork.prefork do ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' # 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} RSpec.configure do |config| config.mock_with :rspec config.use_transactional_fixtures = false config.include Delorean DatabaseCleaner.strategy = :truncation config.before do DatabaseCleaner.clean end endendSpork.each_run do # This code will be run each time you run your specs.end
- 修改.rspec文件,增加如下代码
--drb
- 运行spork
spork
- 在运行 watchr .wtachr 速度加快了
- 清除test环境下的缓存,编辑
config/environments/test.rb
config.cache_classes = false
- Rspec 使用笔记
- Rspec笔记
- Rspec笔记
- 使用RSpec
- RSpec
- rspec
- RSpec
- rspec
- 说说rspec测试的使用
- 使用 RSpec 进行行为驱动测试
- 使用 RSpec 进行行为驱动测试
- 使用 RSpec 进行行为驱动测试
- 使用 RSpec + Capybara 简单 BDD 入门 -目录
- Appium总结(三):Rspec使用初步用法
- Rails 3.2.3 使用 Spork + Guard + RSpec + Capybara + livereload
- ruby on rails中使用 RSpec 进行行为驱动测试
- 使用Rspec进行rails测试详解1-搭建测试环境
- 使用Rspec进行rails测试详解1-Transactions
- js 各种奇葩写法
- ios push机制
- python日志模块(logging)
- 共轭先验的解释
- 《php开发典型模块大全》读书笔记 第二章 基础知识 (张迅雷闪击PHP系列)
- Rspec 使用笔记
- Table 中2个列(TD)的交换
- 开始怀念学生时光
- URL encode 与 URL decode 的C语言实现
- vc6用unicode 编码方式来编译程序
- 外语学习的真实方法及误区
- window 快速启动ORACLE 服务
- 黑马程序员-day20综合练习
- Servlet 工作原理解析