在Rails项目中增加rspec (add rspec to rails and test lib files)

访问量: 1444

1. add to Gemfile:

# Gemfile: 
gem 'rspec-rails', '~> 3.0.0'
然后运行:
$ bundle exec rails generate rspec:install
记得要把生成的.rspec 文件做个修改,删掉
# .rspec file:
--color 
# NO --warning, --require spec_helper

2. 下面是测试lib文件的一个例子: make sure your have this:

# config/application.rb
config.autoload_paths += %W(#{config.root}/lib)

test a file in lib folder:

require 'rails_helper' # 这句话极度重要. 
require 'html_parser'  # it's not require 'lib/html_parser'
describe HtmlParser do

  it 'should parse html_content' do
    puts 'hihihi'
  end 

end

订阅/RSS Feed

Subscribe

分类/category