Skip to content

Commit

Permalink
Add specs for Gems::Client#info
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed May 29, 2011
1 parent 56a0044 commit f856906
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--color
--format=nested
--backtrace
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
5 changes: 5 additions & 0 deletions gems.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 2 additions & 3 deletions lib/gems/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions spec/gems/client_spec.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions spec/gems_spec.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions spec/helper.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f856906

Please sign in to comment.