optimus_prime 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +2 -0
- data/config.ru +4 -0
- data/lib/optimus_prime/server.rb +52 -0
- data/lib/optimus_prime/version.rb +3 -0
- data/lib/optimus_prime.rb +44 -0
- data/optimus_prime.gemspec +27 -0
- data/optimus_prime.log +705 -0
- data/spec/lib/optimus_prime_spec.rb +92 -0
- data/spec/spec_helper.rb +29 -0
- metadata +131 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
describe OptimusPrime do
|
2
|
+
|
3
|
+
let(:op) { OptimusPrime::Base.new }
|
4
|
+
|
5
|
+
it "primes an endpoint" do
|
6
|
+
expect( op.prime("test").status ).to eq 201
|
7
|
+
end
|
8
|
+
|
9
|
+
it "primes an endpoint with attributes" do
|
10
|
+
op.prime("test", "I am a response")
|
11
|
+
|
12
|
+
response = ::Faraday.get("http://localhost:7002/get/test")
|
13
|
+
expect( response.body ).to eq "I am a response"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "sets a content type" do
|
17
|
+
op.prime("test", "I am a response", content_type: :json)
|
18
|
+
|
19
|
+
response = ::Faraday.get("http://localhost:7002/get/test")
|
20
|
+
expect( response.headers["content-type"] ).to eq "application/json"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "retrieves a path containing attributes" do
|
24
|
+
op.prime("route/name", "<html><head><title>Response</title></head><body><h1>Hi</h1><body></html>", content_type: :html)
|
25
|
+
response = ::Faraday.get('http://localhost:7002/get/route/name')
|
26
|
+
|
27
|
+
expect(response.headers["content-type"]).to include("text/html")
|
28
|
+
expect(response.body).to include("<h1>Hi</h1>")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "retrieves a very nested path" do
|
32
|
+
op.prime("getUserProfile/queue/token/12345678", { username: 'Antonio', age: 21 }.to_json, content_type: :json)
|
33
|
+
response = ::Faraday.get('http://localhost:7002/get/getUserProfile/queue/token/12345678')
|
34
|
+
|
35
|
+
expect(JSON.parse(response.body)).to eq({ "username" => "Antonio", "age" => 21 })
|
36
|
+
end
|
37
|
+
|
38
|
+
it "retrieves from url with params" do
|
39
|
+
op.prime("getUser?id=10&queue=NaN", { username: "Test" }.to_json, content_type: :json)
|
40
|
+
response = ::Faraday.get('http://localhost:7002/get/getUser?id=10&queue=NaN')
|
41
|
+
|
42
|
+
expect( JSON.parse(response.body) ).to eq({ "username" => "Test" })
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns a 404 when endpoint is not found" do
|
46
|
+
response = ::Faraday.get('http://localhost:7002/get/iDoNotExist')
|
47
|
+
|
48
|
+
expect( response.status ).to eq 404
|
49
|
+
end
|
50
|
+
|
51
|
+
it "allows developers to change the response status code" do
|
52
|
+
op.prime("notFound", { username: "Test" }.to_json, content_type: :json, status_code: 404)
|
53
|
+
response = ::Faraday.get('http://localhost:7002/get/notFound')
|
54
|
+
|
55
|
+
expect( response.status ).to eq 404
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns 200 http status code as default" do
|
59
|
+
op.prime("continue", { username: "Test" }.to_json, content_type: :json)
|
60
|
+
response = ::Faraday.get('http://localhost:7002/get/continue')
|
61
|
+
|
62
|
+
expect( response.status ).to eq 200
|
63
|
+
end
|
64
|
+
|
65
|
+
it "handles POST requests" do
|
66
|
+
op.prime("user", { username: "Test" }.to_json, content_type: :json)
|
67
|
+
response = ::Faraday.post('http://localhost:7002/get/user')
|
68
|
+
|
69
|
+
expect( JSON.parse(response.body) ).to eq({ "username" => "Test" })
|
70
|
+
end
|
71
|
+
|
72
|
+
context "Starting and Stopping the server" do
|
73
|
+
it "starts the server" do
|
74
|
+
OptimusPrime.restart_server
|
75
|
+
expect( `ls ./tmp/pids` ).to include("optimus_prime.pid")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "stops the server" do
|
79
|
+
OptimusPrime.start_server
|
80
|
+
OptimusPrime.stop_server
|
81
|
+
expect( `ls ./tmp/pids` ).to_not include("optimus_prime.pid")
|
82
|
+
OptimusPrime.start_server
|
83
|
+
end
|
84
|
+
|
85
|
+
it "informs me if the server is already running" do
|
86
|
+
OptimusPrime.start_server
|
87
|
+
expect( OptimusPrime.start_server ).to include("Optimus is already priming :)")
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "optimus_prime"
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
begin
|
5
|
+
OptimusPrime.start_server
|
6
|
+
|
7
|
+
config.filter_run :focus
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
|
10
|
+
if config.files_to_run.one?
|
11
|
+
config.default_formatter = 'doc'
|
12
|
+
end
|
13
|
+
|
14
|
+
config.profile_examples = 10
|
15
|
+
|
16
|
+
config.order = :random
|
17
|
+
Kernel.srand config.seed
|
18
|
+
|
19
|
+
config.expect_with :rspec do |expectations|
|
20
|
+
expectations.syntax = :expect
|
21
|
+
end
|
22
|
+
|
23
|
+
config.mock_with :rspec do |mocks|
|
24
|
+
mocks.syntax = :expect
|
25
|
+
|
26
|
+
mocks.verify_partial_doubles = true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: optimus_prime
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Antonio Nalesso
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thin
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: " It allows developers to define endpoint, persist some data to be returned
|
84
|
+
when called the endpoint defined."
|
85
|
+
email:
|
86
|
+
- acnalesso@yahoo.co.uk
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- config.ru
|
98
|
+
- lib/optimus_prime.rb
|
99
|
+
- lib/optimus_prime/server.rb
|
100
|
+
- lib/optimus_prime/version.rb
|
101
|
+
- optimus_prime.gemspec
|
102
|
+
- optimus_prime.log
|
103
|
+
- spec/lib/optimus_prime_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: ''
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.2.2
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Create endpoints and persists data
|
129
|
+
test_files:
|
130
|
+
- spec/lib/optimus_prime_spec.rb
|
131
|
+
- spec/spec_helper.rb
|