Class: Sunspot::Rails::Tester

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sunspot/rails/tester.rb

Constant Summary collapse

VERSION =
'1.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.pidObject

Returns the value of attribute pid.



12
13
14
# File 'lib/sunspot/rails/tester.rb', line 12

def pid
  @pid
end

.serverObject

Returns the value of attribute server.



12
13
14
# File 'lib/sunspot/rails/tester.rb', line 12

def server
  @server
end

.startedObject

Returns the value of attribute started.



12
13
14
# File 'lib/sunspot/rails/tester.rb', line 12

def started
  @started
end

Class Method Details

.clearObject



63
64
65
# File 'lib/sunspot/rails/tester.rb', line 63

def clear
  self.server = nil
end

.configurationObject



59
60
61
# File 'lib/sunspot/rails/tester.rb', line 59

def configuration
  server.send(:configuration)
end

.give_feedbackObject



36
37
38
39
# File 'lib/sunspot/rails/tester.rb', line 36

def give_feedback
  puts 'Sunspot server is starting...' while starting
  puts "Sunspot server took #{seconds} seconds to start"
end

.kill_at_exitObject



32
33
34
# File 'lib/sunspot/rails/tester.rb', line 32

def kill_at_exit
  at_exit { Process.kill('TERM', pid) }
end

.secondsObject



49
50
51
# File 'lib/sunspot/rails/tester.rb', line 49

def seconds
  '%.2f' % (Time.now - started)
end

.start_original_sunspot_sessionObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sunspot/rails/tester.rb', line 14

def start_original_sunspot_session
  unless started?
    self.server = Sunspot::Rails::Server.new
    self.started = Time.now
    self.pid = fork do
      $stderr.reopen('/dev/null')
      $stdout.reopen('/dev/null')
      server.run
    end
    kill_at_exit
    give_feedback
  end
end

.started?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/sunspot/rails/tester.rb', line 28

def started?
  not server.nil?
end

.startingObject



41
42
43
44
45
46
47
# File 'lib/sunspot/rails/tester.rb', line 41

def starting
  sleep(1)
  Net::HTTP.get_response(URI.parse(uri))
  false
rescue Errno::ECONNREFUSED
  true
end

.uriObject



53
54
55
# File 'lib/sunspot/rails/tester.rb', line 53

def uri
  "http://#{hostname}:#{port}#{path}"
end