Created
October 22, 2021 17:58
-
-
Save nishio-dens/13f6d5e9c3d6455791342126fcfbe065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Author
nishio-dens
commented
Oct 22, 2021
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