1

My ruby application runs Webrick server. I want to test it by cucumber and want to ensure that it gives me right response.

Is it normal to run server in test environment for testing? Where in my code I should start server process and where I should destroy it?

Now I start server by background step and destroy in After hook. It's slow because server starts before every scenario and destroys after.

I have idea to start server in env.rb and destroy it in at_exit block declared also in env.rb. What do you think about it?

Do you know any patterns for that problem?

2 Answers 2

1

I use Spork for this. It starts up one or more servers, and has the ability to reload these when needed. This way, each time you run your tests you're not incurring the overhead of firing up Rails.

https://github.com/sporkrb/spork

Check out this RailsCast for the details: http://railscasts.com/episodes/285-spork

Sign up to request clarification or add additional context in comments.

Comments

1

Since cucumber does not support spork any more (why ?) I use the following code in env.rb To fork a process I use this lib : https://github.com/jarib/childprocess

require 'childprocess' ChildProcess.posix_spawn = true wkDir=File.dirname(__FILE__) server_dir = File.join(wkDir, '../../site/dev/bin') #Because I use rvm , I have to run the server thru a shell @server = ChildProcess.build("sh","-c","ruby pageServer.rb -p 4563") @server.cwd = server_dir @server.io.inherit! @server.leader = true @server.start at_exit do puts "----------------at exit--------------" puts "Killing process " + @server.pid.to_s @server.stop if @server.alive? puts "Server is still alive - kill it manually" end end 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.