I tried the whole BDD
approach and would like to test the AMQP
-bounded aspect of the vanilla Ruby
application that I am writing. Choosing Minitest
as a test basis for the balance of functions and expressiveness, unlike other target vegetable frameworks, I decided to write this specification:
# File ./test/specs/services/my_service_spec.rb # Requirements for test running and configuration require "minitest/autorun" require "./test/specs/spec_helper" # External requires # Minitest Specs for EventMachine require "em/minitest/spec" # Internal requirements require "./services/distribution/my_service" # Spec start describe "MyService", "A Gateway to an AMQP Server" do # Connectivity it "cannot connect to an unreachable AMQP Server" do # This line breaks execution, commented out # include EM::MiniTest::Spec # ... # (abridged) Alter the configuration by specifying # an invalid host such as " l0c@alho $t" or such # ... # Try to connect and expect to fail with an Exception MyApp::MyService.connect.must_raise EventMachine::ConnectionError end end
I commented on the inclusion of the em-minitest-spec gem function , which should force the specification to work inside the EventMachine
reactor, if I turn it on, I encountered another exception due to (I suppose) built-in classes and such: NoMethodError: undefined method 'include' for #<#<Class:0x3a1d480>:0x3b29e00>
.
The code I'm testing, namely the connect
method in this service, is based on in this article and looks like this:
All exception handling is just an attempt to throw an exception from an exception in a place where I can catch / handle it, which also did not help, with or without the begin
and raise
bits, get the same result when spec starts:
EventMachine::ConnectionError: unable to resolve server address
, which is actually what I would expect, but Minitest
does not work very well with the concept of the entire reactor and does not pass the test based on this Exception
.
The question remains: how to test EventMachine
related code using Minitest
spec-mechanisms? Another question also concerned Cucumber
, also without an answer.
Or should I focus on my core functions (like messaging and viewing messages sent / received) and forget about edge cases? Any insight would really help!
Of course, everything can be reduced to what I wrote above, perhaps this is not the way to write / test these aspects. May be!
Notes on my environment: ruby 1.9.3p194 (2012-04-20) [i386-mingw32]
(yes, Win32:>), minitest 3.2.0
, eventmachine (1.0.0.rc.4 x86-mingw32)
, amqp (0.9.7)
Thanks in advance!