Add Sinatra::Runner For Managing Sinatra Servers #122

Merged
merged 8 commits into from Jul 21, 2016

Projects

None yet

4 participants

@apotonick
Contributor

This is extremely useful e.g. if you wanna test your REST client against a real backend (with real network calls). Assuming the test backend is a sinatra app, this class helps you to start and stop the server in your test.

@apotonick apotonick referenced this pull request in sinatra/sinatra Feb 12, 2014
Closed

Use Sinatra::Runner In Integration Test #840

@rkh rkh commented on the diff Mar 7, 2014
lib/sinatra/runner.rb
+#
+# Whereever you need this test backend, here's how you manage it. The following example assumes you
+# have a test in your app that needs to be run against your test backend.
+#
+# runner = ServerRunner.new
+# runner.run
+#
+# # ..tests against localhost:4567 here..
+#
+# runner.kill
+#
+# For an example, check https://github.com/apotonick/roar/blob/master/test/test_helper.rb
+module Sinatra
+ class Runner
+ def app_file
+ File.expand_path("../server.rb", __FILE__)
@rkh
rkh Mar 7, 2014 Member

Shouldn't this be configurable?

@apotonick
apotonick Mar 8, 2014 Contributor

It is, by overriding this method.

@rkh rkh commented on the diff Mar 7, 2014
lib/sinatra/runner.rb
+ def get(url)
+ Timeout.timeout(1) { get_url("#{protocol}://127.0.0.1:#{port}#{url}") }
+ end
+
+ def log
+ @log ||= ""
+ loop { @log << pipe.read_nonblock(1) }
+ rescue Exception
+ @log
+ end
+
+ private
+ attr_accessor :pipe
+
+ def start
+ IO.popen(command)
@rkh
rkh Mar 7, 2014 Member

Where did the JRuby implementation go?

@rkh
Member
rkh commented Mar 7, 2014

No tests. :(

@vipulnsward vipulnsward commented on the diff Apr 7, 2014
lib/sinatra/runner.rb
+# runner = ServerRunner.new
+# runner.run
+#
+# # ..tests against localhost:4567 here..
+#
+# runner.kill
+#
+# For an example, check https://github.com/apotonick/roar/blob/master/test/test_helper.rb
+module Sinatra
+ class Runner
+ def app_file
+ File.expand_path("../server.rb", __FILE__)
+ end
+
+ def run
+ #puts command
@vipulnsward
vipulnsward Apr 7, 2014 Contributor

we can remove the puts

@apotonick apotonick referenced this pull request in trailblazer/roar May 16, 2014
Closed

Add JRuby support #95

@zzak zzak added this to the 1.5 milestone Feb 6, 2015
@zzak zzak added the feature label Feb 6, 2015
@zzak
Member
zzak commented Feb 6, 2015

We'll look into this for Sinatra 1.5

@zzak
Member
zzak commented May 3, 2016

@apotonick Find a way to make it configurable, remove the #puts statement, and add some tests and you're good

@zzak
Member
zzak commented Jul 21, 2016

Ok, I'm going to merge this, even without the configure option (since there is a workaround) and tests.

It's a new feature, that I will mark as experimental, so I'm fine if we add them later.

@zzak zzak merged commit 632945f into sinatra:master Jul 21, 2016

1 check passed

default The Travis CI build passed
Details
@zzak zzak referenced this pull request in trailblazer/roar Jul 21, 2016
Closed

Remove test/lib/runner.rb once sinatra-contrib is updated #195

@myabc myabc added a commit to myabc/roar that referenced this pull request Dec 9, 2016
@myabc myabc Switch to Sinatra::Runner on sinatra master
sinatra/sinatra-contrib#122 has been merged.

Closes #195.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
74b568d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment