ruby on rails - How should I unit test this module? -


I am developing the railroad for a short time, but I'm picking it fast enough soon

How do I write tests, but I never know who should test me and I have really made it difficult to start writing my own test.

I recently wrote a gem to experiment with the API for a project and I thought it would be the best time to write some tests. I am still losing so much what I should test.

I was hoping that I have posted one of my classes in some ways, so that someone can give me some ideas to be tested.

The API is working with the JSN Objects Return, so in all of my ways there are really only Assistants that get the request and get Jason back to the application. To get the requests I received Using the HTTParty gem.

The first method lists only some information about a particular advertiser:

  Module MyModule class user & lt; MyObject # User # will list information about this specific user # Required parameters: # user_id # Example: # MyModule.connect ("Your API Key") # MyModule :: User.list (5) # Returns: # Returns the following properties: A single result with: # {# "user_name": "blah", # "user_id": 253, # "last_login": "2011-03-01" #} def list (user) MyModule.get ("My initial It is anticipated that I will test to make sure that this JSON object is returned with the correct properties, but the whole thing  

Do I need to be tested to make sure that there are arguments passed in the system or should I not worry about anything? < P>

The unit test should check the behavior of an object or method, and not the object construction, however There are only a few things you can test here:

  1. That your GET request is successful (or not).
  2. That you are valid JSON (or not).
  3. That your record is not disturbing.

    You probably should test at a little more level. For example, I test the story of this user:

      Given a record with some reasonable stability data, when the record is successfully recovered, then your application is useful Does something    

Comments