Karel Minarik faa0ee14bd [UTIL] Added a source code generator using the JSON API specs
The generator is based on [Thor](https://github.com/wycats/thor),
a library/framework for command line applications.

The generator will read the JSON API spec file(s), and generate
the Ruby source code (one file per API endpoint) with correct
module namespace, method names, and RDoc documentation.

It will generate a test file for each API endpoint as well.

Currently it only generates Ruby source, but can easily be
extended and adapted to generate source code for other
programming languages.

Usage example:

    $ thor api:code:generate ../../api-spec/*.json --force --verbose
2013-06-16 23:25:08 +02:00

27 lines
892 B
Plaintext

require 'test_helper'
module Elasticsearch
module Test
class <%= @module_namespace.empty? ? @method_name.camelize : @module_namespace.map {|n| n.capitalize}.join + @method_name.camelize %>Test < ::Test::Unit::TestCase
context "<%= @module_namespace.empty? ? '' : @module_namespace.map {|n| n.capitalize}.join + ': ' %><%= @method_name.humanize %>" do
subject { FakeClient.new(nil) }
should "perform correct request" do
subject.expects(:perform_request).with do |method, url, params, body|
assert_equal 'FAKE', method
assert_equal 'test', url
assert_equal Hash.new, params
<%= @spec['body'].nil? ? 'assert_nil body' : 'assert_equal Hash.new, body' %>
true
end.returns(FakeResponse.new)
subject.<%= @full_namespace.join('.') %>
end
end
end
end
end