Skip to content

Instantly share code, notes, and snippets.

@nishio-dens
Created October 22, 2021 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishio-dens/13f6d5e9c3d6455791342126fcfbe065 to your computer and use it in GitHub Desktop.
Save nishio-dens/13f6d5e9c3d6455791342126fcfbe065 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", "~> 6.1.4"
gem "debug"
gem "puma"
gem "capybara"
gem "webdrivers"
gem "rspec-rails"
end
## Test rails controller
require "rails"
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
config.hosts << "example.org"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
get "/" => "test#index"
get "/something" => "test#something"
end
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def index
render plain: "Hello Home"
end
def something
render plain: "Hello Something"
end
end
## Test spec - RSpec + capybara
require "rspec/rails"
require "rspec/autorun"
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.use_active_record = false
config.render_views
end
require "capybara"
require "debug"
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.server_host = "0.0.0.0"
Capybara.server_port = 3002
Capybara.server = :puma
Capybara.javascript_driver = :selenium
RSpec.describe "BugTest", type: :system do
it "visit /" do
visit "/"
expect(page).to have_content("Hello Home")
end
it "visit /something" do
visit "/something"
expect(page).to have_content("Hello Something")
end
end
@nishio-dens
Copy link
Author

[nishio@NPC] $ ruby debug_test.rb                                                                                                                                                                                           [main@0 ~/Projects/debug_test]
Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.6
Using concurrent-ruby 1.1.9
Using i18n 1.8.10
Using minitest 5.14.4
Using tzinfo 2.0.4
Using zeitwerk 2.5.1
Using activesupport 6.1.4.1
Using builder 3.2.4
Using erubi 1.10.0
Using mini_portile2 2.6.1
Using racc 1.6.0
Using nokogiri 1.12.5 (x86_64-darwin)
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.12.0
Using rails-html-sanitizer 1.4.2
Using actionview 6.1.4.1
Using rack 2.2.3
Using rack-test 1.1.0
Using actionpack 6.1.4.1
Using nio4r 2.5.8
Using websocket-extensions 0.1.5
Using websocket-driver 0.7.5
Using actioncable 6.1.4.1
Using globalid 0.5.2
Using activejob 6.1.4.1
Using activemodel 6.1.4.1
Using activerecord 6.1.4.1
Using marcel 1.0.2
Using mini_mime 1.1.2
Using activestorage 6.1.4.1
Using mail 2.7.1
Using actionmailbox 6.1.4.1
Using actionmailer 6.1.4.1
Using actiontext 6.1.4.1
Using public_suffix 4.0.6
Using addressable 2.8.0
Using bundler 2.1.4
Using regexp_parser 2.1.1
Using xpath 3.2.0
Using capybara 3.35.3
Using childprocess 4.1.0
Using io-console 0.5.9
Using reline 0.2.7
Using irb 1.3.7
Using debug 1.3.1
Using diff-lcs 1.4.4
Using method_source 1.0.0
Using puma 5.5.2
Using thor 1.1.0
Using railties 6.1.4.1
Using sprockets 4.0.2
Using sprockets-rails 3.2.2
Using rails 6.1.4.1
Using rexml 3.2.5
Using rspec-support 3.10.2
Using rspec-core 3.10.1
Using rspec-expectations 3.10.1
Using rspec-mocks 3.10.2
Using rspec-rails 5.0.2
Using rubyzip 2.3.2
Using selenium-webdriver 4.0.3
Using webdrivers 5.0.0
DEBUGGER: Attaching after process 64836 fork to child process 64883
2021-10-23 02:59:15 WARN Selenium [DEPRECATION] [:browser_options] :options as a parameter for driver initialization is deprecated. Use :capabilities with an Array of value capabilities/options if necessary instead.
Capybara starting Puma...
* Version 5.5.2 , codename: Zawgyi
* Min threads: 0, max threads: 4
* Listening on http://0.0.0.0:3002
I, [2021-10-23T02:59:16.835245 #64836]  INFO -- : Started GET "/" for 127.0.0.1 at 2021-10-23 02:59:16 +0900
I, [2021-10-23T02:59:16.905022 #64836]  INFO -- : Started GET "/favicon.ico" for 127.0.0.1 at 2021-10-23 02:59:16 +0900
F, [2021-10-23T02:59:16.905522 #64836] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/favicon.ico"):

.I, [2021-10-23T02:59:17.019008 #64836]  INFO -- : Started GET "/something" for 127.0.0.1 at 2021-10-23 02:59:17 +0900
.

Finished in 2.02 seconds (files took 0.28034 seconds to load)
2 examples, 0 failures

[nishio@NPC] $

@fwolfst
Copy link

fwolfst commented Nov 18, 2022

But unfortunately you cannot call debugger in the test case and istruct Capybara to do stuff (visit '/test') from there :( - works with pry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment