Question: Access Sinatra settings from Minitest test_helper

Question

Access Sinatra settings from Minitest test_helper

Answers 0
Added at 2016-12-30 15:12
Tags
Question

I am trying to access a variable defined in Sinatra settings from my test helper with no luck. This is my code:

Main app:

require 'sinatra'

set :foo, 'bar'

# use settings.foo in the routes

tests/test_helper.rb

ENV['RACK_ENV'] = 'test'

require 'minitest/autorun'
require 'rack/test'

module Minitest
  class Spec
    include Rack::Test::Methods

    def app
      Sinatra::Application
    end

    before do
      # do something with settings.foo
    end
  end
end

I have tried Sinatra::Application.settings.foo and also app.settings.foo but none work.

I have also tried adding a helper method like the one below:

lib/helpers/settings_helper.rb

module SettingsHelper
  def foo
    settings.foo
  end
end

helpers SettingsHelper

This works inside app, but again doesn't work inside test_helper. I tried requiring settings_helper.rb in test_helper. Also added an include. None of this worked.

Does anybody know what am I doing wrong?

Happy holidays

Answers to

Access Sinatra settings from Minitest test_helper

Source Show
◀ Wstecz