Played a little bit with TestUnit, MiniTest Unit/Spec, RSpec and
Cucumber/Capybara
For Unit testing i decided for MiniTest::Unit, because it’s in the
stdlib
For Feature testing (only 1 test feature yet) i’ll use Cucumber/Capybara
The question for my unit tests:
In the lib folder i got a cli class which handles all cli interaction
(run, generate, etc). When i try to test my run method in
command_line_interface_test.rb i had to add a “environment” parameter to
the lib file, so it doesn’t start the specified Rack::Server in the
Test.
I think this isn’t very clean to edit a Core file so tests can hook into
it
Is there a better way to achieve this?
In general:
If you find something which can be done better, just say it (it’s my
first real Ruby Application)
In the lib folder i got a cli class which handles all cli interaction
(run, generate, etc). When i try to test my run method in
command_line_interface_test.rb i had to add a “environment” parameter to
the lib file, so it doesn’t start the specified Rack::Server in the
Test.
I think this isn’t very clean to edit a Core file so tests can hook into
it
Is there a better way to achieve this?
Some vague thoughts (I had no time to look into the source):
I assume the purpose of the `run’ method is to start the server,
so what do you want to test if not that a server is started?
Maybe your run method does more than it should (like setup).
you could move those parts to a different method
and only test the helper method
or use a mock for Rack::Server that doesn’t really start the server
(MiniTest::Mock)
or you might want to try monkey patching Rack::Server
in your test file
In the lib folder i got a cli class which handles all cli interaction
(run, generate, etc). When i try to test my run method in
command_line_interface_test.rb i had to add a “environment” parameter to
the lib file, so it doesn’t start the specified Rack::Server in the
Test.
I think this isn’t very clean to edit a Core file so tests can hook into
it
Is there a better way to achieve this?
Some vague thoughts (I had no time to look into the source):
I assume the purpose of the `run’ method is to start the server,
so what do you want to test if not that a server is started?
Maybe your run method does more than it should (like setup).
you could move those parts to a different method
and only test the helper method
or use a mock for Rack::Server that doesn’t really start the server
(MiniTest::Mock)
or you might want to try monkey patching Rack::Server
in your test file
Regards,
Marcus
Thanks for your response!
I think I’m going to look in Mock objects and as u said move some part
into helper methods.
Greetings,
Benny
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.