Using Cucumbers with Sinatra Modular Applications

I am building a mid-size application using Sinatra and everything was fine when I had one app.rb file and I followed Aslak instructions on Github:

https://github.com/cucumber/cucumber/wiki/Sinatra

As the application got bigger and bigger and the app.rb file started to grow in size, I reorganized a lot of bits into middleware-style modules using Sinatra :: Base, displaying things using an extension file (config .ru). ) etc.

The application works well - but my specs exploded because there was no longer an app.rb file for working with webrat (as defined in the link above).

I tried to find examples of how to do this, and I think I'm just not used to Cuke's internals, as I cannot find a single way to cover all applications. I tried just pointing to "config.ru" instead of app.rb - but this does not work.

What I did in the end - and this is completely hacking - is the presence of a separate app.rb file in my support directory, which has everything you need so that I can at least test the model. I can also indicate the routes there - but this is not at all what I want to do.

So the question is: how can I get Cucumber to work correctly with a modular approach to applications?

+3
source share
3 answers

Sinatra

,

  def app
    Sinatra::Application
  end

 def app
    Rack::Builder.new do
      map '/a' { run MyAppA }
      map '/b' { run MyAppB }
    end
  end

.

, config.ru, , , .

+2

- - , , :). env.rb(/features/support/env.rb):

require 'sinatra'
require 'test/unit'
require 'spec/expectations'
require 'rack/test'
require 'webrat'
require 'app1'
require 'app2'
require 'app3'

Webrat.configure do |config|
  config.mode = :rack
end

class MyWorld
  require 'test/unit'

  set :environment, :test

  include Rack::Test::Methods
  include Webrat::Methods
  include Webrat::Matchers

  Webrat::Methods.delegate_to_session :response_code, :response_body, :response

  def app
    Rack::Builder.new do
      map '/' do
        run App1 #important - this is the class name
      end
      map '/app1' do
        run App2
      end
      map '/app2' do
        run App3
      end
    end
  end
end

World do
  MyWorld.new

end
+2

https://gist.github.com/28d510d9fc25710192bc

def app
  eval "Rack::Builder.new {( " + File.read(File.dirname(__FILE__) + '/../config.ru') + "\n )}"
end
0
source

Source: https://habr.com/ru/post/1737741/


All Articles