要获得良好的开端,可以使用bundle gem
命令和rspec --init
.
~/code $ bundle gem my_lib
create my_lib/Gemfile
create my_lib/Rakefile
create my_lib/LICENSE.txt
create my_lib/README.md
create my_lib/.gitignore
create my_lib/my_lib.gemspec
create my_lib/lib/my_lib.rb
create my_lib/lib/my_lib/version.rb
Initializating git repo in /Users/john/code/my_lib
~/code $ cd my_lib/
~/code/my_lib $ git commit -m "Empty project"
~/code/my_lib $ rspec --init
The --configure option no longer needs any arguments, so true was ignored.
create spec/spec_helper.rb
create .rspec
- 密码是
lib
- 规格有
spec
种
- 测试数据或文件共
spec/fixtures/
份
- 需要
lib/my_lib.rb
个ruby文件.您也可以在该文件中定义例外,或者在它们自己的文件中定义例外——根据您自己的偏好.
- C源文件有
ext/my_lib
个
- shell脚本和可执行文件共有
bin
个
当有疑问时,看看其他Ruby 是如何排列的.
Further information:
您应该在gempec中添加rspec作为开发依赖项,以使其他开发人员更容易进行开发
- 编辑我的库.gemspec,在底部附近添加
gem.add_development_dependency 'rspec'
和gem.add_development_dependency 'rake'
.
- 将
Bundler.setup
和require 'my_lib'
添加到等级库/等级库辅助对象的顶部.rb,以确保在运行规范时加载gem依赖项.
- 将
require "rspec/core/rake_task"
和task :default => :spec
添加到您的Rakefile,这样运行rake
将运行您的规格.
当你在做你的最新作品时,guard-rspec可以节省你的时间和麻烦,因为automatically可以在文件改变时运行你的规格,提醒你规格失败.
~/code/my_lib $ git add spec/spec_helper.rb
~/code/my_lib $ git commit -am "Add RSpec"
~/code/my_lib $ vim my_lib.gemspec # add guard development dependency
~/code/my_lib $ bundle
~/code/my_lib $ bundle exec guard init
~/code/my_lib $ vim Guardfile # Remove the sections below the top one
~/code/my_lib $ git add Guardfile
~/code/my_lib $ git commit -am "Add Guard"
当你对自己的创作感到满意后,把它推到github上
# create a github repository for your gem, then push it up
~/code/my_lib $ curl -u myusername https://api.github.com/user/repos -d '{"name":"my_lib"}'
~/code/my_lib $ git remote add origin git@github.com:myusername/my_lib.git
~/code/my_lib $ git push
然后,当你准备在Rubygems上发布你的Ruby 时.org,运行rake release
,它将 bootstrap 你完成这些步骤.
~/code/my_lib $ rake release
进一步参考