sinatra_fake_webservice 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Elad Meidar
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = Sinatra Fake Webservice
2
+
3
+ SFW provides an easy and simple wrapper for a sinatra application you can use in your tests in order to test/simulate remote API and HTTP calls and responses.
4
+
5
+ == Why shouldn't i use FakeWeb?
6
+
7
+ FakeWeb is awesome, but it allows you only to register *one* response per url, although in some cases you might need more than one response per url depend on your usage for example: testing an XMLRPC service or a WSDL that both might have only one url and respond based on parameters.
8
+
9
+ == Installation
10
+
11
+ Command line:
12
+ sudo gem install sinatra_fake_webservice+
13
+
14
+ Or in bundler (0.9.x) add this line to your .gemfile:
15
+
16
+ gem 'sinatra_fake_webservice', :group => :test
17
+
18
+
19
+ == Usage
20
+
21
+ First you'll need to create a SinatraWebService instance that can accept +:host+ and +:port+ options:
22
+
23
+ @fakews = SinatraWebService.new :host => 'localhost', :port => 7000
24
+
25
+ and then simply use the familiar sinatra DSL to create methods and responses.
26
+
27
+ @fakews.get '/awesome' do
28
+ "YAY!!"
29
+ end+
30
+
31
+ tada!
32
+
33
+ i simply used Net::HTTP to access the sinatra app, but i bet there are more ways to do it:
34
+
35
+ res = Net::HTTP.start(@fakews.host, @fakews.port) do |http|
36
+ http.get('/awesome')
37
+ end
38
+
39
+ assert_equal "YAY!!", res.body
40
+
41
+ == Note on Patches/Pull Requests
42
+
43
+ * Fork the project.
44
+ * Make your feature addition or bug fix.
45
+ * Add tests for it. This is important so I don't break it in a
46
+ future version unintentionally.
47
+ * Commit, do not mess with rakefile, version, or history.
48
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
49
+ * Send me a pull request. Bonus points for topic branches.
50
+
51
+ == Copyright
52
+
53
+ Copyright (c) 2010 Elad Meidar. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "sinatra_fake_webservice"
8
+ gem.summary = %Q{use a sinatra application in your Rails test environment to fake a remote web service that needs more magic than Fakeweb}
9
+ gem.description = %Q{FakeWeb allows you to fake a response from a specific url, this gem intends to give developers the option to allow several responses from the same url based on parameters (ex: WSDL)}
10
+ gem.email = "elad@nautilus6.com"
11
+ gem.homepage = "http://github.com/eladmeidar/sinatra_fake_webservice"
12
+ gem.authors = ["Elad Meidar"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.add_dependency 'sinatra'
15
+
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/test_*.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "sinatra_fake_webservice #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,16 @@
1
+ # Disabling the capture of the Errno::EADDRINUSE exception in #run! so we can make WebService catch it.
2
+ # class Sinatra::Base
3
+ # def self.run!(options={})
4
+ # attempts = 0
5
+ # set options
6
+ # handler = detect_rack_handler
7
+ # handler_name = handler.name.gsub(/.*::/, '')
8
+ # handler.run self, :Host => bind, :Port => port do |server|
9
+ # trap(:INT) do
10
+ # ## Use thins' hard #stop! if available, otherwise just #stop
11
+ # server.respond_to?(:stop!) ? server.stop! : server.stop
12
+ # end
13
+ # set :running, true
14
+ # end
15
+ # end
16
+ # end
@@ -0,0 +1,53 @@
1
+
2
+
3
+ class SinatraWebService
4
+
5
+ attr_accessor :host, :port
6
+
7
+ class SinatraStem < Sinatra::Base
8
+ get '/' do
9
+ "Hello! i am lindesy lohan!"
10
+ end
11
+ end
12
+
13
+
14
+ def initialize(options = {})
15
+ @host = options[:host] ||= 'localhost'
16
+ @port = options[:port] ||= 4567
17
+ end
18
+
19
+ def running?
20
+ false
21
+ end
22
+
23
+ def run!
24
+ @port = find_free_port
25
+
26
+ app = Thread.new("running_app") do
27
+ SinatraStem.run! :post => @host, :port => @port.to_i
28
+ sleep 1
29
+ end
30
+ end
31
+
32
+ def find_free_port
33
+ found = false
34
+ attempts = 0
35
+ while !found and attempts < 10
36
+ puts "\n== Trying port #{@port}"
37
+ begin
38
+ res = Net::HTTP.start(host,port) do |http|
39
+ http.get('/')
40
+ end
41
+ attempts += 1
42
+ @port = @port.succ
43
+ rescue Errno::ECONNREFUSED
44
+ return @port
45
+ end
46
+ end
47
+ end
48
+
49
+ def method_missing(method, *args, &block)
50
+ SinatraStem.send(method, *args, &block) unless method.to_s == "proxy"
51
+ end
52
+
53
+ end
@@ -0,0 +1,60 @@
1
+ require 'net/http'
2
+ class WebService
3
+
4
+ class SinatraStem < Sinatra::Base
5
+ get '/' do
6
+ "Hello! i am lindesy lohan!"
7
+ end
8
+ end
9
+
10
+ attr_accessor :port, :host, :name, :sinatra_app
11
+
12
+
13
+ # Initialize a new face service
14
+ def initialize(options = {})
15
+ @name = options[:name] ||= "App"
16
+ @port = options[:port] ||= "4567"
17
+ @host = options[:host] ||= "localhost"
18
+ @sinatra_app = Sinatra::Base.new
19
+ end
20
+
21
+ def proxy
22
+ @sinatra_app
23
+ end
24
+
25
+ def run
26
+
27
+ @port = find_free_port
28
+
29
+ app = Thread.new("running_#{self.name}") do
30
+ puts "\n == Starting webservice '#{@name}' on port #{@port}"
31
+ proxy.run! :post => @host, :port => @port.to_i
32
+ sleep 1
33
+ end
34
+ end
35
+
36
+ def find_free_port
37
+ found = false
38
+ attempts = 0
39
+ while !found and attempts < 10
40
+ puts "\n== Trying port #{@port}"
41
+ begin
42
+ res = Net::HTTP.start(host,port) do |http|
43
+ http.get('/')
44
+ end
45
+ attempts += 1
46
+ @port = @port.succ
47
+ rescue Errno::ECONNREFUSED
48
+ return @port
49
+ end
50
+ end
51
+ end
52
+
53
+ def proxy
54
+ @sinatra_app
55
+ end
56
+
57
+ def method_missing(method, *args, &block)
58
+ proxy.send(method, *args, &block) unless method.to_s == "proxy"
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ require 'sinatra/base'
2
+
3
+ class SinatraStem < Sinatra::Base
4
+
5
+ get '/' do
6
+ "Hellllllo! i am Lindsey Lohan!!"
7
+ end
8
+ end
9
+
data/sinatra.log ADDED
@@ -0,0 +1,273 @@
1
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
2
+ Started
3
+ .....
4
+ == Trying to run App on post 4567
5
+ .== Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
6
+ ..
7
+ == Trying to run App on post 4567
8
+ == Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
9
+ == Someone is already performing on port 4567!
10
+ Hiya!
11
+ .
12
+ Finished in 0.22206 seconds.
13
+
14
+ 9 tests, 10 assertions, 0 failures, 0 errors
15
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
16
+ Started
17
+ .....
18
+ == Trying to run App on post 4567
19
+ .== Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
20
+ ..
21
+ == Trying to run App on post 4567
22
+ == Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
23
+ == Someone is already performing on port 4567!
24
+ Hiya!
25
+ .
26
+ Finished in 0.19735 seconds.
27
+
28
+ 9 tests, 10 assertions, 0 failures, 0 errors
29
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
30
+ Started
31
+ ..
32
+ == Trying to run App on post 4567
33
+ == Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
34
+ Hiya!
35
+ .
36
+ Finished in 0.046046 seconds.
37
+
38
+ 3 tests, 4 assertions, 0 failures, 0 errors
39
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
40
+ Started
41
+ .....
42
+ == Trying to run App on post 4567
43
+ .== Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
44
+ ..
45
+ == Trying to run App on post 4567
46
+ == Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
47
+ == Someone is already performing on port 4567!
48
+ Hiya!
49
+ .
50
+ Finished in 0.04921 seconds.
51
+
52
+ 9 tests, 10 assertions, 0 failures, 0 errors
53
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
54
+ Started
55
+ .....
56
+ == Trying to run App on post 4567
57
+ .== Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
58
+ ..
59
+ == Trying to run App on post 4567
60
+ == Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
61
+ == Someone is already performing on port 4567!
62
+ Hiya!
63
+ .
64
+ Finished in 0.047577 seconds.
65
+
66
+ 9 tests, 10 assertions, 0 failures, 0 errors
67
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
68
+ Started
69
+ .....
70
+ == Trying to run App on post 4567
71
+ .== Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
72
+ ..
73
+ == Trying to run App on post 4567
74
+ == Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
75
+ == Someone is already performing on port 4567!
76
+ Hiya!
77
+ .
78
+ Finished in 0.260547 seconds.
79
+
80
+ 9 tests, 10 assertions, 0 failures, 0 errors
81
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
82
+ Started
83
+ .....
84
+ == Trying to run App on post 4567
85
+ .== Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4568
86
+
87
+ == Trying to run App on post 4568
88
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4569
89
+
90
+ == Trying to run App on post 4569
91
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4570
92
+
93
+ == Trying to run App on post 4570
94
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4571
95
+
96
+ == Trying to run App on post 4571
97
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4572
98
+
99
+ == Trying to run App on post 4572
100
+ ..
101
+ == Trying to run App on post 4567
102
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4568
103
+
104
+ == Trying to run App on post 4568
105
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4569
106
+
107
+ == Trying to run App on post 4569
108
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4570
109
+
110
+ == Trying to run App on post 4570
111
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4571
112
+
113
+ == Trying to run App on post 4571
114
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4572
115
+
116
+ == Trying to run App on post 4572
117
+ E
118
+ Finished in 0.045649 seconds.
119
+
120
+ 1) Error:
121
+ test: a new web service with a custom method should respond to '/test' with 'Hiya!'. (TestWebservice):
122
+ Errno::ECONNREFUSED: Connection refused - connect(2)
123
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:560:in `initialize'
124
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:560:in `open'
125
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:560:in `connect'
126
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/timeout.rb:53:in `timeout'
127
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/timeout.rb:93:in `timeout'
128
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:560:in `connect'
129
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:553:in `do_start'
130
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:542:in `start'
131
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:440:in `start'
132
+ ./test/test_web_service.rb:31:in `__bind_1266537637_187400'
133
+ /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `call'
134
+ /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `test: a new web service with a custom method should respond to '/test' with 'Hiya!'. '
135
+
136
+ 9 tests, 9 assertions, 0 failures, 1 errors
137
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
138
+ Started
139
+ .....
140
+ == Trying to run App on post 4567
141
+ .== Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4568
142
+
143
+ == Trying to run App on post 4568
144
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4569
145
+
146
+ == Trying to run App on post 4569
147
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4570
148
+
149
+ == Trying to run App on post 4570
150
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4571
151
+
152
+ == Trying to run App on post 4571
153
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4572
154
+
155
+ == Trying to run App on post 4572
156
+ ..
157
+ == Trying to run App on post 4567
158
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4568
159
+
160
+ == Trying to run App on post 4568
161
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4569
162
+
163
+ == Trying to run App on post 4569
164
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4570
165
+
166
+ == Trying to run App on post 4570
167
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4571
168
+
169
+ == Trying to run App on post 4571
170
+ == Failed (undefined local variable or method `bind' for WebService::App:Class), retrying again on port 4572
171
+
172
+ == Trying to run App on post 4572
173
+ E
174
+ Finished in 0.045099 seconds.
175
+
176
+ 1) Error:
177
+ test: a new web service with a custom method should respond to '/test' with 'Hiya!'. (TestWebservice):
178
+ Errno::ECONNREFUSED: Connection refused - connect(2)
179
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:560:in `initialize'
180
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:560:in `open'
181
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:560:in `connect'
182
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/timeout.rb:53:in `timeout'
183
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/timeout.rb:93:in `timeout'
184
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:560:in `connect'
185
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:553:in `do_start'
186
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:542:in `start'
187
+ /Users/elad/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/net/http.rb:440:in `start'
188
+ ./test/test_web_service.rb:31:in `__bind_1266537644_167228'
189
+ /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `call'
190
+ /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `test: a new web service with a custom method should respond to '/test' with 'Hiya!'. '
191
+
192
+ 9 tests, 9 assertions, 0 failures, 1 errors
193
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
194
+ Started
195
+ .....
196
+ == Trying to run App on post 4567
197
+ .== Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
198
+ ..
199
+ == Trying to run App on post 4567
200
+ == Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
201
+ == Someone is already performing on port 4567!
202
+ Hiya!
203
+ .
204
+ Finished in 0.047605 seconds.
205
+
206
+ 9 tests, 10 assertions, 0 failures, 0 errors
207
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
208
+ Started
209
+ .....
210
+ == Trying to run App on post 4567
211
+ .== Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
212
+ ..
213
+ Finished in 0.042507 seconds.
214
+
215
+ 8 tests, 9 assertions, 0 failures, 0 errors
216
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
217
+ Started
218
+ .......
219
+ Finished in 0.000965 seconds.
220
+
221
+ 7 tests, 9 assertions, 0 failures, 0 errors
222
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
223
+ Started
224
+ .......
225
+ Finished in 0.000975 seconds.
226
+
227
+ 7 tests, 9 assertions, 0 failures, 0 errors
228
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
229
+ Started
230
+ ..
231
+ Finished in 0.000354 seconds.
232
+
233
+ 2 tests, 3 assertions, 0 failures, 0 errors
234
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
235
+ Started
236
+ ..
237
+ Finished in 0.000353 seconds.
238
+
239
+ 2 tests, 3 assertions, 0 failures, 0 errors
240
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
241
+ Started
242
+ ..
243
+ Finished in 0.000357 seconds.
244
+
245
+ 2 tests, 3 assertions, 0 failures, 0 errors
246
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
247
+ Started
248
+ ..
249
+ Finished in 0.000355 seconds.
250
+
251
+ 2 tests, 3 assertions, 0 failures, 0 errors
252
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
253
+ Started
254
+ .....
255
+ Finished in 0.000809 seconds.
256
+
257
+ 5 tests, 6 assertions, 0 failures, 0 errors
258
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
259
+ Started
260
+ .......
261
+ Finished in 0.000972 seconds.
262
+
263
+ 7 tests, 9 assertions, 0 failures, 0 errors
264
+ Loaded suite /Users/elad/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader
265
+ Started
266
+ .......
267
+ == Trying to run App on post 4567
268
+ == Sinatra/0.9.4 has taken the stage on 4567 for development with backup from WEBrick
269
+ Hiya!
270
+ .
271
+ Finished in 0.197477 seconds.
272
+
273
+ 8 tests, 10 assertions, 0 failures, 0 errors
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sinatra_fake_webservice}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Elad Meidar"]
12
+ s.date = %q{2010-02-18}
13
+ s.description = %q{FakeWeb allows you to fake a response from a specific url, this gem intends to give developers the option to allow several responses from the same url based on parameters (ex: WSDL)}
14
+ s.email = %q{elad@nautilus6.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/sinatra_ext.rb",
27
+ "lib/sinatra_webservice.rb",
28
+ "lib/web_service.rb",
29
+ "metal/sinatra_stem.rb",
30
+ "sinatra.log",
31
+ "sinatra_fake_webservice.gemspec",
32
+ "test/helper.rb",
33
+ "test/test_sinatra_fake_webservice.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/eladmeidar/sinatra_fake_webservice}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.5}
39
+ s.summary = %q{use a sinatra application in your Rails test environment to fake a remote web service that needs more magic than Fakeweb}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_sinatra_fake_webservice.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ s.add_dependency(%q<sinatra>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
+ s.add_dependency(%q<sinatra>, [">= 0"])
59
+ end
60
+ end
61
+
data/test/helper.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'metal'))
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ require 'sinatra/base'
11
+ #require 'sinatra_ext'
12
+ require 'sinatra_webservice'
13
+ #require 'web_service'
14
+
15
+ class Test::Unit::TestCase
16
+ end
@@ -0,0 +1,35 @@
1
+ require 'helper'
2
+
3
+ class TestSinatraFakeWebservice < Test::Unit::TestCase
4
+
5
+ context "a new sinatra web service" do
6
+
7
+ setup do
8
+ @sinatra_app = SinatraWebService.new
9
+ end
10
+
11
+ should "have default host and port" do
12
+ assert_equal 4567, @sinatra_app.port
13
+ assert_equal 'localhost', @sinatra_app.host
14
+ end
15
+
16
+ context "with a registered GET service" do
17
+
18
+ setup do
19
+ @sinatra_app.get '/payme' do
20
+ "OMG I GOT PAID"
21
+ end
22
+
23
+ @sinatra_app.run!
24
+ end
25
+
26
+ should "respond to '/payme' with 'OMG I GOT PAID" do
27
+ res = Net::HTTP.start(@sinatra_app.host, @sinatra_app.port) do |http|
28
+ http.get('/payme')
29
+ end
30
+
31
+ assert_equal "OMG I GOT PAID",res.body
32
+ end
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra_fake_webservice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Elad Meidar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-18 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: sinatra
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: "FakeWeb allows you to fake a response from a specific url, this gem intends to give developers the option to allow several responses from the same url based on parameters (ex: WSDL)"
36
+ email: elad@nautilus6.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/sinatra_ext.rb
52
+ - lib/sinatra_webservice.rb
53
+ - lib/web_service.rb
54
+ - metal/sinatra_stem.rb
55
+ - sinatra.log
56
+ - sinatra_fake_webservice.gemspec
57
+ - test/helper.rb
58
+ - test/test_sinatra_fake_webservice.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/eladmeidar/sinatra_fake_webservice
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: use a sinatra application in your Rails test environment to fake a remote web service that needs more magic than Fakeweb
87
+ test_files:
88
+ - test/helper.rb
89
+ - test/test_sinatra_fake_webservice.rb