Module: EvelpidonTestHelpers::TestSunspot
- Defined in:
- lib/evelpidon_test_helpers/sunspot.rb
Overview
Stubbing out Solr
Taken from : timcowlishaw.co.uk/post/3179661158/testing-sunspot-with-test-unit
Class Attribute Summary collapse
-
.original_session ⇒ Object
Returns the value of attribute original_session.
-
.pid ⇒ Object
Returns the value of attribute pid.
-
.server ⇒ Object
Returns the value of attribute server.
-
.stub_session ⇒ Object
Returns the value of attribute stub_session.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.original_session ⇒ Object
Returns the value of attribute original_session.
8 9 10 |
# File 'lib/evelpidon_test_helpers/sunspot.rb', line 8 def original_session @original_session end |
.pid ⇒ Object
Returns the value of attribute pid.
8 9 10 |
# File 'lib/evelpidon_test_helpers/sunspot.rb', line 8 def pid @pid end |
.server ⇒ Object
Returns the value of attribute server.
8 9 10 |
# File 'lib/evelpidon_test_helpers/sunspot.rb', line 8 def server @server end |
.stub_session ⇒ Object
Returns the value of attribute stub_session.
8 9 10 |
# File 'lib/evelpidon_test_helpers/sunspot.rb', line 8 def stub_session @stub_session end |
Class Method Details
.included(klass) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/evelpidon_test_helpers/sunspot.rb', line 16 def self.included(klass) klass.instance_eval do def startup Sunspot.session = TestSunspot.original_session rd, wr = IO.pipe pid = fork do STDOUT.reopen(wr) STDERR.reopen(wr) TestSunspot.server ||= Sunspot::Rails::Server.new begin TestSunspot.server.run ensure wr.close end end TestSunspot.pid = pid ready = false until ready do ready = true if rd.gets =~ /Started\ SocketConnector/ sleep 0.5 end rd.close end def shutdown Sunspot.remove_all! Process.kill("HUP",TestSunspot.pid) Process.wait Sunspot.session = TestSunspot.stub_session end end def teardown Sunspot.remove_all! end end |
.setup ⇒ Object
10 11 12 13 |
# File 'lib/evelpidon_test_helpers/sunspot.rb', line 10 def setup TestSunspot.original_session = Sunspot.session Sunspot.session = TestSunspot.stub_session = Sunspot::Rails::StubSessionProxy.new(Sunspot.session) end |
Instance Method Details
#teardown ⇒ Object
48 49 50 |
# File 'lib/evelpidon_test_helpers/sunspot.rb', line 48 def teardown Sunspot.remove_all! end |