Easy-HTTP-Mock 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/Gemfile +15 -0
- data/Gemfile.lock +53 -0
- data/README.md +4 -0
- data/bin/easyhttpmock +16 -0
- data/bin/ehm +16 -0
- data/easy-http-mock.gemspec +15 -0
- data/example/bar.json +3 -0
- data/example/bar_haha.json +3 -0
- data/example/bar_hehe.json +3 -0
- data/example/test.yml +19 -0
- data/lib/easy-http-mock.rb +50 -0
- data/lib/easy-http-mock/version.rb +3 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 241a0e308933927c6a7d41d8efa7b9ed7fbd8f0e
|
4
|
+
data.tar.gz: 6ac203cc8965a6a62f6072a63cea1d793ad616e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa3d16c97374902a17250e9edfc33aa206d4f4eeb85e763f97d68d2033ae7bbf705a4dca5d2f7bfe7be66bbf4f0f2eba4795e5e2c3f4c4ba25864128081db42e
|
7
|
+
data.tar.gz: c4aed46a9123e30df78c31dff7839087256fd7bf0cccb02e19b34f0bc1cb4790a050a0475a58000b8b55f0067868e0d3238afa91fba495fdffb25ccfb0277a8e
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.2.5)
|
5
|
+
ffi (1.9.3)
|
6
|
+
listen (1.0.3)
|
7
|
+
rb-fsevent (>= 0.9.3)
|
8
|
+
rb-inotify (>= 0.9)
|
9
|
+
rb-kqueue (>= 0.2)
|
10
|
+
mini_portile (0.5.2)
|
11
|
+
nokogiri (1.6.0)
|
12
|
+
mini_portile (~> 0.5.0)
|
13
|
+
rack (1.5.2)
|
14
|
+
rack-protection (1.5.1)
|
15
|
+
rack
|
16
|
+
rack-test (0.6.2)
|
17
|
+
rack (>= 1.0)
|
18
|
+
rb-fsevent (0.9.3)
|
19
|
+
rb-inotify (0.9.2)
|
20
|
+
ffi (>= 0.5.0)
|
21
|
+
rb-kqueue (0.2.0)
|
22
|
+
ffi (>= 0.5.0)
|
23
|
+
rerun (0.8.2)
|
24
|
+
listen (~> 1.0.3)
|
25
|
+
rspec (2.14.1)
|
26
|
+
rspec-core (~> 2.14.0)
|
27
|
+
rspec-expectations (~> 2.14.0)
|
28
|
+
rspec-mocks (~> 2.14.0)
|
29
|
+
rspec-core (2.14.7)
|
30
|
+
rspec-expectations (2.14.4)
|
31
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
32
|
+
rspec-html-matchers (0.4.3)
|
33
|
+
nokogiri (>= 1.4.4)
|
34
|
+
rspec (>= 2.0.0)
|
35
|
+
rspec-mocks (2.14.4)
|
36
|
+
shotgun (0.9)
|
37
|
+
rack (>= 1.0)
|
38
|
+
sinatra (1.4.4)
|
39
|
+
rack (~> 1.4)
|
40
|
+
rack-protection (~> 1.4)
|
41
|
+
tilt (~> 1.3, >= 1.3.4)
|
42
|
+
tilt (1.4.1)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
rack-test
|
49
|
+
rerun
|
50
|
+
rspec
|
51
|
+
rspec-html-matchers
|
52
|
+
shotgun
|
53
|
+
sinatra
|
data/README.md
ADDED
data/bin/easyhttpmock
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'easy-http-mock'
|
4
|
+
options = {}
|
5
|
+
|
6
|
+
OptionParser.new { |op|
|
7
|
+
op.banner = "Usage: #{File.basename $0} [options] config_file"
|
8
|
+
op.on('-p', '--port [PORT]', Integer, 'set the port') { |port| options[:port] = port }
|
9
|
+
op.on('-o', '--addr [ADDR]', 'set the host') { |val| options[:addr] = val }
|
10
|
+
op.on('-h', '--help', 'show this usage') { puts op; exit }
|
11
|
+
}.parse!(ARGV)
|
12
|
+
|
13
|
+
config = ARGV[0]
|
14
|
+
abort "configuration #{config} not found" unless File.exist? config
|
15
|
+
|
16
|
+
EasyHTTPMock.start(config, options)
|
data/bin/ehm
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'easy-http-mock'
|
4
|
+
options = {}
|
5
|
+
|
6
|
+
OptionParser.new { |op|
|
7
|
+
op.banner = "Usage: #{File.basename $0} [options] config_file"
|
8
|
+
op.on('-p', '--port [PORT]', Integer, 'set the port') { |port| options[:port] = port }
|
9
|
+
op.on('-o', '--addr [ADDR]', 'set the host') { |val| options[:addr] = val }
|
10
|
+
op.on('-h', '--help', 'show this usage') { puts op; exit }
|
11
|
+
}.parse!(ARGV)
|
12
|
+
|
13
|
+
config = ARGV[0]
|
14
|
+
abort "configuration #{config} not found" unless File.exist? config
|
15
|
+
|
16
|
+
EasyHTTPMock.start(config, options)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
require 'easy-http-mock/version'
|
3
|
+
|
4
|
+
Gem::Specification.new 'Easy-HTTP-Mock', EasyHTTPMock::VERSION do |s|
|
5
|
+
s.description = 'Easy HTTP Mock is a tool aim at quickly mock http service'
|
6
|
+
s.summary = 'Mock HTTP service at minutes'
|
7
|
+
s.authors = ['Wang Chao']
|
8
|
+
s.email = 'cwang8023@gmail.com'
|
9
|
+
s.homepage = 'https://github.com/charleyw/Easy-HTTP-Mock'
|
10
|
+
s.license = 'MIT'
|
11
|
+
s.files = `git ls-files`.split("\n") - %w[.gitignore .travis.yml .ruby-version .ruby-gemset test.yml]
|
12
|
+
s.test_files = s.files.select { |p| p =~ /^spec\/.*_spec.rb/ }
|
13
|
+
s.executables = ['ehm', 'easyhttpmock']
|
14
|
+
s.add_dependency 'sinatra', '~> 1.4.4'
|
15
|
+
end
|
data/example/bar.json
ADDED
data/example/test.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
- &bar
|
3
|
+
request: &bar_request
|
4
|
+
path: /bar
|
5
|
+
response: bar.json
|
6
|
+
-
|
7
|
+
request:
|
8
|
+
<<: *bar_request
|
9
|
+
query:
|
10
|
+
param_one: haha
|
11
|
+
param_two: blabla
|
12
|
+
response: bar_haha.json
|
13
|
+
-
|
14
|
+
request:
|
15
|
+
<<: *bar_request
|
16
|
+
query:
|
17
|
+
param_three: hehe
|
18
|
+
response: bar_hehe.json
|
19
|
+
...
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'sinatra'
|
5
|
+
|
6
|
+
class EasyHTTPMock < Sinatra::Base
|
7
|
+
set(:query) do |query_params|
|
8
|
+
condition do
|
9
|
+
query_params.detect do |key, value|
|
10
|
+
(!params.has_key? key) || params[key] != value
|
11
|
+
end.nil? ? true : false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def start(config, options)
|
17
|
+
@mocking_config_file = config
|
18
|
+
config_sinatra(options)
|
19
|
+
begin
|
20
|
+
define_mock(parsing_configuration(config))
|
21
|
+
rescue Exception => e
|
22
|
+
abort "Got exception when define mocked http service:\n#{e}"
|
23
|
+
end
|
24
|
+
run!
|
25
|
+
end
|
26
|
+
|
27
|
+
def config_sinatra(options)
|
28
|
+
[:port, :addr].each { |key| set key, options[key] if options.key? key }
|
29
|
+
end
|
30
|
+
|
31
|
+
def parsing_configuration(config_file)
|
32
|
+
settings = YAML.load_file config_file
|
33
|
+
settings.sort do |x, y|
|
34
|
+
x['request'].size < y['request'].size ? 1 : -1
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def define_mock(conf)
|
40
|
+
conf.each do |service|
|
41
|
+
requestConf, responseConf = service['request'], service['response']
|
42
|
+
base_path = File.dirname(@mocking_config_file)
|
43
|
+
get requestConf.delete('path'), requestConf.inject({}) { |h, (k, v)| h[k] = [v]; h} do
|
44
|
+
File.read(base_path + '/' + responseConf)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Easy-HTTP-Mock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wang Chao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sinatra
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.4
|
27
|
+
description: Easy HTTP Mock is a tool aim at quickly mock http service
|
28
|
+
email: cwang8023@gmail.com
|
29
|
+
executables:
|
30
|
+
- ehm
|
31
|
+
- easyhttpmock
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- README.md
|
38
|
+
- bin/easyhttpmock
|
39
|
+
- bin/ehm
|
40
|
+
- easy-http-mock.gemspec
|
41
|
+
- example/bar.json
|
42
|
+
- example/bar_haha.json
|
43
|
+
- example/bar_hehe.json
|
44
|
+
- example/test.yml
|
45
|
+
- lib/easy-http-mock.rb
|
46
|
+
- lib/easy-http-mock/version.rb
|
47
|
+
homepage: https://github.com/charleyw/Easy-HTTP-Mock
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.0.6
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Mock HTTP service at minutes
|
71
|
+
test_files: []
|