Skip to content

Commit

Permalink
Initial try to add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lsolesen committed Aug 13, 2021
1 parent 6aae084 commit ac63663
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
11 changes: 11 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ end
gem 'classifier-reborn'
gem 'gsl'
gem 'html-proofer'

group :development, :test do
gem 'html-proofer'
gem "rspec"
gem "selenium-webdriver"
gem "webdrivers"
gem "puma"
gem "capybara"
gem "rack-jekyll"
gem "pry"
end
9 changes: 9 additions & 0 deletions spec/index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe "index", type: :feature, js: true do
it "has the page title" do
visit '/'
# `binding.pry` is useful for crafting the right selector
# or checking the actual state of the page
binding.pry # test will pause here
expect(find('.post-link').text).to eq('Welcome to Jekyll!')
end
end
57 changes: 57 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Require all of the necessary gems
require 'rspec'
require 'capybara/rspec'
require 'rack/jekyll'
require 'rack/test'
require 'pry'
require 'webdrivers'

RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
# Configure Capybara to use Selenium.
Capybara.register_driver :selenium do |app|
chrome_prefs = {
'download' => {
'default_directory' => './support/',
'prompt_for_download' => false
},
'profile' => {
'default_content_settings' => { 'multiple-automatic-downloads': 1 }, # for chrome version olde ~42
'default_content_setting_values' => { 'automatic_downloads': 1 }, # for chrome newe 46
'password_manager_enabled' => false
},
'safebrowsing' => {
'enabled' => false,
'disable_download_protection' => true
}
}

# Set headless with docker friendly args.
chrome_args = %w[window-size=1024,768 disable-gpu no-sandbox disable-translate no-default-browser-check disable-popup-blocking]
# To run full browser instead of headless mode, run this command: HEADLESS=false rspec spec
unless ENV.fetch('HEADLESS', 'true') == 'false'
chrome_args += %w[headless]
end

# Initialize chromedriver.
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
prefs: chrome_prefs,
args: chrome_args
}
)
driver = Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities)

driver
end
# Configure Capybara to load the website through rack-jekyll.
# (force_build: true) builds the site before the tests are run,
# so our tests are always running against the latest version
# of our jekyll site.
Capybara.app = Rack::Jekyll.new(force_build: true)
end

0 comments on commit ac63663

Please sign in to comment.