On Monday, February 25, 2013 at 1:02 PM, Luca G. Soave wrote:
Hi, I'm having hard time trying to make rspec working on this app.rb goliath endpoint server :
require 'goliath'
require 'grape'
require 'yajl/json_gem'
require 'em-synchrony/em-mongo'
class API < Grape::API
version 'v1', :using => :path
format :json
resource 'categories' do
# http://0.0.0.0:9000/v1/categories/
get "/" do
coll = env.mongo.collection('categories') #Connection Pool from Goliath ENV
coll.find({})
end
end
end
class App < Goliath::API
def response(env)
API.call(env)
end
end
I would need something like :
require 'spec_helper'
require 'yajl/json_gem'
describe App do
include Rack::Test::Methods
def app
API
end
describe API do
describe 'GET /v1/categories' do
it 'get several categories of repositories by name' do
get "/v1/categories"
last_response.status.should == 200
JSON.parse(last_response.body)["name"].should == "Ruby Web Frameworks"
end
end
end
end
but this simpli dosn't work. I also had a look at spec/integration examples without success.
Can someone please show me the right way ?
--
You received this message because you are subscribed to the Google Groups "Goliath.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to goliath-io+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
In spec/spec_helper.rb I added goliath test helper and all dependencies. In my case :
require 'em-synchrony/em-http' require 'goliath/test_helper' require 'yajl/json_gem' Goliath.env = :test RSpec.configure do |c| c.include Goliath::TestHelper, :example_group => { :file_path => /spec\// } end
in spec/app_spec.rb
require 'spec_helper'
require File.join(File.dirname(__FILE__), '../', 'app')
describe App do
def config_file
File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'app.rb'))
end
let(:api_options) { { :config => config_file } }
it 'renders ' do
with_api(App, api_options) do
get_request(:path => '/v1/categories') do |c|
resp = JSON.parse(c.response)
categories = resp.map{|r|r['name']}
categories.to_s.should =~ /Ruby Web Frameworks/
end
end
end
end