-
-
Save tdreyno/c977de5d398c8c2d4b6a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Make sure we can specify test settings as required | |
ENV['MM_ENV'] ||= 'test' | |
require 'middleman/rack' | |
require 'middleman-core/rack' | |
require 'rspec' | |
require 'capybara/rspec' | |
require 'capybara/poltergeist' | |
require 'webmock/rspec' | |
require 'fileutils' | |
require 'byebug' | |
require_relative 'support/helpers' | |
require_relative 'support/shared_contexts' | |
# Disable all external requests in test mode (will raise error in test run) | |
WebMock.disable_net_connect!(allow_localhost: true) | |
# Uncomment below to allow network access during tests | |
# WebMock.allow_net_connect! | |
# Bootstrap Middleman and create reference to Middleman Application | |
module MiddlemanApplication | |
extend RSpec::SharedContext | |
# Set logging output to file | |
FileUtils.mkdir('log') unless File.exist?('log') | |
rspec_logger = ::Middleman::Logger.singleton('log/rspec.log') | |
# Fixtures need to be set as an environment variable so it can be accessed in | |
# config.rb and they need to be set here so the environment variable is set at | |
# the appropriate time | |
ENV['MM_DATA_DIR'] = 'spec/fixtures/data' | |
# This refereces the actual (parent) app, which is used | |
# for Capybara testing | |
main_app = ::Middleman::Application.new do || | |
# Ensure that we don't do any file watching during tests | |
config[:watcher_disable] = true | |
end | |
# N.B. We set up the Capybara app from within this module scope so that | |
# we can hang on to the Middleman application and not have to reinstantiate | |
# it for every test | |
Capybara.app = ::Middleman::Rack.new(main_app).to_app | |
let(:app) do | |
main_app | |
end | |
let(:logger) do | |
rspec_logger | |
end | |
let(:fixtures_path) { File.join(File.dirname(__FILE__), 'fixtures/data') } | |
end | |
RSpec.configure do |config| | |
config.include MiddlemanApplication | |
config.include Helpers | |
Capybara.javascript_driver = :poltergeist | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment