我已經更新了這個答案,以配合當前的最佳實踐:
捆紮機支持創業板的發展非常完美。如果要創建一個寶石,你需要在你的Gemfile的唯一事情是這樣的:
source "https://rubygems.org"
gemspec
這告訴捆紮機看你gemspec文件中的依賴關係,當你運行bundle install
。
接下來,請確保RSpec是您的寶石的開發依賴項。編輯gemspec,所以它讀取:
spec.add_development_dependency "rspec"
接下來,創建spec/spec_helper.rb
並添加類似:
require 'bundler/setup'
Bundler.setup
require 'your_gem_name' # and any other gems you need
RSpec.configure do |config|
# some (optional) config here
end
前兩行告訴捆紮機加載您gemspec裏面只有寶石。當您在自己的機器上安裝自己的寶石時,這會強制您的規格使用您當前的代碼,而不是單獨安裝的版本。
創建規範,例如spec/foobar_spec.rb
:
require 'spec_helper'
describe Foobar do
pending "write it"
end
可選:添加一個.rspec
文件默認選項,並把它放在你的寶石的根路徑:
--color
--format documentation
最後:運行規範:
$ rspec spec/foobar_spec.rb
我想我必須寫一個:-) ...至少有兩個寶石,已經很好地整合:行爲作爲標籤可以和acts_as_geocodable。 – Zardoz 2010-12-09 12:50:36