servme 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/servme/service.rb +2 -2
- data/lib/servme/version.rb +1 -1
- data/servme.gemspec +6 -2
- data/spec/lib/servme/service_spec.rb +43 -0
- data/spec/lib/servme/service_stubbing_spec.rb +71 -0
- data/spec/spec_helper.rb +14 -0
- metadata +57 -3
data/README.md
CHANGED
@@ -43,7 +43,7 @@ before(:each) do
|
|
43
43
|
:login => "todd",
|
44
44
|
:password => "scotch"
|
45
45
|
}
|
46
|
-
}).respond_with(:token => "1234567890")
|
46
|
+
}).respond_with(:token => "1234567890")
|
47
47
|
end
|
48
48
|
```
|
49
49
|
|
@@ -60,7 +60,7 @@ before(:each) do
|
|
60
60
|
:login => "todd",
|
61
61
|
:password => "scotch"
|
62
62
|
}
|
63
|
-
}).error_with(401)
|
63
|
+
}).error_with(401)
|
64
64
|
end
|
65
65
|
```
|
66
66
|
|
data/lib/servme/service.rb
CHANGED
@@ -27,7 +27,7 @@ module Servme
|
|
27
27
|
|
28
28
|
def format_response(response)
|
29
29
|
body = json?(response) ? JSON::dump(response[:data]) : response[:data]
|
30
|
-
[response[:status_code], response[:headers],
|
30
|
+
[response[:status_code], response[:headers], body]
|
31
31
|
end
|
32
32
|
|
33
33
|
def json?(response)
|
@@ -48,7 +48,7 @@ module Servme
|
|
48
48
|
def self.stub(config)
|
49
49
|
(@@stubbings[config[:url]] ||= {}).tap do |urls|
|
50
50
|
(urls[config[:method] || :get] ||= {}).tap do |methods|
|
51
|
-
methods[stringify_keys(config[:params]
|
51
|
+
methods[stringify_keys(config[:params] || {})] = {
|
52
52
|
:data => config[:response],
|
53
53
|
:headers => DEFAULT_HEADERS.merge(config[:headers] || {}),
|
54
54
|
:status_code => config[:status_code] || 200
|
data/lib/servme/version.rb
CHANGED
data/servme.gemspec
CHANGED
@@ -17,6 +17,10 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
["json","sinatra",
|
21
|
-
|
20
|
+
["json","sinatra","thin"].each { |d| gem.add_runtime_dependency d }
|
21
|
+
|
22
|
+
gem.add_development_dependency "rspec"
|
23
|
+
gem.add_development_dependency "rspec-given", '1.4.2'
|
24
|
+
gem.add_development_dependency "rack-test"
|
25
|
+
# gem.add_development_dependency "debugger"
|
22
26
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Servme::Service do
|
4
|
+
def app
|
5
|
+
Servme::Service
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "default responses" do
|
9
|
+
shared_examples_for "default responses" do
|
10
|
+
Then { last_response.headers['Content-Type'].should == 'application/json' }
|
11
|
+
Then { last_response.status.should == 404 }
|
12
|
+
Then do
|
13
|
+
last_response.body.should be_json({
|
14
|
+
:error => "Servme doesn't know how to respond to this request",
|
15
|
+
:request => {
|
16
|
+
:method => method,
|
17
|
+
:params => {
|
18
|
+
:like => "dance"
|
19
|
+
},
|
20
|
+
:path => "/do/stuff"
|
21
|
+
}
|
22
|
+
})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#get" do
|
27
|
+
it_behaves_like "default responses" do
|
28
|
+
Given(:method) { "get" }
|
29
|
+
When { get('/do/stuff?like=dance') }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#post" do
|
34
|
+
it_behaves_like "default responses" do
|
35
|
+
Given(:method) { "post" }
|
36
|
+
When { post('/do/stuff', {:like => "dance"}) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Servme
|
4
|
+
describe ServiceStubbing do
|
5
|
+
def app
|
6
|
+
Service
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "json responses" do
|
10
|
+
Given do
|
11
|
+
ServiceStubbing.new({
|
12
|
+
:url => "/foo",
|
13
|
+
:method => :get,
|
14
|
+
:params => {
|
15
|
+
:bar => "baz"
|
16
|
+
}
|
17
|
+
}).respond_with(:woot? => "w00t!")
|
18
|
+
end
|
19
|
+
|
20
|
+
context "stubbing met" do
|
21
|
+
When { get('/foo?bar=baz') }
|
22
|
+
Then { last_response.status.should == 200 }
|
23
|
+
|
24
|
+
Then { last_response.body.should be_json :woot? => "w00t!" }
|
25
|
+
end
|
26
|
+
|
27
|
+
context "stubbing not met" do
|
28
|
+
context "wrong params" do
|
29
|
+
When { get('/foo?bar=bam') }
|
30
|
+
Then { last_response.status.should == 404 }
|
31
|
+
end
|
32
|
+
context "wrong method" do
|
33
|
+
When { post('/foo', :bar => "baz") }
|
34
|
+
Then { last_response.status.should == 404 }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "status code responses" do
|
41
|
+
Given do
|
42
|
+
ServiceStubbing.new({
|
43
|
+
:url => "/bizness/stuff",
|
44
|
+
:method => :post,
|
45
|
+
:params => {
|
46
|
+
:bizness => "true",
|
47
|
+
:money => "12"
|
48
|
+
}
|
49
|
+
}).error_with(333)
|
50
|
+
end
|
51
|
+
When { post('/bizness/stuff', { :bizness => true, :money => 12 }) }
|
52
|
+
Then { last_response.status.should == 333 }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "non-json responses" do
|
56
|
+
Given do
|
57
|
+
ServiceStubbing.new({
|
58
|
+
:url => "/index",
|
59
|
+
:method => :get,
|
60
|
+
:headers => {
|
61
|
+
'Content-Type' => "application/html"
|
62
|
+
}
|
63
|
+
}).respond_with("<html>hi</html>")
|
64
|
+
end
|
65
|
+
When { get('/index') }
|
66
|
+
Then { last_response.body.should == "<html>hi</html>" }
|
67
|
+
Then { last_response.headers['Content-Type'].should == "application/html" }
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'servme'
|
2
|
+
|
3
|
+
require 'rack/test'
|
4
|
+
require 'rspec/given'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.include Rack::Test::Methods
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec::Matchers.define :be_json do |expected|
|
11
|
+
match do |actual|
|
12
|
+
actual == JSON::dump(expected)
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -59,6 +59,54 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec-given
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - '='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.4.2
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - '='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.4.2
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rack-test
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
62
110
|
description: a simple test server for stubbing API responses
|
63
111
|
email:
|
64
112
|
- searls@gmail.com
|
@@ -77,6 +125,9 @@ files:
|
|
77
125
|
- lib/servme/service_stubbing.rb
|
78
126
|
- lib/servme/version.rb
|
79
127
|
- servme.gemspec
|
128
|
+
- spec/lib/servme/service_spec.rb
|
129
|
+
- spec/lib/servme/service_stubbing_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
80
131
|
homepage: https://github.com/testdouble/servme
|
81
132
|
licenses: []
|
82
133
|
post_install_message:
|
@@ -102,4 +153,7 @@ signing_key:
|
|
102
153
|
specification_version: 3
|
103
154
|
summary: Servme lets you stub server responses by standing-in for some remote system
|
104
155
|
your code under test depends on
|
105
|
-
test_files:
|
156
|
+
test_files:
|
157
|
+
- spec/lib/servme/service_spec.rb
|
158
|
+
- spec/lib/servme/service_stubbing_spec.rb
|
159
|
+
- spec/spec_helper.rb
|