Table of Contents
Useful links
- ruby toolbox: fuking awesome, find gems you want
- rubygems - Make your own gem: 官方的教程
- Developing a RubyGem using Bundler: 可以参考参考,其实看 bundler 生成的 readme 也够
- ruby-doc core: 居家旅行必备之良品,可以试试 pry 的
show-doc
个人推荐使用 bundler 来开发,使用 bundle gem yourgem 来快速搭起一个 gem 的基本结构。
本文接下来的内容都是基于你使用了 bundler 来初始化你的 gem 这一前提来讲的。
Ruby style guide
ruby 没有官方的 styleguide。个人的意见是,可以看看,写好后跑一遍,然后看看哪些推荐的用法,增加代码可读性。
Tests
CI and code coverage(travis ci + codecov)
使用 bundler 自动生成的 travis 自动配置就够了,一般使用不需要修改。
使用 codecov 的话,首先在你的 Gemfile 中加上这一行
gem 'codecov', :require => false, :group => :test
在你的 test/test_helper.rb 开头 加上一下内容。
require 'simplecov' SimpleCov.start if ENV['CI']=='true' require 'codecov' SimpleCov.formatter = SimpleCov::Formatter::Codecov end
安装相关的依赖, 更新 Gemfile.lock
$ bin/setup
以后跑测试的时候就会有测试覆盖的报告了
$ rake test Run options: --seed 55816 # Running: .......................... Finished in 0.009876s, 2632.7000 runs/s, 21871.6614 assertions/s. 26 runs, 216 assertions, 0 failures, 0 errors, 0 skips Coverage report generated for Unit Tests to /home/lord63/code/colors.rb/coverage. 156 / 156 LOC (100.0%) covered.
使用 # :nocov: 包住你需要忽略覆盖的的代码。
我们使用的是 simplecov,详情去 colszowka/simplecov
codecov 官方的 ruby guide 在这里, repo token 我是没用的,因为本地的覆盖数据我也不想上传,
而 ci 那边的话你也是不用设置 token 的。