diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake new file mode 100644 index 0000000..e5daa70 --- /dev/null +++ b/lib/tasks/ci.rake @@ -0,0 +1,35 @@ +unless Rails.env.production? + APP_ROOT = File.dirname(__FILE__) + require "solr_wrapper" + require "fcrepo_wrapper" + require 'solr_wrapper/rake_task' + + desc "Run Continuous Integration" + task :ci do + ENV["environment"] = "test" + solr_params = { + port: 8985, + verbose: true, + managed: true + } + fcrepo_params = { + port: 8986, + verbose: true, + managed: true, + enable_jms: false, + fcrepo_home_dir: 'tmp/fcrepo4-test-data' + } + SolrWrapper.wrap(solr_params) do |solr| + solr.with_collection( + name: "hydra-test", + persist: false, + dir: Rails.root.join("solr", "config") + ) do + FcrepoWrapper.wrap(fcrepo_params) do + Rake::Task["spec"].invoke + end + end + end + # Rake::Task["doc"].invoke + end +end \ No newline at end of file diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index bbe1ba5..13ce14a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,11 +1,19 @@ -# 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 'spec_helper' +require 'action_view' +require 'devise' +require 'devise/version' +require 'rspec/matchers' +require 'active_fedora/cleaner' +require 'capybara/rspec' +require 'capybara/rails' +require 'database_cleaner' # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are @@ -19,13 +27,20 @@ # of increasing the boot-up time by auto-requiring all files in the support # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. -# -# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } +Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # Checks for pending migrations and applies them before tests are run. # If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.maintain_test_schema! +# See https://github.com/thoughtbot/shoulda-matchers#rspec +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end + RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" @@ -54,4 +69,37 @@ config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") + + config.before :suite do + ActiveFedora::Cleaner.clean! + end + + config.before :each do + DatabaseCleaner.strategy = :truncation + DatabaseCleaner.start + end + + config.after do + DatabaseCleaner.clean + end + + config.include Devise::Test::ControllerHelpers, type: :controller + config.include Capybara::RSpecMatchers, type: :input + + config.include Warden::Test::Helpers, type: :feature + config.after(:each, type: :feature) { Warden.test_reset! } + + # Gets around a bug in RSpec where helper methods that are defined in views aren't + # getting scoped correctly and RSpec returns "does not implement" errors. So we + # can disable verify_partial_doubles if a particular test is giving us problems. + # Ex: + # describe "problem test", verify_partial_doubles: false do + # ... + # end + config.before :each do |example| + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = example.metadata.fetch(:verify_partial_doubles, true) + end + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce33d66..4d74d13 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ -# 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`. +# 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. @@ -12,6 +13,9 @@ # the additional setup, and require it from the spec files that actually need # it. # +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate @@ -44,9 +48,9 @@ # triggering implicit auto-inclusion in groups with matching metadata. 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. -=begin + # 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 @@ -57,29 +61,29 @@ # 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" + # 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! + # 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 + # 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 + # 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 @@ -92,5 +96,4 @@ # test failures related to randomization by passing the same `--seed` value # as the one that triggered the failure. Kernel.srand config.seed -=end end