ruby-grape / grape-rabl

Use rabl with grape
MIT License
136 stars 29 forks source link

Use Rack::Config to set 'api.tilt.root' in config.ru #4

Closed volkanunsal closed 11 years ago

volkanunsal commented 12 years ago

Following up on my note on issue #2, I tried configuring the middleware from Rails application.rb.


class Application < Rails::Application
  config.middleware.use(Rack::Config) do |env|
    env['api.tilt.root'] = Rails.root.join "app", "views", "api"
  end
end

While that works in other environments, it does not work in the test environment. Specifically, Rspec is complaining that it cannot find the root path for Tilt.

LTe commented 11 years ago

Try this:

RSpec.configure do |config|
  config.include Rack::Test::Methods
end

class MyAPI < Grape::API
  get "/", :rabl => "home" do
    @user = current_user
  end
end

describe "API" do
  before { MyAPI.before { env["api.tilt.root"] = "path_to_views" } }

  def app
    MyAPI
  end

  it "success" do
    get '/'
    last_response.should be_success
  end
end

Check also grape-rabl specs: https://github.com/LTe/grape-rabl/blob/master/spec/grape_rabl_spec.rb

Please re-open if you have any problems