diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..bb259fe --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--color +--format=nested +--backtrace diff --git a/Rakefile b/Rakefile index 2762450..3616e54 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,12 @@ require 'bundler' Bundler::GemHelper.install_tasks +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) + +task :default => :spec +task :test => :spec + require 'yard' namespace :doc do YARD::Rake::YardocTask.new do |task| diff --git a/gems.gemspec b/gems.gemspec index 46c5325..bcc6ba9 100644 --- a/gems.gemspec +++ b/gems.gemspec @@ -2,7 +2,12 @@ require File.expand_path('../lib/gems/version', __FILE__) Gem::Specification.new do |gem| + gem.add_development_dependency 'ZenTest', '~> 4.5' + gem.add_development_dependency 'maruku', '~> 0.6' gem.add_development_dependency 'rake', '~> 0.9' + gem.add_development_dependency 'rspec', '~> 2.6' + gem.add_development_dependency 'simplecov', '~> 0.4' + gem.add_development_dependency 'webmock', '~> 1.6' gem.add_development_dependency 'yard', '~> 0.7' gem.add_runtime_dependency 'faraday', '~> 0.6.1' gem.add_runtime_dependency 'faraday_middleware', '~> 0.6.3' diff --git a/lib/gems/client.rb b/lib/gems/client.rb index 2ff396b..796f648 100644 --- a/lib/gems/client.rb +++ b/lib/gems/client.rb @@ -12,10 +12,9 @@ class Client # @param options [Hash] A customizable set of options. # @return [Hashie::Mash] # @example - # Gems.information 'rails' - def information(gem, options={}) + # Gems.info 'rails' + def info(gem, options={}) get("/api/v1/gems/#{gem}.json", options) end - alias :info :information end end diff --git a/spec/gems/client_spec.rb b/spec/gems/client_spec.rb new file mode 100644 index 0000000..4683978 --- /dev/null +++ b/spec/gems/client_spec.rb @@ -0,0 +1,19 @@ +require 'helper' + +describe Gems::Client do + before do + @client = Gems::Client.new + end + + describe "#info" do + before do + stub_get("/api/v1/gems/rails.json").to_return(:body => fixture("rails.json")) + end + + it "should return some basic information about the given gem" do + info = @client.info 'rails' + a_get("/api/v1/gems/rails.json").should have_been_made + info.name.should == 'rails' + end + end +end diff --git a/spec/gems_spec.rb b/spec/gems_spec.rb new file mode 100644 index 0000000..f023c4f --- /dev/null +++ b/spec/gems_spec.rb @@ -0,0 +1,30 @@ +require 'helper' + +describe Gems do + context "when delegating to a client" do + before do + stub_get("/api/v1/gems/rails.json").to_return(:body => fixture("rails.json")) + end + + it "should get the correct resource" do + Gems.info('rails') + a_get("/api/v1/gems/rails.json").should have_been_made + end + + it "should return the same results as a client" do + Gems.info('rails').should == Gems::Client.new.info('rails') + end + end + + describe '.respond_to?' do + it 'should take an optional argument' do + Gems.respond_to?(:new, true).should be_true + end + end + + describe ".new" do + it "should return a Gems::Client" do + Gems.new.should be_a Gems::Client + end + end +end diff --git a/spec/helper.rb b/spec/helper.rb new file mode 100644 index 0000000..5c767b1 --- /dev/null +++ b/spec/helper.rb @@ -0,0 +1,23 @@ +$:.unshift File.expand_path('..', __FILE__) +$:.unshift File.expand_path('../../lib', __FILE__) +require 'simplecov' +SimpleCov.start +require 'gems' +require 'rspec' +require 'webmock/rspec' + +def a_get(path) + a_request(:get, 'http://rubygems.org' + path) +end + +def stub_get(path) + stub_request(:get, 'http://rubygems.org' + path) +end + +def fixture_path + File.expand_path('../fixtures', __FILE__) +end + +def fixture(file) + File.new(fixture_path + '/' + file) +end