Skip to content

Commit

Permalink
Add setup for feature testing
Browse files Browse the repository at this point in the history
This commit sets up solr_wrapper for use in the local
testing enviroment and in travis. It includes changes so that
solr will run in travis and includes a fixture
geoblacklight json file that is used in the feature
tests that are also added in this commit.
  • Loading branch information
little9 committed Apr 9, 2018
1 parent 8c2d2c4 commit 174499a
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 79 deletions.
7 changes: 4 additions & 3 deletions .solr_wrapper.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Place any default configuration for solr_wrapper here
# port: 8983
instance_dir: tmp/solr-development
download_dir: /var/tmp
collection:
persist: true
dir: solr/conf/
name: blacklight-core
name: aster-development
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ language: ruby
cache: bundler
dist: trusty

jdk:
- oraclejdk8

rvm:
- 2.4.1
script:
- bundle exec rake aster:ci
- bundle exec rake aster:travis
notifications:
email: false
10 changes: 5 additions & 5 deletions config/blacklight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# each environment can have a jetty_path with absolute or relative
# (to app root) path to a jetty/solr install. This is used
# by the rake tasks that start up solr automatically for testing
# and by rake solr:marc:index.
# and by rake solr:marc:index.
#
# jetty_path is not used by a running Blacklight application
# at all. In general you do NOT need to deploy solr in Jetty, you can deploy it
# however you want.
# however you want.
# jetty_path is only required for rake tasks that need to know
# how to start up solr, generally for automated testing.
# how to start up solr, generally for automated testing.

development:
adapter: solr
url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:8983/solr/blacklight-core" %>
url: http://127.0.0.1:<%= ENV['SOLR_TEST_PORT'] || 8983 %>/solr/aster-development
test: &test
adapter: solr
url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8983}/solr/blacklight-core" %>
url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:#{ENV.fetch('SOLR_TEST_PORT', 8985)}/solr/aster-test" %>
production:
adapter: solr
url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:8983/solr/aster" %>
6 changes: 5 additions & 1 deletion config/solr.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
production:
development:
url: http://127.0.0.1:<%= ENV['SOLR_TEST_PORT'] || 8983 %>/solr/aster-development
test:
url: http://127.0.0.1:<%= ENV['SOLR_TEST_PORT'] || 8985 %>/solr/aster-test
production:
url: http://127.0.0.1:8983/solr/aster
6 changes: 6 additions & 0 deletions config/solr_wrapper_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
port: 8985
instance_dir: tmp/solr-test
collection:
persist: false
dir: solr/conf/
name: aster-test
1 change: 1 addition & 0 deletions lib/tasks/spec.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
unless Rails.env.production?
namespace :aster do
task :spec do
Expand Down
27 changes: 27 additions & 0 deletions lib/tasks/travis.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

unless Rails.env.production?
APP_ROOT = File.dirname(__FILE__)
require 'solr_wrapper'
require 'solr_wrapper/rake_task'
namespace :aster do
desc 'Run Continuous Integration'
task :travis do
ENV['environment'] = 'test'
solr_params = {
port: 8985,
verbose: true,
managed: true
}
SolrWrapper.wrap(solr_params) do |solr|
solr.with_collection(
name: 'aster-test',
persist: false,
dir: Rails.root.join('solr', 'conf')
) do
Rake::Task['aster:ci'].invoke
end
end
end
end
end
8 changes: 8 additions & 0 deletions spec/features/home_page_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'viewing content on the aster home page', type: :feature do
scenario 'viewing the version' do
visit '/'
expect(page).to have_css '.version'
end
end
12 changes: 12 additions & 0 deletions spec/features/show_page_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe 'viewing content on the aster show page', type: :feature do
before do
Rake::Task['geoblacklight:solr:seed'].invoke
end
scenario 'viewing the show page' do
visit solr_document_path 'gford-20140000-010015_belvegr'
expect(page).to have_content 'Vegetation, Maya Forest, Belize, 1995'
end
end
19 changes: 19 additions & 0 deletions spec/fixtures/solr_documents/maya_forest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"geoblacklight_version": "1.0",
"dc_identifier_s": "ucsb:gford-20140000-010015_belvegr",
"layer_slug_s":"gford-20140000-010015_belvegr",
"dc_language_s": "English",
"dc_publisher_s": "University of California, Santa Barbara. Map and Imagery Laboratory",
"dc_rights_s": "Public",
"dc_title_s": "Vegetation, Maya Forest, Belize, 1995",
"dc_type_s": "Dataset",
"dct_references_s": "{\"http://www.opengis.net/def/serviceType/ogc/wfs\":\"http://geoservices-sandbox.library.ucsb.edu:8080/geoserver/ucsb/ows?service=WFS\",\"http://www.opengis.net/def/serviceType/ogc/wms\":\"http://geoservices-sandbox.library.ucsb.edu:8080/geoserver/ucsb/wms?service=WMS\"}",
"solr_geom": "ENVELOPE(-88.0804, -89.2587, 18.4977, 15.8808)",
"dct_spatial_sm": "Belize",
"dc_subject_sm":"Belize",
"dc_creator_sm":"UCSB",
"dct_provenance_s": "UCSB",
"layer_geom_type_s": "Polygon"
}
]
6 changes: 4 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!

