Sha256: 95d1f4d674f922313937262f861d695a0acbda69b424a82282ad621465ebbea5

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'pathname'
require 'active_support/core_ext/hash/reverse_merge'

module Machined
  module SpecHelpers
    # Convenience method for creating a new Machined environment
    def machined(config = {})
      @machined ||= Machined::Environment.new(config.reverse_merge(:skip_bundle => true))
    end
    
    # Convenience method for creating a new Machined sprocket,
    # with an automatic reference to the current Machined
    # environment instance.
    def create_sprocket(config = {})
      Machined::Sprocket.new machined, config
    end
  
    # Returns a fresh context, that can be used to test helpers.
    def context(logical_path = 'application.js', options = {})
      @context ||= begin
        pathname = options[:pathname] || Pathname.new(File.join('assets', logical_path)).expand_path
        env      = options[:env] || machined.assets
        
        env.context_class.new env, logical_path, pathname
      end
    end
    
    # Runs the CLI with the given args.
    def machined_cli(args, silence = true)
      capture(:stdout) {
        Machined::CLI.start args.split(' ')
      }
    end
    
    # Captures the given stream and returns it:
    #
    #   stream = capture(:stdout) { puts 'Cool' }
    #   stream # => "Cool\n"
    #
    def capture(stream)
      begin
        stream = stream.to_s
        eval "$#{stream} = StringIO.new"
        yield
        result = eval("$#{stream}").string
      ensure
        eval "$#{stream} = #{stream.upcase}"
      end
  
      result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
machined-0.8.0 spec/support/helpers.rb