Sha256: ca847d16dc8b25a78c9a46d0bd6580a1036ef6f4930a7ff7208d6c3ad2a53c01

Contents?: true

Size: 1.69 KB

Versions: 7

Compression:

Stored size: 1.69 KB

Contents

require 'sprockets'
require 'sprockets-helpers'
require 'sinatra/base'
require 'sinatra/sprockets/helpers'
require 'test_construct'
require 'pathname'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

RSpec.configure do |config|
  config.include TestConstruct::Helpers

  # Disable old `should` syntax
  config.expect_with :rspec do |c|
    c.syntax = :expect
  end

  # Returns a Sprockets environment. Automatically
  # appends the 'assets' path if available.
  def env
    @env ||= Sprockets::Environment.new.tap do |env|
      env.append_path 'assets' if File.directory?('assets')
    end
  end

  # Returns a fresh context, that can be used to test helpers.
  def context(logical_path = 'application.js', pathname = nil)
    pathname ||= Pathname.new(File.join('assets', logical_path)).expand_path

    if Sprockets::Helpers.are_using_sprockets_3
      env.context_class.new(
        :environment => env,
        :name => logical_path,
        :filename => pathname,
        :metadata => {}
      )
    else
      env.context_class.new env, logical_path, pathname
    end
  end

  # Exemplary file system layout for usage in test-construct
  def assets_layout(construct)
    lambda { |c|
      c.file('assets/main.js') do |f|
        f << "//= require a\n"
        f << "//= require b\n"
      end
      c.file('assets/a.js')
      c.file('assets/b.js')

      c.file('assets/main.css') do |f|
        f << "/*\n"
        f << "*= require a\n"
        f << "*= require b\n"
        f << "*/\n"
      end
      c.file('assets/a.css')
      c.file('assets/b.css')
    }.call(construct)
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
sprockets-helpers-1.4.0 spec/spec_helper.rb
sprockets-helpers-1.3.0 spec/spec_helper.rb
sprockets-helpers-1.2.3 spec/spec_helper.rb
sprockets-helpers-1.2.2 spec/spec_helper.rb
arcabouco-0.2.13 vendor/bundle/gems/sprockets-helpers-1.2.1/spec/spec_helper.rb
sprockets-helpers-1.2.1 spec/spec_helper.rb
sprockets-helpers-1.2.0 spec/spec_helper.rb