-
-
Notifications
You must be signed in to change notification settings - Fork 96
Closed
Description
I'm not a web developer so I never used Capybara integrated with the Ruby web app -- I always ran the tests as a separetly hosted application. However I'm currently making a Sinatra app and I suppose integrating it with the minitest would allow me to start and stop the app automatically that would be nice. But I can't figure out how to do that. I tried to follow https://sinatrarb.com/testing.html
# Gemfile
source "https://rubygems.org"
gem "sinatra"
gem "minitest"
gem "cuprite"# main.rb
require "sinatra/base"
class MyApp < Sinatra::Base
set :bind, "0.0.0.0"
set :port, 8001
get "/" do
"hello"
end
run! if $0 == __FILE__
end# minitest_cuprite.helper.rb
require "capybara/cuprite"
Capybara.current_driver = Capybara.javascript_driver = :cuprite
Capybara.register_driver :cuprite do |app|
Capybara::Cuprite::Driver.new app, "headless": false
end
require "capybara/minitest"
require "minitest/spec"
Minitest::Spec.include Capybara::DSL
Minitest::Spec.include Capybara::Minitest::Assertions
require "minitest/autorun"# cat test.rb
require_relative "minitest_cuprite.helper"
ENV['APP_ENV'] = 'test'
require './main'
Capybara.server = :webrick
Capybara.app = MyApp.new
describe :test do
before do
Capybara.reset_sessions!
end
it do
visit "http://localhost:8001"
require "irb"
binding.irb
end
endbut when the browser window opens the localhost is down, it does not look like Sinatra was started. What do I miss here?
UPD: moving the require helper after the .app = is probably more correct but still no effect.
Metadata
Metadata
Assignees
Labels
No labels