Skip to content

Commit

Permalink
Implements VCR to speed up specs and avoid lots of hits on production…
Browse files Browse the repository at this point in the history
… service
  • Loading branch information
rafaelp committed Sep 26, 2013
1 parent 3f15991 commit a3c8a1b
Show file tree
Hide file tree
Showing 14 changed files with 2,573 additions and 59 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ group :development do
gem "bundler", "~> 1.3.5"
gem "jeweler", "~> 1.8.4"
end

group :test do
gem "vcr", "2.6.0"
gem "webmock", "1.13.0"
end
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ GEM
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.33)
addressable (2.3.5)
atomic (1.1.7)
builder (3.1.4)
crack (0.4.1)
safe_yaml (~> 0.9.0)
curb (0.8.3)
diff-lcs (1.2.4)
git (1.2.5)
Expand All @@ -35,9 +38,14 @@ GEM
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1)
safe_yaml (0.9.7)
thread_safe (0.1.0)
atomic
tzinfo (0.3.37)
vcr (2.6.0)
webmock (1.13.0)
addressable (>= 2.2.7)
crack (>= 0.3.2)

PLATFORMS
ruby
Expand All @@ -50,3 +58,5 @@ DEPENDENCIES
jeweler (~> 1.8.4)
rdoc (~> 3.12)
rspec
vcr (= 2.6.0)
webmock (= 1.13.0)
64 changes: 36 additions & 28 deletions spec/bitstamp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,50 @@

describe Bitstamp do

it 'should raise if not properly configured' do
-> { Bitstamp.sanity_check! }.should raise_error
end

it 'should not raise if properly configured' do
Bitstamp.setup do |config|
config.key = 'test'
config.secret = 'test'
describe :sanity_check! do
context 'not properly configured' do
it { -> { Bitstamp.sanity_check! }.should raise_error }
end
context 'properly configured' do
before {
Bitstamp.setup do |config|
config.key = 'test'
config.secret = 'test'
end
}
it { -> { Bitstamp.sanity_check! }.should_not raise_error }
end

-> { Bitstamp.sanity_check! }.should_not raise_error
end

it 'should have a orders helper method' do
Bitstamp.should respond_to :orders
end

it 'should have a ticker helper method' do
Bitstamp.ticker.should be_kind_of Bitstamp::Ticker
describe :orders do
it { should respond_to :orders }
end

it 'should list information about your balance' do
read_bitstamp_yaml

Bitstamp.balance.should be_kind_of Hash
describe :ticket, vcr: {cassette_name: 'bitstamp/ticker'} do
subject { Bitstamp.ticker }
it { should be_kind_of Bitstamp::Ticker }
its(:high) { should == "124.90" }
its(:last) { should == "124.89" }
its(:timestamp) { should == "1380232743" }
its(:bid) { should == "124.70" }
its(:volume) { should == "7603.35699992" }
its(:low) { should == "123.00" }
its(:ask) { should == "124.89" }
end

it 'should have a order_book method' do
Bitstamp.order_book.should be_kind_of Hash
describe :balance, vcr: {cassette_name: 'bitstamp/balance'} do
before { read_bitstamp_yaml }
subject { Bitstamp.balance }
it { should == {"btc_reserved"=>"0", "fee"=>"0.4000", "btc_available"=>"0", "usd_reserved"=>"0", "btc_balance"=>"0", "usd_balance"=>"6953.07", "usd_available"=>"6953.07"} }
end

it 'should have bids and asks in the order_book' do
order_book = Bitstamp.order_book
order_book.should have_key("asks")
order_book.should have_key("bids")
order_book["asks"].should be_kind_of Array
order_book["bids"].should be_kind_of Array
describe :order_book, vcr: {cassette_name: 'bitstamp/order_book'} do
let(:order_book) { Bitstamp.order_book }
subject { order_book }
it { should be_kind_of Hash }
it { should have_key("asks") }
it { should have_key("bids") }
it { order_book["asks"].should be_kind_of Array }
it { order_book["bids"].should be_kind_of Array }
end
end
22 changes: 5 additions & 17 deletions spec/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,9 @@ class Bitstamp::Coin < Bitstamp::Model;end
class Bitstamp::Coins < Bitstamp::Collection;end

describe Bitstamp::Coins do
let(:kojns) { Bitstamp::Coins.new }

it 'should have a name representing the class his name but not modules' do
kojns.name.should eq 'coin'
end

it 'module should reflect a singular form' do
kojns.module.should eq "bitstamp/coin"
end

it 'should have a model' do
kojns.model.should be Bitstamp::Coin
end

it 'should have an api end point' do
kojns.path.should eq "/api/coins"
end
subject { Bitstamp::Coins.new }
its(:name) { should eq 'coin' }
its(:module) { should eq "bitstamp/coin" }
its(:model) { should be Bitstamp::Coin }
its(:path) { should eq "/api/coins" }
end
63 changes: 63 additions & 0 deletions spec/fixtures/vcr_cassettes/bitstamp/balance.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a3c8a1b

Please sign in to comment.