name, version, and platform •Gems split out reusable functionality that others can use •Some gems also provide command line utilities Gems are build using the Rubygems tool (included with Ruby itself).
freewill.rb └── freewill.gemspec So, this is your first gem. Contains information about the gem’s files, test information, platform, version number, author’s email and name. Contains the code of the gem.
freewill ├── lib/ │ └── freewill.rb ├── test/ │ └── test_freewill.rb ├── README ├── Rakefile └── freewill.gemspec This is a more usual gem. Contains the executables of the gem. Contains the tests of the gem. Contains the docs of the gem. Helps automating gem release, testing and generate docs.
tar zxvf data.tar.gz x lib/freewill.rb [...] › gunzip metadata.gz › cat metadata --- !ruby/object:Gem::Specification name: redpomo version: !ruby/object:Gem::Version version: 0.0.7 prerelease: platform: ruby authors: - Stefano Verna autorequire: bindir: bin [...] All the gem files are placed in an inner data.tar.gz tarball A YAML serialized version of a Ruby class, containing all the gemspec infos.
if successful and false if the feature is already loaded. If the filename does not resolve to an absolute path, it will be searched for in the directories listed in $LOAD_PATH.
:list desc "install APP_NAME", "install an app" method_options :version def install(name) version = options[:version] # do something end desc "list [SEARCH]", "list all the apps" def list(search = "") # list everything end end
do describe ".hot" do it "fetches /hot.json stories, and prints them out" do stories = double("stories array") Redditor::Story.stub(:find).with(type: :hot).and_return(stories) Redditor::StoriesPrinter.should_receive(:output).with(stories) subject.hot end end end
do describe ".hot" do it "fetches /hot.json stories, and prints them out" do stories = double("stories array") Redditor::Story.stub(:find).with(type: :hot).and_return(stories) Redditor::StoriesPrinter.should_receive(:output).with(stories) subject.hot end end end double generic term for any kind of pretend object used in place of a real object for testing purposes. The name comes from the notion of a Stunt Double in movies.
do describe ".hot" do it "fetches /hot.json stories, and prints them out" do stories = double("stories array") Redditor::Story.stub(:find).with(type: :hot).and_return(stories) Redditor::StoriesPrinter.should_receive(:output).with(stories) subject.hot end end end
do describe "#find" do it "fetches stories for the specified filter, mapping them into Stories" do url = double("Reddit URL") raw_story = double("story hash") story = double("Story") Redditor::Story.stub(:url_for).with(foo: :bar).and_return(url) Redditor::Story.stub(:fetch).with(url).and_return([ raw_story ]) Redditor::Story.stub(:new).with(raw_story).and_return(story) result = Redditor::Story.find(foo: :bar) result.should have(1).story result.first.should == story end end end