require 'capybara/rspec'
require 'capybara/rails'
require 'rake'
Rails.application.load_tasks
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
Expand Down
88 changes: 21 additions & 67 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
require 'coveralls'
Coveralls.wear!('rails')
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require 'rails_helper'

RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
Expand All @@ -39,58 +26,25 @@
mocks.verify_partial_doubles = true
end

# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
# have no way to turn it off -- the option exists only for backwards
# compatibility in RSpec 3). It causes shared context metadata to be
# inherited by the metadata hash of host groups and examples, rather than
# triggering implicit auto-inclusion in groups with matching metadata.
# @note In January 2018, TravisCI disabled Chrome sandboxing in its Linux
# container build environments to mitigate Meltdown/Spectre
# vulnerabilities, at which point Hyrax could no longer use the
# Capybara-provided :selenium_chrome_headless driver (which does not
# include the `--no-sandbox` argument).
Capybara.register_driver :selenium_chrome_headless_sandboxless do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.args << '--headless'
browser_options.args << '--disable-gpu'
browser_options.args << '--no-sandbox'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end

Capybara.default_driver = :rack_test # This is a faster driver
Capybara.javascript_driver = :selenium_chrome_headless_sandboxless # This is slower

config.shared_context_metadata_behavior = :apply_to_host_groups

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# # This allows you to limit a spec run to individual examples or groups
# # you care about by tagging them with `:focus` metadata. When nothing
# # is tagged with `:focus`, all examples get run. RSpec also provides
# # aliases for `it`, `describe`, and `context` that include `:focus`
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
# config.filter_run_when_matching :focus
#
# # Allows RSpec to persist some state between runs in order to support
# # the `--only-failures` and `--next-failure` CLI options. We recommend
# # you configure your source control system to ignore this file.
# config.example_status_persistence_file_path = "spec/examples.txt"
#
# # Limits the available syntax to the non-monkey patched syntax that is
# # recommended. For more details, see:
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
# config.disable_monkey_patching!
#
# # Many RSpec users commonly either run the entire suite or an individual
# # file, and it's useful to allow more verbose output when running an
# # individual spec file.
# if config.files_to_run.one?
# # Use the documentation formatter for detailed output,
# # unless a formatter has already been configured
# # (e.g. via a command-line flag).
# config.default_formatter = "doc"
# end
#
# # Print the 10 slowest examples and example groups at the
# # end of the spec run, to help surface which specs are running
# # particularly slow.
# config.profile_examples = 10
#
# # Run specs in random order to surface order dependencies. If you find an
# # order dependency and want to debug it, you can fix the order by providing
# # the seed, which is printed after each run.
# # --seed 1234
# config.order = :random
#
# # Seed global randomization in this process using the `--seed` CLI option.
# # Setting this allows you to use `--seed` to deterministically reproduce
# # test failures related to randomization by passing the same `--seed` value
# # as the one that triggered the failure.
# Kernel.srand config.seed
config.order = :random

Kernel.srand config.seed
end

0 comments on commit 174499a

Please sign in to comment.