Skip to content

Commit 8a71b9f

Browse files
committed
Merge pull request #2 from acumenbrands/add_tests
Add tests to cover functionality
2 parents de50f41 + 3923b5f commit 8a71b9f

File tree

8 files changed

+76
-6
lines changed

8 files changed

+76
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ spec/reports
1111
test/tmp
1212
test/version_tmp
1313
tmp
14+
Gemfile.lock
1415

1516
# YARD artifacts
1617
.yardoc

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
source :rubygems
22

3-
gemspec
3+
gemspec

kraken-io.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
1515
s.license = 'MIT'
1616
s.add_dependency('json')
1717
s.add_dependency('httparty')
18-
s.add_dependency('httmultiparty')
1918
s.add_dependency('multipart-post')
20-
s.add_dependency('rest-client')
21-
end
19+
s.add_development_dependency('rspec')
20+
s.add_development_dependency('webmock', '~> 1.17')
21+
end

lib/kraken-io.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require 'json'
22
require 'httparty'
3-
require 'rest-client'
43
require 'net/http/post/multipart'
54

65
module Kraken
@@ -48,4 +47,4 @@ def upload(params = {})
4847
end
4948
end
5049
end
51-
end
50+
end

spec/1px_f8fcff.gif

35 Bytes
Loading

spec/kraken-io_spec.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
require 'spec_helper'
2+
3+
describe Kraken::API do
4+
let(:result) do
5+
{
6+
"success" => true,
7+
"file_name" => "header.jpg",
8+
"original_size" => 324520,
9+
"kraked_size" => 165358,
10+
"saved_bytes" => 159162,
11+
"kraked_url" => "http://dl.kraken.io/ecdfa5c55d5668b1b5fe9e420554c4ee/header.jpg"
12+
}.to_json
13+
end
14+
15+
subject { Kraken::API.new(1,2) }
16+
describe '#url' do
17+
let(:expected_params) do
18+
{
19+
'url' => 'http://farts.gallery',
20+
'wait' => true,
21+
'auth' => { 'api_key' => 1, 'api_secret' => 2}
22+
}
23+
end
24+
25+
it 'provides a url to the kraken api' do
26+
stub_request(:post, "https://api.kraken.io/v1/url")
27+
.with(:body => expected_params.to_json).to_return(body: result)
28+
29+
subject.url(
30+
'url' => 'http://farts.gallery',
31+
'wait' => true
32+
)
33+
end
34+
end
35+
36+
describe '#upload' do
37+
let(:expected_params) do
38+
{
39+
'wait' => true,
40+
'auth' => { 'api_key' => 1, 'api_secret' => 2}
41+
}
42+
end
43+
44+
it 'uploads multipart form data to the server' do
45+
stub_request(:post, "https://api.kraken.io/v1/upload").with do |req|
46+
expect(req.body).to include(expected_params.to_json)
47+
expect(req.body).to include('filename="test.gif"')
48+
expect(req.headers['Content-Type']).to include('multipart/form-data')
49+
end.to_return(body: result)
50+
51+
subject.upload(
52+
'wait' => true,
53+
'file' => File.expand_path('test.gif', File.dirname(__FILE__))
54+
)
55+
end
56+
end
57+
end

spec/spec_helper.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'rubygems'
2+
require 'bundler/setup'
3+
4+
ROOT = File.expand_path('../..', __FILE__)
5+
Dir[File.join(ROOT, 'spec/support/**/*.rb')].each {|f| require f}
6+
$LOAD_PATH.unshift(File.expand_path('lib', ROOT))
7+
8+
require 'kraken-io'
9+
require 'webmock/rspec'
10+
11+
RSpec.configure do |config|
12+
config.mock_with :rspec
13+
end

spec/test.gif

35 Bytes
Loading

0 commit comments

Comments
 (0)