Using capybara_discoball to mount a Rails engine?
Closed this issue · 5 comments
Hi,
Just wondering if there was any experience with using capybara_discoball to mount a Rails engine (rather than another Rack application eg Sinatra).
I am trying mount a Rails::Engine within Capybara_Discoball in a Rails application and running into dead ends so far.
I haven't tried this, but you should be able to mount any Rack application. We frequently mount fake services written using Sinatra.
What does your boot code currently look like?
I was doing something like this:
runner = Capybara::Discoball::Runner.new(WfsRails::Runner)
runner.boot
Then:
require 'wfs_rails'
module WfsRails
class Runner
def initialize
Rails.application.routes.draw do
mount WfsRails::Engine => '/wfs_rails'
end
end
end
I'm just not really sure what the entry point to a Rails engine should be in something like this.
I think the issue is that Runner
needs to be a Rack application, so it should respond to call
. It looks like Rails engines are Rack applications themselves; have you tried passing the engine directly? If you want to change the way routing works for the engine or something like that, I think middleware is likely the best approach.
Thanks I was able to figure this out with a colleague (thanks @cbeer).
For those interested, you can do something like:
runner = Capybara::Discoball::Runner.new(OpenStruct.new(new: WfsRails::Engine.app))
new
for Rails::Engines
is a private method and this was just a quick work around to proof of concept the approach.
Right, the difference being the Rails::Engine
API will only hand you an instance of a Rack application, while discoball seems to expect a class.
I wonder if there's some way to adapt discoball to be more lenient about the kinds of things it accepts.