¿Cómo escribir pruebas para el registro alternativo para Rails (gem)?

How to write tests for alternative logging for Rails (tests for gem)? Not only unit tests, but also check functionality with rails. Maybe somebody know best way for such testing.

preguntado el 08 de noviembre de 11 a las 15:11

That's a pretty vague question. Are you looking for suggestions on framework? (rspec / test::unit) ... or are you looking for a specific idea on how to test objects that are going to use your gem? -

I search how to test logger in gem, if no rails. Example (with rails): I add gem, create controller and views, activate gem, do request on controller and check logs in rspec. As I understand best solution - add rails tested rails app, but what to do, if I want test several rails versions? -

1 Respuestas

If you want to test the integration of a gem then you could do this with either rspec or cucumber or even test_unit if you wanted the process would be very similar.

You essentially need to write some integration tests that are going to build a new rails application (you could do this by running the 'rails new application' command or by loading a pre-build rails application in your project). I would probably do the former and create a new rails application into a your_project_dir/tmp/test_rails_application and make sure you ignore the tmp dir in git. Also remove the application every time you run your integration tests.

You now need to write some code to add your logging gem to the Gemfile and have the process run bundle to install the gem. Once you've done that you should be able to see where to go with this, you'll be writing code to add code to your rails application, load up the application and assert your logging commands are getting written out to the log files.

It's not an overly difficult process but will require some thought about the best way to get it done.

David

respondido 09 nov., 11:14

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.