Module: Iudex::HTTP::Test::Helper

Defined in:
lib/iudex-http-test/helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.running_standalone?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
# File 'lib/iudex-http-test/helper.rb', line 57

def self.running_standalone?
  res = Net::HTTP.start( 'localhost', Server::DEFAULT_PORT ) do |http|
    http.open_timeout = 0.5
    http.read_timeout = 1.0
    http.get( '/index' )
  end
  ( res.code.to_i == 200 )
rescue Timeout::Error, Errno::ECONNREFUSED
  false
end

.serverObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/iudex-http-test/helper.rb', line 44

def self.server
  @server ||=
    begin
      if running_standalone?
        OpenStruct.new( :port => Server::DEFAULT_PORT )
      else
        server = Server.new
        server.start
        server
      end
    end
end

.stopObject



68
69
70
71
72
73
74
75
# File 'lib/iudex-http-test/helper.rb', line 68

def self.stop
  if @server
    $stderr.puts
    @server.stop
    @server.join
    @server = nil
  end
end

Instance Method Details

#serverObject



40
41
42
# File 'lib/iudex-http-test/helper.rb', line 40

def server
  Helper.server
end