Best way to write test cases for json views? (I.e., web services) - ruby-on-rails-3

I have a Rails app which implements a web service. I'm not sure how to best write tests for it.
It has one controller. Each method provides json output. As far as I can tell, functional (views) tests would be the right thing to use, but they seem to only work with HTML.

i think that you could be good with using a library like json_spec.
in combination with cucumber this could also server as a documentation for your api-users. have a look at this nice blog post using json_spec.

Related

Do Karate UI support Angular UI based application testing

If karate supports Angular testing, can i have some example so that i can look into it.
Have been going through locators given at https://intuit.github.io/karate/karate-core/#locators but unable to get exact information on how to proceed.
There is no need, Karate works with plain HTML.
And if you need to do some specifc JS helpers (which is all that frameworks that claim to support Angular do), just use the tips here and make re-usable functions: https://stackoverflow.com/a/60800181/143475
If you still have a question, ask a new question and provide a sample (can be online, see examples in link above) for us to understand and discuss.

ruby on rails - create a simple html page

I need some assistance in creating a simple html page and locate it in the server.
Since I couldnt find it in the doc I tried to put a index2.html file in the /public library and when I tried to get receive it using
http://127.0.0.1:3000/index2.html
or
http://127.0.0.1:3000/public/index2.html
and receiver
ActionController::RoutingError (No route matches [GET] "/public/index2.html"):
how do I get the html from the server
how di I make it the default.
Thanks.
EDIT : thanks for your answers. I am looking for the simplest way to work. in many tutorials it says you can put it in the public folder and thats it. This will same me useless controllers.
You can do that in several ways : the more obvious would be to have an action in one of your controller (or a new one, whatever) that does nothing (except render the view), and add a route to it. There is other ways to achieve this too, with more adapted tools. I never used any of them, so might want to google it (static page rails), but I know one of them is a gem called High Voltage. Hope this serves you well.
I think you might have mis-understood Rails...
I have never used it but I think I can probably help you with your answer. Rails is the most popular MVC framework for the language Ruby, hence 'Ruby on Rails'. Here is a link to the MVC framework this may help you understand it:
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
With the MVC framework you can't 'get' a file directly through the URL. You have to get it through the routing engine. Usually you do this through a Controller which renders a view, typically, from a model.
It's difficult to explain if you don't understand how the MVC framework works but once you have an understanding you should be able to develop web applications very rapidly.
Have a look here for creating your first rails app:
http://guides.rubyonrails.org/getting_started.html

What are good libraries to create restful iPhone Apps with Django and Objective-C?

Our new iPhone project consists of a native app and a server it needs to communicate with. I'd like the server to be written in Python/Django.
The last time we created something similar, the server was in written in asp.net and it exposed relevant methods as a SOAP-based web service. This was very convenient, since we were able to generate almost all server communication code from the WSDL using http://sudzc.com/. Now I basically want to do the same, but with Django instead of asp.net. More specifically, I want to expose methods and objects over an API and I'd really like to have some automatic Objective-C code generation at the other end.
I've looked at a few libraries for Django that are supposed to expose RESTful APIs, and most people seem to recommend django-piston or django-rest-framework. Will either of them have a WSDL-style description that I can use to auto-generate ObjC-code, though? Is there another set of tools for achieving what I'm after that I should be investigating?
In my personal experience I don't know of anything that exists to generate client-side stubs in Objective-C for a REST service. However, there's a very good library called RESTKit that features a JSON or XML to object mapping layer, and nice features like CoreData integration and local caching. There are number of useful Stackoverflow questions on it.
So that can get you part of the way, since it will handle communication and object mapping. If you need to build code-generation, it could output code that sets up RESTKit's mapping structures.
Another REST client lib for iOS that I like a lot is LRResty, for its clean API, but it's lower level than RESTKit in that it doesn't have any built-in parsing/object mapping features.
In this similar stackoverflow question there's a link to something called wsdl2objc which sounds like it's in line with what you need on the iOS side (I've no personal experience with it, so ymmv, etc...)

How to use RhinoMocks to test async WCF service call

We have a Silverlight 4 app that is making the standard async call to a WCF service to get data from the database. We have an interface for this IDataService so we can mock it out. I've been reading about RhinoMocks and trying to understand how to write a test for this. I think I would need to test that the call was made to get the data (something like GetCustomers) and then that the GetCustomersCompleted method was called with the data. I've seen so many different examples today and the old way to raise an event vs the new way (and I didn't know either). Does anyone have a simple example of using RhinoMocks for this kind of test? It seems like it would be something very common if one is using TDD and RhinoMocks with Silverlight. Any examples or links would be greatly appreciated. After several days of exploring I'd be great full for any help in this area.
thanks in advance!
Bill
I was struggling trying to write some async tests for a WPF app until I found the following blog entry:
http://blog.tatham.oddie.com.au/2009/04/09/testing-the-world-and-writing-better-quality-code-along-the-way/
I believe it should work for the Silverlight version of Rhino Mocks as well.

Web application programming using objective-c?

Just say you have a quite large and complicated desktop application written in objective-c/cocoa written properly in MVC. You then wish to replace the V and C so that it is a web application?
Is there anything like Tomcat but for objective c? The closest thing I can think of is somehow convert the Model code into an apache module to load in apache?
Obviously I could embed some sort of HTTP server and write a whole pile of code to manage sessions and requests and responses and so on, but might there be a simpler way?
You can leave the server almost as-is. I'd run it as a daemon in the background.
I'd split the controller part. One part of it resides on the server as a connection between HTTP requests and the daemon.
You could run a self-made http server.
You could build it into a Apache module as you mentioned.
You could access your controller through CGI. This is the easiest option as I see it.
The second part of the controller is written in Javascript in the browser, exchanging data with the server and updating the GUI.
The view part is written completely in javascript.
You could - if you want - leave out the controller on the server and make the model understand HTTP requests.
For the Controller / View part consider using a framework.
jQuery for only a light interface. (Or a similar framework.)
I haven't yet found a framework that leaves all the model stuff to the server. Maybe you can use SproutCore or Cappuccino accordingly.
SproutCore, the full-backed MVC framework that is used by Apple. (Think so at least.)
Cappuccino, another full-backed MVC framework.
Have you looked at Cappuccino? http://cappuccino.org/
I have not used but have heard many good things about it.
There is a new web development platform for Objective-C/Cocoa called Bombax. It sounds like exactly what you're looking for (it is designed to allow you to write entire web applications in Objective-C). Perhaps you could even combine it with Cappuccino. You can check it out at http://www.bombaxtic.com.
The closest you'll probably come to Objective-C web frameworks are either SOPE, or GNUStep, neither of which I have used, but ran across when I was deciding if I wanted to use Rails or something written in Objective-C for my web stuff. There's also ARJDatabase, which is kind of like Core Data, but not source compatible.
The bottom line is, unless you were very careful about how you wrote your code (i.e. wrote it with GNUStep in mind, didn't use anything Apple specific) you're probably going to have to do quite a bit of work anyway. And if you used Core Data at all, there's no way I know of to reuse that outside of a Mac App. And since it's not setup to be used my multiple simultaneous users, you wouldn't want to use that in a web app anyway. Bottom line, I went with Rails.
There is Frothkit - http://code.google.com/p/frothkit/ but it appears not to have been updated for a year.