Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
guard 'rspec', cmd: 'bundle exec rspec --color' do | ||
# watch /lib/ files | ||
watch(%r{^lib/(.+).rb$}) do |m| | ||
"spec/#{m[1]}_spec.rb" | ||
end | ||
|
||
# watch /spec/ files | ||
watch(%r{^spec/(.+).rb$}) do |m| | ||
"spec/#{m[1]}.rb" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
require "bundler/gem_tasks" | ||
require 'rspec/core/rake_task' | ||
require 'bundler/gem_tasks' | ||
|
||
# Default directory to look in is `/specs` | ||
# Run with `rake spec` | ||
RSpec::Core::RakeTask.new(:spec) do |task| | ||
task.rspec_opts = ['--color', '--format', 'nested'] | ||
end | ||
|
||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,37 @@ | ||
require "blanket/version" | ||
require 'httparty' | ||
|
||
module Blanket | ||
# Your code goes here... | ||
def self.wrap(base_uri) | ||
Blanket.new base_uri | ||
end | ||
|
||
class Blanket | ||
def initialize(base_uri) | ||
@base_uri = base_uri | ||
@uri_parts = [] | ||
end | ||
|
||
def get | ||
HTTParty.get uri_from_parts(@base_uri.clone, @uri_parts.clone) | ||
@uri_parts = [] | ||
end | ||
|
||
def respond_to?(method, include_private = false) | ||
true | ||
end | ||
|
||
def method_missing(method, *args, &block) | ||
@uri_parts << method | ||
self | ||
end | ||
|
||
private | ||
|
||
def uri_from_parts(base_uri, parts) | ||
parts.inject(base_uri) do |memo, part| | ||
memo << "/#{part}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
|
||
describe Blanket do | ||
describe '#get' do | ||
let :api do | ||
Blanket::wrap("http://api.example.org") | ||
end | ||
|
||
before :each do | ||
allow(HTTParty).to receive(:get) | ||
end | ||
|
||
it 'GETs a simple resource' do | ||
api.users.get() | ||
|
||
expect(HTTParty).to have_received(:get).with("http://api.example.org/users") | ||
end | ||
|
||
it 'resets after performing a request' do | ||
api.users.get() | ||
api.videos.get() | ||
|
||
expect(HTTParty).to have_received(:get).with("http://api.example.org/videos") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'pry' | ||
require 'Blanket' |