Sha256: 255355a8dd65ec1b4ada989eb9327631a9f43ba329f24fbcad09c05287dfd198

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require 'volt/volt/core' if RUBY_PLATFORM != 'opal'

module Volt
  class << self
    def spec_setup(app_path = '.')
      require 'volt'

      ENV['SERVER'] = 'true'
      ENV['VOLT_ENV'] = 'test'

      require 'volt/boot'

      # Require in app
      volt_app = Volt.boot(app_path)

      unless RUBY_PLATFORM == 'opal'
        begin
          require 'volt/spec/capybara'

          setup_capybara(app_path, volt_app)
        rescue LoadError => e
          Volt.logger.warn("unable to load capybara, if you wish to use it for tests, be sure it is in the app's Gemfile")
          Volt.logger.error(e)
        end
      end

      unless ENV['BROWSER']
        # Not running integration tests with ENV['BROWSER']
        RSpec.configuration.filter_run_excluding type: :feature
      end

      # Setup the spec collection accessors
      # RSpec.shared_context "volt collections", {} do
      RSpec.shared_examples_for 'volt collections', {} do
        # Page conflicts with capybara's page method, so we call it the_page for now.
        # TODO: we need a better solution for page

        let(:the_page) { Model.new }
        let(:store) do
          @__store_accessed = true
          $page ||= Page.new
          $page.store
        end

        def cleanup_after
          Volt::DataStore.fetch.drop_database

          $page.instance_variable_set('@store', nil)
        end

        if RUBY_PLATFORM != 'opal'
          after do
            if @__store_accessed
              # Clear the database after each spec where we use store
              cleanup_after
            end
          end

          # Cleanup after integration tests also.
          after(:example, {type: :feature}) do
            cleanup_after
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
volt-0.9.2 lib/volt/spec/setup.rb