faraday-for_test 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.pryrc +1 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +10 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/faraday-for_test.gemspec +28 -0
- data/lib/faraday/for_test/configuration.rb +12 -0
- data/lib/faraday/for_test/proxy.rb +28 -0
- data/lib/faraday/for_test/response/assertion.rb +23 -0
- data/lib/faraday/for_test/response/dumper.rb +52 -0
- data/lib/faraday/for_test/response/formatter.rb +64 -0
- data/lib/faraday/for_test/response.rb +18 -0
- data/lib/faraday/for_test.rb +19 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1fed5e88399502ca9836ada430fd85f511196613
|
4
|
+
data.tar.gz: 20fb405fc40505568e0d84235e10c0a8c4e69628
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95b9ce1df9400884f7cca5b6c4027900cf9ddca40374422ac2b15e1df0be4d4e04c13c99619ac43c6ecaa326bca0a1b1758c2b5be6d4ed3aae200b6011522f1e
|
7
|
+
data.tar.gz: 63e79d200841fbc6e0106feaf9028ef7bfa4b3de8d2cbfde94093c861085b92c7c872d58505c8da5a2fd69e2bdcde17fda60bda71c89b048a44c08369a883172
|
data/.gitignore
ADDED
data/.pryrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "faraday/for_test"
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 okitan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Faraday::ForTest
|
2
|
+
|
3
|
+
Convinient functions for test
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'faraday-for_test'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install faraday-for_test
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/okitan/faraday-for_test. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
28
|
+
|
29
|
+
|
30
|
+
## License
|
31
|
+
|
32
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "faraday/for_test"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "faraday-for_test"
|
5
|
+
spec.version = File.read(File.expand_path("VERSION", File.dirname(__FILE__))).chomp
|
6
|
+
spec.authors = ["okitan"]
|
7
|
+
spec.email = ["okitakunio@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "convinient functions for api test"
|
10
|
+
spec.description = "convinient functions for api test"
|
11
|
+
spec.homepage = "https://github.com/okitan/faraday-for_test"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
+
spec.bindir = "exe"
|
16
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "faraday", ">= 0.8"
|
20
|
+
spec.add_dependency "rack"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
# debub
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "tapp"
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Faraday::ForTest
|
2
|
+
class Proxy < BasicObject
|
3
|
+
attr_reader :connection
|
4
|
+
|
5
|
+
def initialize(connection)
|
6
|
+
@connection = connection
|
7
|
+
end
|
8
|
+
|
9
|
+
# proxy every method
|
10
|
+
def method_missing(name, *args, &block)
|
11
|
+
if @connection.respond_to?(name)
|
12
|
+
maybe_response = @connection.__send__(name, *args, &block)
|
13
|
+
|
14
|
+
if maybe_response.is_a?(::Faraday::Response)
|
15
|
+
response = ::Faraday::ForTest::Response.new(maybe_response)
|
16
|
+
|
17
|
+
# TODO: configurable to find out request_params from args
|
18
|
+
response.request_params = args.find {|e| e.is_a?(::Array) || e.is_a?(::Hash) || e.is_a?(::NilClass) }
|
19
|
+
response
|
20
|
+
else
|
21
|
+
maybe_response
|
22
|
+
end
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Faraday::ForTest
|
2
|
+
class Response
|
3
|
+
module Assertion
|
4
|
+
class AssertionError < StandardError
|
5
|
+
attr_accessor :response
|
6
|
+
|
7
|
+
def initialize(response)
|
8
|
+
@response = response
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def must_succeed
|
13
|
+
unless success?
|
14
|
+
raise AssertionError.new(self)
|
15
|
+
else
|
16
|
+
self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
include Assertion
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Faraday::ForTest
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :dump_always
|
4
|
+
attr_accessor :dump_if_assert_failed
|
5
|
+
end
|
6
|
+
|
7
|
+
class Response
|
8
|
+
module Dumper
|
9
|
+
# TODO: enable configuration
|
10
|
+
def dump(pretty = true)
|
11
|
+
warn "-------- 8x [req] x8 --------"
|
12
|
+
warn request_line
|
13
|
+
warn request_headers
|
14
|
+
warn "\n"
|
15
|
+
warn request_body(pretty)
|
16
|
+
warn "-------- 8x [res] x8 --------"
|
17
|
+
warn status_line
|
18
|
+
warn response_headers
|
19
|
+
warn "\n"
|
20
|
+
warn response_body(pretty)
|
21
|
+
warn "-------- 8x [end] x8 --------"
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def dump_once
|
27
|
+
dump unless @dumped
|
28
|
+
@dumped = true
|
29
|
+
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
# override
|
34
|
+
def initialize(response)
|
35
|
+
super
|
36
|
+
dump_once if Faraday::ForTest.configuration.dump_always
|
37
|
+
end
|
38
|
+
|
39
|
+
# override assertion
|
40
|
+
def must_succeed
|
41
|
+
begin
|
42
|
+
super
|
43
|
+
rescue Faraday::ForTest::Response::Assertion::AssertionError => e
|
44
|
+
dump_once if Faraday::ForTest.configuration.dump_if_assert_failed
|
45
|
+
raise e
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
prepend Dumper
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "rack/utils"
|
2
|
+
|
3
|
+
module Faraday::ForTest
|
4
|
+
class Configuration
|
5
|
+
def body_formatters
|
6
|
+
@body_formatters ||= {
|
7
|
+
"application/x-www-form-urlencoded" => Rack::Utils.method(:build_query)
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_body_formatter(key, proc = nil, &block)
|
12
|
+
body_formatters[key] = block_given? ? block : proc
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Response
|
17
|
+
module Formatter
|
18
|
+
# TODO: actual http version
|
19
|
+
def request_line
|
20
|
+
[ env[:method].upcase, env[:url], "HTTP/1.1" ].join(" ") + "\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
def request_headers
|
24
|
+
env[:request_headers].map {|k, v| "#{k}: #{v}" }.join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
# TODO: configuraable
|
28
|
+
def request_body(pretty = false)
|
29
|
+
if request_params && !request_params.empty?
|
30
|
+
if formatter = Faraday::ForTest.configuration.body_formatters.find {|k, v| env[:request_headers]["Content-Type"] =~ /#{k}/ }
|
31
|
+
formatter.last.call(request_params)
|
32
|
+
else
|
33
|
+
request_params.inspect
|
34
|
+
end
|
35
|
+
else
|
36
|
+
""
|
37
|
+
end + "\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
# TODO: reason-phase
|
41
|
+
def status_line
|
42
|
+
[ "HTTP/1.1", status ].join(" ") + "\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
def response_headers
|
46
|
+
headers.map {|k, v| "#{k}: #{v}" }.join("\n")
|
47
|
+
end
|
48
|
+
|
49
|
+
def response_body(pretty = false)
|
50
|
+
if body && !body.empty?
|
51
|
+
if formatter = Faraday::ForTest.configuration.body_formatters.find {|k, v| headers["content-type"] =~ /#{k}/ }
|
52
|
+
formatter.last.call(body)
|
53
|
+
else
|
54
|
+
body.inspect
|
55
|
+
end
|
56
|
+
else
|
57
|
+
""
|
58
|
+
end + "\n"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
include Formatter
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module Faraday::ForTest
|
4
|
+
class Response < SimpleDelegator
|
5
|
+
require "faraday/for_test/response/assertion"
|
6
|
+
require "faraday/for_test/response/formatter"
|
7
|
+
|
8
|
+
# this overwride assertion
|
9
|
+
require "faraday/for_test/response/dumper"
|
10
|
+
|
11
|
+
attr_accessor :request_params
|
12
|
+
|
13
|
+
def initialize(response)
|
14
|
+
@respone = response
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
module ForTest
|
5
|
+
require "faraday/for_test/configuration"
|
6
|
+
|
7
|
+
require "faraday/for_test/proxy"
|
8
|
+
require "faraday/for_test/response"
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def configuration
|
12
|
+
Configuration.instance
|
13
|
+
end
|
14
|
+
def configure(&block)
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faraday-for_test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- okitan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: tapp
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: convinient functions for api test
|
98
|
+
email:
|
99
|
+
- okitakunio@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".pryrc"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CHANGELOG.md
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- VERSION
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- faraday-for_test.gemspec
|
117
|
+
- lib/faraday/for_test.rb
|
118
|
+
- lib/faraday/for_test/configuration.rb
|
119
|
+
- lib/faraday/for_test/proxy.rb
|
120
|
+
- lib/faraday/for_test/response.rb
|
121
|
+
- lib/faraday/for_test/response/assertion.rb
|
122
|
+
- lib/faraday/for_test/response/dumper.rb
|
123
|
+
- lib/faraday/for_test/response/formatter.rb
|
124
|
+
homepage: https://github.com/okitan/faraday-for_test
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.5.2
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: convinient functions for api test
|
148
|
+
test_files: []
|