mirror of
https://github.com/seejohnrun/haste-client.git
synced 2025-12-15 16:25:57 +00:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83052b3504 | ||
|
|
e213bf2a22 | ||
|
|
34dd41eb04 | ||
|
|
57bd045ae9 | ||
|
|
ca19c71738 | ||
|
|
f918c81b38 | ||
|
|
7028107b9f | ||
|
|
65adc1ae4e | ||
|
|
a877692ab3 | ||
|
|
e8912c3456 | ||
|
|
45ce09bc88 | ||
|
|
0133b1549c | ||
|
|
1e2ceee70f | ||
|
|
2ca3df7a01 | ||
|
|
06d4afb1ca | ||
|
|
eeede13a3c | ||
|
|
6e9801e547 | ||
|
|
fb77a2e9f5 | ||
|
|
baeeb2874a | ||
|
|
32c4523e1c | ||
|
|
c307e8c904 | ||
|
|
1037d899b9 | ||
|
|
b5aa8fbacc | ||
|
|
1f3318adeb | ||
|
|
4c0e5f311d | ||
|
|
dab2d08f42 | ||
|
|
dfb69c5e0d | ||
|
|
f79b70da61 | ||
|
|
898884f07c | ||
|
|
3ba2c53587 | ||
|
|
0ea5e5c61c | ||
|
|
94b2a4fbec | ||
|
|
3a1d4045b3 | ||
|
|
82ae343455 | ||
|
|
22ea2e9e3c | ||
|
|
b6113d9fd3 | ||
|
|
a98f4d765e |
3
.bundle/config
Normal file
3
.bundle/config
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
BUNDLE_RETRY: "3"
|
||||
BUNDLE_JOBS: "4"
|
||||
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* @toptal/marketing-tools-2-eng
|
||||
33
.github/pull_request_template.md
vendored
Normal file
33
.github/pull_request_template.md
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
[ABC-1234](https://toptal-core.atlassian.net/browse/ABC-1234)
|
||||
|
||||
### Description
|
||||
|
||||
Describe the changes and motivations for the pull request, unless obvious from the title.
|
||||
|
||||
[Designs](https://share.abstract.com) (if applicable)
|
||||
|
||||
### How to test
|
||||
|
||||
- `bundle install`
|
||||
- FIXME: Add the steps describing how to test your changes manually
|
||||
|
||||
### Environment variables
|
||||
|
||||
Include a snapshot of the ENV vars used in your local env when this PR was created.
|
||||
|
||||
```
|
||||
PUBLIC_ENV_VAR=public-value
|
||||
GLOBAL_SECRET_ENV_VAR=xxx # Added in 1Password in Shared-Utilities-Environment group
|
||||
OWN_PRIVATE_ENV_VAR # Different for everyone
|
||||
```
|
||||
|
||||
### Acceptance Criteria
|
||||
|
||||
- [ ] Add acceptance criterias from Jira task [ABC-1234]
|
||||
|
||||
### Pre-merge checklist
|
||||
|
||||
- [ ] The PR relates to a single subject with a clear title and description in grammatically correct, complete sentences.
|
||||
- [ ] Verify that feature branch is up-to-date with `master` (if not - rebase it).
|
||||
- [ ] Double check the quality of [commit messages](http://chris.beams.io/posts/git-commit/).
|
||||
- [ ] A snapshot of the author's env vars has been added
|
||||
30
.github/workflows/close-inactive.yaml
vendored
Normal file
30
.github/workflows/close-inactive.yaml
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
name: Close inactive issues and PRs
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "30 1 * * *"
|
||||
|
||||
jobs:
|
||||
close-stale:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
steps:
|
||||
- uses: actions/stale@v6
|
||||
with:
|
||||
days-before-stale: 30
|
||||
days-before-close: 14
|
||||
stale-issue-label: "stale"
|
||||
stale-pr-label: "stale"
|
||||
|
||||
exempt-issue-labels: backlog,triage,nostale
|
||||
exempt-pr-labels: backlog,triage,nostale
|
||||
|
||||
stale-pr-message: "This PR is stale because it has been open for 30 days with no activity."
|
||||
close-pr-message: "This PR was closed because it has been inactive for 14 days since being marked as stale."
|
||||
|
||||
stale-issue-message: "This issue is stale because it has been open for 30 days with no activity."
|
||||
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
|
||||
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
27
.github/workflows/unit.yml
vendored
Normal file
27
.github/workflows/unit.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
name: Unit
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
unit_tests:
|
||||
name: Unit tests
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: '3.0'
|
||||
bundler-cache: true
|
||||
|
||||
- name: Run bundle install
|
||||
run: |
|
||||
gem install bundler
|
||||
bundle install --jobs 4 --retry 3
|
||||
|
||||
- name: Build and test with rspec
|
||||
run: bundle exec rspec spec
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@
|
||||
*.gem
|
||||
Gemfile.lock
|
||||
.rspec
|
||||
.DS_STORE
|
||||
|
||||
@@ -4,6 +4,6 @@ branches:
|
||||
- master
|
||||
rvm:
|
||||
- 1.8.7
|
||||
- 1.9.2
|
||||
- 1.9.3
|
||||
- 2.0.0
|
||||
- 2.4.0
|
||||
|
||||
8
LICENSE.txt
Normal file
8
LICENSE.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
Copyright 2022 Toptal LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
144
README.md
144
README.md
@@ -1,16 +1,14 @@
|
||||
# Haste Client
|
||||
|
||||
[](http://travis-ci.org/seejohnrun/haste-client)
|
||||
Haste-client is a simple client for uploading data to `Haste` server. All you need to do is to pipe data in STDIN:
|
||||
|
||||
haste-client is a simple client for uploading data to haste-server. All you do it pipe data in STDIN:
|
||||
`cat file | HASTE_SERVER_TOKEN=mytoken haste`
|
||||
|
||||
`cat file | haste`
|
||||
And once the output makes it to the server, it will print the `Haste` share page URL to STDOUT.
|
||||
|
||||
And once the output makes it to the server, it will print the URL to STDOUT.
|
||||
This can be combined with `pbcopy`, like:
|
||||
|
||||
This can be really really cool in combination with `pbcopy`, like:
|
||||
|
||||
* mac osx: `cat file | haste | pbcopy`
|
||||
* mac osx: `cat file | haste | pbcopy`
|
||||
* linux: `cat file | haste | xsel`
|
||||
|
||||
after which the contents of `file` will be accessible at a URL which has been copied to your pasteboard.
|
||||
@@ -21,36 +19,106 @@ after which the contents of `file` will be accessible at a URL which has been co
|
||||
gem install haste
|
||||
```
|
||||
|
||||
## Making uploading file contents easier
|
||||
## Configuration
|
||||
|
||||
If you supply a valid file path as argument #1 to the client, it will be uploaded:
|
||||
Most of the configuration is controlled by env variables. Here is the all environment variables that you can use.
|
||||
|
||||
``` bash
|
||||
```
|
||||
HASTE_SERVER: Haste server domain url
|
||||
HASTE_SERVER_TOKEN: Github authentication token
|
||||
HASTE_SHARE_SERVER: Haste share server domain url
|
||||
HASTE_USER: Basic authentication user name
|
||||
HASTE_PASS: Basic authentication user pass
|
||||
HASTE_SSL_CERTS: SSL certs path
|
||||
```
|
||||
|
||||
To add these environment variables, you should simply add them to your ~.bash_profile:
|
||||
|
||||
```bash
|
||||
export VARIABLE="value"
|
||||
```
|
||||
|
||||
### Authentication
|
||||
|
||||
If you are using default `HASTE_SERVER`, you need to have an GitHub authentication token.
|
||||
You can get the information about authentication and how to generate token [here](https://www.toptal.com/developers/hastebin/documentation)
|
||||
|
||||
After you have generated your token, you should add it to your ~.bash_profile:
|
||||
|
||||
```bash
|
||||
export HASTE_SERVER_TOKEN="mytoken"
|
||||
```
|
||||
|
||||
or you can add token to your command:
|
||||
|
||||
```bash
|
||||
cat file | HASTE_SERVER_TOKEN=mytoken haste`
|
||||
```
|
||||
|
||||
If your `Haste` installation requires http authentication, add the following to your ~.bash_profile:
|
||||
|
||||
```bash
|
||||
export HASTE_USER="myusername"
|
||||
export HASTE_PASS="mypassword"
|
||||
```
|
||||
|
||||
if you are using SSL, you will need to supply your certs path
|
||||
|
||||
```bash
|
||||
export HASTE_SSL_CERTS="/System/Library/OpenSSL/certs"
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
If you supply a valid file path as an argument to the client, it will be uploaded:
|
||||
|
||||
```bash
|
||||
# equivalent
|
||||
cat file | haste
|
||||
haste file
|
||||
```
|
||||
|
||||
## You can get the raw version
|
||||
### Different Haste server
|
||||
|
||||
Want the raw URL returned instead? (a plain-text version)?
|
||||
By default, `Haste` share page will point at `https://hastebin.com`.
|
||||
If you have haste-server configured to serve bins on a separate domain, you also need to set ENV['HASTE_SHARE_SERVER'] value to that domain.
|
||||
|
||||
``` bash
|
||||
cat file | haste --raw # or
|
||||
haste file --raw
|
||||
To set the value of share server, you can add the following to your ~.bash_profile:
|
||||
|
||||
```bash
|
||||
export HASTE_SHARE_SERVER="myshareserver"
|
||||
```
|
||||
|
||||
## Changing the location of your haste server
|
||||
### Different Haste server
|
||||
|
||||
By default, haste will point at `http://hastebin.com`. You can change this by setting the value of `ENV['HASTE_SERVER']` to the URL of your haste server. You can also use `alias` to make easy shortcuts if you commonly use a few hastes intermingled with each other. To do that, you'd put something like this into ~.bash_profile:
|
||||
By default, haste server will point at `https://hastebin.com`.
|
||||
You can change this by setting the value of `ENV['HASTE_SERVER']` to the URL of your `Haste` server.
|
||||
|
||||
``` bash
|
||||
alias work_haste="HASTE_SERVER=http://something.com haste"
|
||||
To set the value of server, you can add the following to your ~.bash_profile:
|
||||
|
||||
```bash
|
||||
export HASTE_SERVER="myserver"
|
||||
```
|
||||
|
||||
After which you can use `work_haste` to send hastes to that server instead.
|
||||
### Use with alias
|
||||
|
||||
## Use as a library
|
||||
You can also use `alias` to make easy shortcuts if you commonly use a few hastes intermingled with each other.
|
||||
To do that, you'd put something like this into ~.bash_profile:
|
||||
|
||||
``` bash
|
||||
alias work_haste="HASTE_SERVER=https://something.com HASTE_SERVER_TOKEN=mytoken haste"
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
``` bash
|
||||
alias work_haste="HASTE_SERVER_TOKEN=mytoken haste"
|
||||
```
|
||||
|
||||
After which you can use `work_haste` to send hastes to that server or with different tokens instead.
|
||||
|
||||
|
||||
### Use as a library
|
||||
|
||||
You can also use `Haste` as a library to upload hastes:
|
||||
|
||||
@@ -61,36 +129,6 @@ uploader.upload_raw 'this is my data' # key
|
||||
uploader.upload_path '/tmp/whaaaa' # key
|
||||
```
|
||||
|
||||
## Windows Support
|
||||
## Contributor License Agreement
|
||||
|
||||
If you'd like an alternative on Windows that supports functionality similar to `pbcopy`, check out Aidan Ryan's [WinHaste](https://github.com/ajryan/WinHaste) project.
|
||||
|
||||
## Lightweight Alternative
|
||||
|
||||
Han Boetes and @nickthename have contributed a simple shell-script alternative for those not interested in installing a RubyGem:
|
||||
|
||||
``` bash
|
||||
haste() { a=$(cat); curl -X POST -s -d "$a" http://hastebin.com/documents | awk -F '"' '{print "http://hastebin.com/"$4}'; }
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
``` bash
|
||||
cat file.txt | haste
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
John Crepezzi <john.crepezzi@gmail.com>
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright © 2011 John Crepezzi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
Licensed under the [MIT](https://github.com/toptal/haste-client/blob/master/LICENSE.txt 'https://github.com/toptal/haste-client/blob/main/LICENSE.txt') license.
|
||||
|
||||
9
Rakefile
9
Rakefile
@@ -1,7 +1,9 @@
|
||||
require 'rspec/core/rake_task'
|
||||
require File.dirname(__FILE__) + '/lib/haste/version'
|
||||
|
||||
task :build => :test do
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
|
||||
task :build => :spec do
|
||||
system "gem build haste.gemspec"
|
||||
end
|
||||
|
||||
@@ -12,8 +14,3 @@ task :release => :build do
|
||||
# push the gem
|
||||
system "gem push haste-#{Haste::VERSION}.gem"
|
||||
end
|
||||
|
||||
RSpec::Core::RakeTask.new(:test) do |t|
|
||||
t.pattern = 'spec/**/*_spec.rb'
|
||||
fail_on_error = true # be explicit
|
||||
end
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require 'bundler/setup'
|
||||
|
||||
require 'pathname'
|
||||
path = Pathname.new(__FILE__)
|
||||
require File.expand_path(File.dirname(path.realpath) + '/../lib/haste')
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
require 'rubygems'
|
||||
require File.dirname(__FILE__) + '/lib/haste/version'
|
||||
|
||||
spec = Gem::Specification.new do |s|
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'haste'
|
||||
s.author = 'John Crepezzi'
|
||||
s.author = 'Toptal'
|
||||
s.add_development_dependency('rspec')
|
||||
s.add_dependency('json')
|
||||
s.add_dependency('faraday')
|
||||
s.add_dependency('faraday', '~> 0.9')
|
||||
s.description = 'CLI Haste Client'
|
||||
s.email = 'john.crepezzi@gmail.com'
|
||||
s.license = 'MIT License'
|
||||
s.homepage = 'https://github.com/toptal/haste-client'
|
||||
s.email = 'open-source@toptal.com'
|
||||
s.executables = 'haste'
|
||||
s.files = Dir['lib/**/*.rb', 'haste']
|
||||
s.platform = Gem::Platform::RUBY
|
||||
|
||||
@@ -4,7 +4,13 @@ module Haste
|
||||
|
||||
# Create a new uploader
|
||||
def initialize
|
||||
@uploader = Uploader.new ENV['HASTE_SERVER']
|
||||
@uploader = Uploader.new(
|
||||
ENV['HASTE_SERVER'],
|
||||
ENV['HASTE_SERVER_TOKEN'],
|
||||
ENV['HASTE_SHARE_SERVER'],
|
||||
ENV['HASTE_USER'],
|
||||
ENV['HASTE_PASS'],
|
||||
ENV['HASTE_SSL_CERTS'])
|
||||
end
|
||||
|
||||
# And then handle the basic usage
|
||||
@@ -16,11 +22,7 @@ module Haste
|
||||
key = @uploader.upload_raw STDIN.readlines.join
|
||||
end
|
||||
# Put together a URL
|
||||
if ARGV.include?('--raw')
|
||||
url = "#{@uploader.server_url}/raw/#{key}"
|
||||
else
|
||||
url = "#{@uploader.server_url}/#{key}"
|
||||
end
|
||||
url = "#{@uploader.share_server_url}/share/#{key}"
|
||||
# And write data out
|
||||
if STDOUT.tty?
|
||||
STDOUT.puts url
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
require 'json'
|
||||
require 'faraday'
|
||||
require 'uri'
|
||||
|
||||
module Haste
|
||||
|
||||
DEFAULT_URL = 'http://hastebin.com'
|
||||
DEFAULT_SERVER_URL = 'https://hastebin.com'
|
||||
DEFAULT_SHARE_SERVER_URL = 'https://hastebin.com'
|
||||
|
||||
class Uploader
|
||||
|
||||
attr_reader :server_url
|
||||
attr_reader :server_url, :server_token, :share_server_url, :server_user, :server_pass, :ssl_certs
|
||||
|
||||
def initialize(server_url = nil)
|
||||
@server_url = server_url || Haste::DEFAULT_URL
|
||||
@server_url = @server_url.dup
|
||||
@server_url = @server_url.chop if @server_url.end_with?('/')
|
||||
def initialize(server_url = nil, server_token = nil, share_server_url = nil, server_user = nil, server_pass = nil, ssl_certs = nil)
|
||||
@server_url = generate_url(server_url || Haste::DEFAULT_SERVER_URL)
|
||||
@share_server_url = generate_url(share_server_url || Haste::DEFAULT_SHARE_SERVER_URL)
|
||||
|
||||
@server_user = server_user
|
||||
@server_token = server_token
|
||||
@server_pass = server_pass
|
||||
@ssl_certs = ssl_certs
|
||||
end
|
||||
|
||||
def generate_url(url)
|
||||
url = url.dup
|
||||
url = url.chop if url.end_with?('/')
|
||||
return url
|
||||
end
|
||||
|
||||
# Take in a path and return a key
|
||||
@@ -40,16 +52,42 @@ module Haste
|
||||
|
||||
private
|
||||
|
||||
def post_path
|
||||
parsed_uri = URI.parse(server_url)
|
||||
"#{parsed_uri.path}/documents"
|
||||
end
|
||||
|
||||
def do_post(data)
|
||||
connection.post('/documents', data)
|
||||
connection.post(post_path, data)
|
||||
end
|
||||
|
||||
def connection
|
||||
@connection ||= Faraday.new(:url => server_url) do |c|
|
||||
c.adapter Faraday.default_adapter
|
||||
@connection ||= connection_set
|
||||
end
|
||||
|
||||
def connection_set
|
||||
return connection_https if @ssl_certs
|
||||
connection_http
|
||||
end
|
||||
|
||||
def connection_http
|
||||
Faraday.new(:url => server_url) do |c|
|
||||
connection_config(c)
|
||||
end
|
||||
end
|
||||
|
||||
def connection_https
|
||||
Faraday.new(:url => server_url, :ssl => { :ca_path => @ssl_certs }) do |c|
|
||||
connection_config(c)
|
||||
end
|
||||
end
|
||||
|
||||
def connection_config(config)
|
||||
config.request :authorization, 'Bearer', @server_token if @server_token
|
||||
config.basic_auth(@server_user, @server_pass) if @server_user
|
||||
config.adapter Faraday.default_adapter
|
||||
end
|
||||
|
||||
def fail_with(msg)
|
||||
raise Exception.new(msg)
|
||||
end
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
module Haste
|
||||
|
||||
VERSION = '0.2.0'
|
||||
|
||||
VERSION = '0.3.0'
|
||||
end
|
||||
|
||||
@@ -23,12 +23,12 @@ describe Haste::Uploader do
|
||||
|
||||
before do
|
||||
ostruct = OpenStruct.new(:status => 200, :body => json)
|
||||
uploader.send(:connection).should_receive(:post).with('/documents', data).and_return(ostruct)
|
||||
expect(uploader.send(:connection)).to receive(:post).with('/documents', data).and_return(ostruct)
|
||||
end
|
||||
|
||||
it 'should get the key' do
|
||||
error_message.should be_nil # no error
|
||||
@key.should == 'hello'
|
||||
expect(error_message).to be_nil # no error
|
||||
expect(@key).to eq('hello')
|
||||
end
|
||||
|
||||
end
|
||||
@@ -39,11 +39,11 @@ describe Haste::Uploader do
|
||||
|
||||
before do
|
||||
ostruct = OpenStruct.new(:status => 200, :body => json)
|
||||
uploader.send(:connection).should_receive(:post).with('/documents', data).and_return(ostruct)
|
||||
expect(uploader.send(:connection)).to receive(:post).with('/documents', data).and_return(ostruct)
|
||||
end
|
||||
|
||||
it 'should get an error' do
|
||||
error_message.should start_with 'failure parsing response: '
|
||||
expect(error_message).to start_with('failure parsing response: ')
|
||||
end
|
||||
|
||||
end
|
||||
@@ -52,11 +52,11 @@ describe Haste::Uploader do
|
||||
|
||||
before do
|
||||
ostruct = OpenStruct.new(:status => 404, :body => 'ohno')
|
||||
uploader.send(:connection).should_receive(:post).with('/documents', data).and_return(ostruct)
|
||||
expect(uploader.send(:connection)).to receive(:post).with('/documents', data).and_return(ostruct)
|
||||
end
|
||||
|
||||
it 'should get an error' do
|
||||
error_message.should == 'failure uploading: ohno'
|
||||
expect(error_message).to eq('failure uploading: ohno')
|
||||
end
|
||||
|
||||
end
|
||||
@@ -65,11 +65,11 @@ describe Haste::Uploader do
|
||||
|
||||
before do
|
||||
error = Errno::ECONNREFUSED
|
||||
uploader.send(:connection).should_receive(:post).with('/documents', data).and_raise(error)
|
||||
expect(uploader.send(:connection)).to receive(:post).with('/documents', data).and_raise(error)
|
||||
end
|
||||
|
||||
it 'should get the key' do
|
||||
error_message.should == 'failure connecting: Connection refused'
|
||||
expect(error_message).to eq('failure connecting: Connection refused')
|
||||
end
|
||||
|
||||
end
|
||||
@@ -93,7 +93,7 @@ describe Haste::Uploader do
|
||||
let(:path) { nil }
|
||||
|
||||
it 'should have an error' do
|
||||
error_message.should == 'No input file given'
|
||||
expect(error_message).to eq('No input file given')
|
||||
end
|
||||
|
||||
end
|
||||
@@ -103,7 +103,7 @@ describe Haste::Uploader do
|
||||
let(:path) { '/tmp/why-do-you-have-a-file-called-john' }
|
||||
|
||||
it 'should have an error' do
|
||||
error_message.should == "#{path}: No such path"
|
||||
expect(error_message).to eq("#{path}: No such path")
|
||||
end
|
||||
|
||||
end
|
||||
@@ -115,11 +115,47 @@ describe Haste::Uploader do
|
||||
before { File.open(path, 'w') { |f| f.write(data) } }
|
||||
|
||||
before do
|
||||
uploader.should_receive(:upload_raw).with(data) # check
|
||||
expect(uploader).to receive(:upload_raw).with(data) # check
|
||||
end
|
||||
|
||||
it 'should not receive an error' do
|
||||
error_message.should be_nil
|
||||
expect(error_message).to be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe :post_path do
|
||||
|
||||
let(:post_path) { uploader.send(:post_path) }
|
||||
|
||||
context "when the server URL doesn't have a path" do
|
||||
|
||||
let(:base) { 'http://example.com/' }
|
||||
|
||||
it 'should return /documents' do
|
||||
expect(post_path).to eq('/documents')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "when the server URL has a path" do
|
||||
|
||||
let(:base) { 'http://example.com/friend' }
|
||||
|
||||
it 'should return /documents' do
|
||||
expect(post_path).to eq('/friend/documents')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "when the server URL has a path that ends with slash" do
|
||||
|
||||
let(:base) { 'http://example.com/friend/' }
|
||||
|
||||
it 'should return /documents appended to the path without a duplicate slash' do
|
||||
expect(post_path).to eq('/friend/documents')
|
||||
end
|
||||
|
||||
end
|
||||
@@ -129,13 +165,15 @@ describe Haste::Uploader do
|
||||
describe :server_url do
|
||||
|
||||
let(:server_url) { uploader.server_url }
|
||||
let(:share_server_url) { uploader.share_server_url }
|
||||
|
||||
context 'with default constructor' do
|
||||
|
||||
let(:base) { nil }
|
||||
|
||||
it 'should use the default url' do
|
||||
server_url.should == Haste::DEFAULT_URL
|
||||
it 'should use the default urls' do
|
||||
expect(server_url).to eq(Haste::DEFAULT_SERVER_URL)
|
||||
expect(share_server_url).to eq(Haste::DEFAULT_SHARE_SERVER_URL)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -148,11 +186,11 @@ describe Haste::Uploader do
|
||||
let(:base) { @string }
|
||||
|
||||
it 'should remove the slash' do
|
||||
server_url.should == @string.chop
|
||||
expect(server_url).to eq(@string.chop)
|
||||
end
|
||||
|
||||
it 'should not modify the original' do
|
||||
@string.should == 'hello/'
|
||||
expect(@string).to eq('hello/')
|
||||
end
|
||||
|
||||
end
|
||||
@@ -162,7 +200,7 @@ describe Haste::Uploader do
|
||||
let(:base) { 'hello' }
|
||||
|
||||
it 'should not chop the url' do
|
||||
server_url.should == base
|
||||
expect(server_url).to eq(base)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
require 'bundler/setup'
|
||||
require 'ostruct'
|
||||
|
||||
require File.dirname(__FILE__) + '/../lib/haste'
|
||||
|
||||
Reference in New Issue
Block a user