servme 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07c16f51dfc2009674f65d3e0e46b44bba790b64
4
+ data.tar.gz: 87adfbbe56a82ce3f6e722cb91d9b1a5afee1608
5
+ SHA512:
6
+ metadata.gz: 3c0eed524cc2ab2ef695c60bcb18650fc90a9469e025f807b2e54665cf3fa0116c72bb15094390f189af865d4792d4b44f652873da0808874c3038fec94dcd2e
7
+ data.tar.gz: 9f632d7e3b165a8e62d569646f9878ca52461fa9ae73ee01c88d695415894a325064d684780d8da915d3d7a0f847214f85db68e965616122165c65b44a3d9503
@@ -0,0 +1 @@
1
+ script: "bundle exec rspec"
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Servme
2
2
 
3
+ [![Build Status](https://travis-ci.org/testdouble/servme.png?branch=master)](https://travis-ci.org/testdouble/servme)
4
+
3
5
  Servme is very rough and not ready for public consumption.
4
6
 
5
7
  If you're still reading, servme is a test library that lets you replace some server that your application depends on with an easy-to-stub Sinatra app that can be run in a thread that's subordinate to your tests.
@@ -6,14 +6,15 @@ module Servme
6
6
  }
7
7
 
8
8
  DEFAULT_OPTIONS = {
9
- :static_file_root_path => "dist"
9
+ :static_file_root_path => "dist",
10
+ :static_file_vdir => //
10
11
  }
11
12
 
12
13
  attr_accessor :sinatra_app, :options
13
14
 
14
15
  def initialize(sinatra_app, opts)
15
16
  @sinatra_app = sinatra_app
16
- @options = DEFAULT_OPTIONS.merge(opts)
17
+ @options = DEFAULT_OPTIONS.merge(opts.reject { |k,v| v.nil? })
17
18
  end
18
19
 
19
20
  def stubber
@@ -21,7 +22,9 @@ module Servme
21
22
  end
22
23
 
23
24
  def respond(request)
24
- static_file = File.join(options[:static_file_root_path], request.path)
25
+ relative_path_on_disk = request.path.sub(options[:static_file_vdir], '')
26
+
27
+ static_file = File.join(options[:static_file_root_path], relative_path_on_disk)
25
28
  stub = stubber.stub_for_request(request)
26
29
  if (stub)
27
30
  format_response(stub)
@@ -15,8 +15,22 @@ module Servme
15
15
  responder.respond(request)
16
16
  end
17
17
 
18
+ put '*' do
19
+ responder.respond(request)
20
+ end
21
+
22
+ delete '*' do
23
+ responder.respond(request)
24
+ end
25
+
18
26
  def responder
19
- @responder ||= Responder.new(self, {})
27
+ @responder ||= Responder.new(
28
+ self,
29
+ {
30
+ :static_file_root_path => settings.respond_to?(:static_file_root_path) ? settings.static_file_root_path : nil,
31
+ :static_file_vdir => settings.respond_to?(:static_file_vdir) ? settings.static_file_vdir : nil
32
+ }
33
+ )
20
34
  end
21
35
 
22
36
  def self.clear
@@ -1,3 +1,3 @@
1
1
  module Servme
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -46,4 +46,21 @@ describe Servme::Responder do
46
46
 
47
47
  JSON.parse(response.last).should == {"foo" => "bar"}
48
48
  end
49
+
50
+ context "when the responder is configured with some static file options" do
51
+ subject do
52
+ Servme::Responder.new(sinatra_app,
53
+ {
54
+ :static_file_root_path => 'build',
55
+ :static_file_vdir => '/vdir',
56
+ })
57
+ end
58
+
59
+ it "returns a static file response for a file in a vdir" do
60
+ File.stub(:exists? => true)
61
+ sinatra_app.should_receive(:send_file).with("build/foo")
62
+
63
+ subject.respond(stub(:path => "/vdir/foo", :request_method => "GET"))
64
+ end
65
+ end
49
66
  end
@@ -36,8 +36,20 @@ describe Servme::Service do
36
36
  When { post('/do/stuff', {:like => "dance"}) }
37
37
  end
38
38
  end
39
- end
40
39
 
40
+ describe "#put" do
41
+ it_behaves_like "default responses" do
42
+ Given(:method) { "put" }
43
+ When { put('/do/stuff', { :like => "dance" }) }
44
+ end
45
+ end
41
46
 
47
+ describe "#delete" do
48
+ it_behaves_like "default responses" do
49
+ Given(:method) { "delete" }
50
+ When { delete('/do/stuff', { :like => "dance" }) }
51
+ end
52
+ end
53
+ end
42
54
 
43
- end
55
+ end
@@ -6,35 +6,63 @@ module Servme
6
6
  Service
7
7
  end
8
8
 
9
- describe "json responses" do
9
+ shared_examples_for "stubbing met" do
10
10
  Given do
11
- ServiceStubbing.new({
11
+ ServiceStubbing.new(request).respond_with(:woot? => "w00t!")
12
+ end
13
+
14
+ When { send(verb, '/foo', :bar => 'baz') }
15
+ Then { last_response.status.should == 200 }
16
+
17
+ Then { last_response.body.should be_json :woot? => "w00t!" }
18
+ end
19
+
20
+ context "GET" do
21
+ let(:verb) { :get }
22
+ let(:request) {
23
+ {
12
24
  :url => "/foo",
13
25
  :method => :get,
14
26
  :params => {
15
27
  :bar => "baz"
16
28
  }
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 }
29
+ }
30
+ }
31
+ it_behaves_like "stubbing met"
23
32
 
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 }
33
+ describe "json responses" do
34
+ Given do
35
+ ServiceStubbing.new(request).respond_with(:woot? => "w00t!")
31
36
  end
32
- context "wrong method" do
33
- When { post('/foo', :bar => "baz") }
34
- Then { last_response.status.should == 404 }
37
+
38
+ context "stubbing not met" do
39
+ context "wrong params" do
40
+ When { get('/foo?bar=bam') }
41
+ Then { last_response.status.should == 404 }
42
+ end
43
+ context "wrong method" do
44
+ When { post('/foo', :bar => "baz") }
45
+ Then { last_response.status.should == 404 }
46
+ end
35
47
  end
48
+
36
49
  end
50
+ end
37
51
 
52
+ ["GET", "PUT", "POST", "DELETE"].each do |http_verb|
53
+ context http_verb do
54
+ let(:verb) { http_verb.downcase.to_sym }
55
+ let(:request) {
56
+ {
57
+ :url => "/foo",
58
+ :method => verb,
59
+ :params => {
60
+ :bar => "baz"
61
+ }
62
+ }
63
+ }
64
+ it_behaves_like "stubbing met"
65
+ end
38
66
  end
39
67
 
40
68
  describe "status code responses" do
metadata CHANGED
@@ -1,84 +1,74 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Justin Searls
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-31 00:00:00.000000000 Z
11
+ date: 2013-11-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sinatra
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: thin
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec-given
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - '='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - '='
92
81
  - !ruby/object:Gem::Version
@@ -94,17 +83,15 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rack-test
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: a simple test server for stubbing API responses
@@ -115,10 +102,10 @@ extensions: []
115
102
  extra_rdoc_files: []
116
103
  files:
117
104
  - .gitignore
105
+ - .travis.yml
118
106
  - Gemfile
119
107
  - LICENSE.txt
120
108
  - README.md
121
- - Rakefile
122
109
  - lib/servme.rb
123
110
  - lib/servme/dsl.rb
124
111
  - lib/servme/responder.rb
@@ -133,27 +120,26 @@ files:
133
120
  - spec/spec_helper.rb
134
121
  homepage: https://github.com/testdouble/servme
135
122
  licenses: []
123
+ metadata: {}
136
124
  post_install_message:
137
125
  rdoc_options: []
138
126
  require_paths:
139
127
  - lib
140
128
  required_ruby_version: !ruby/object:Gem::Requirement
141
- none: false
142
129
  requirements:
143
- - - ! '>='
130
+ - - '>='
144
131
  - !ruby/object:Gem::Version
145
132
  version: '0'
146
133
  required_rubygems_version: !ruby/object:Gem::Requirement
147
- none: false
148
134
  requirements:
149
- - - ! '>='
135
+ - - '>='
150
136
  - !ruby/object:Gem::Version
151
137
  version: '0'
152
138
  requirements: []
153
139
  rubyforge_project:
154
- rubygems_version: 1.8.24
140
+ rubygems_version: 2.0.3
155
141
  signing_key:
156
- specification_version: 3
142
+ specification_version: 4
157
143
  summary: Servme lets you stub server responses by standing-in for some remote system
158
144
  your code under test depends on
159
145
  test_files:
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"